In Pascal it is possible to declare union types:
AnimalType = (Dog, Cat);
Animal = record
name: string;
case myType: AnimalType of
Dog: (weight: Integer);
Cat: (age: Integer);
end;
However, it is easy to violate the contract of case:
var
a: Animal;
begin
a.name := 'Kittie';
a.myType := Cat;
a.weight := 10; // There is no weight for cats!
writeln(a.age); // Prints 10
end.
There is a semantic error in this example, but the compiler typechecks it successfully. Also, there is no error at the runtime.
So, does the case block exist only for the documentation purposes?
The short answer to your question is, "no case blocks in variant records are not there only for documentation purposes". I say this because although the Pascal implementation you are using did not detect the fact that the program as accessing an inactive variant, other implementation do detect this error.
The long answer to your question is as follows.
Many people who are just learning Pascal don't realize that there are two major flavours of the Pascal language. There is ISO 7185 Standard Pascal (or just Standard Pascal for short) and there is Turbo/Borland Pascal (the most popular variant). So let me give you two answers to your question "So, does the case block exist only for the documentation purposes"?
The Standard Pascal Answer
Standard Pascal defines an error as "A violation by a program of the requirements of this International Standard that a processor is permitted to leave undetected". So yes, the program you have given does contain an error and yes the processor (i.e. Pascal implementation) you are using does not detect it, but other implementation will detect it, so no the case block in variant records actually has a functional purpose.
The Turbo/Borland Answer
As far as the Turbo/Borland Pascal flavours go, I don't know if none of them will detect this error, but even if none of them do, it's probably better to think of this as an error that they do not detect rather than as something for documentation purposes only. Saying something is for documentation purposes only, sounds to me like saying it was never intended to be functional.