[lazarus] "Variant" variable ?

Michael Van Canneyt michael.vancanneyt at wisa.be
Thu Apr 27 13:37:01 EDT 2000




On Thu, 27 Apr 2000, dvortex wrote:

> 
> 
> On Thu, 27 Apr 2000, Michael Van Canneyt wrote:
> 
> > 
> > 
> > On Thu, 27 Apr 2000, Marc Weustink wrote:
> > 
> > > At 23:20 26-04-2000 +0200, Michael Van Canneyt wrote:
> > > 
> > > >It is in the Case statement.
> > > >
> > > >Case A : Integer of
> > > >   1 : (X : String;);
> > > >   2 : (Y : Longint);
> > > >end;
> > > >
> > > >If A=1 then you can access X as a string
> > > >If A=2 then you can access Y as a Longint.
> > > 
> > > Is there a check on this? I allways thought that 1 and 2 are just 
> > > placeholders?
> > 
> > There is no check; you must do the check. The point is that there are 2 constructs
> > 
> > Case A : Integer of
> >    1 : (X : String;);
> >    2 : (Y : Longint);
> > end;
> > 
> > Here you can set A and thus have an indication which of X or Y you should access.
> > (i.e. A is a normal field of the record)
> > 
> > On the other hand
> > 
> > Case Integer of
> >    1 : (X : String;);
> >    2 : (Y : Longint);
> > end;
> > 
> > doesn't allow to determine what you should access, because there is no 'A' field.
> > 
> That's exactly what is confusing to me .... so how does this one work ?

It's up to the programmer to see which one he should use.

For instance TRect can be defined as follows:

  TPoint = Record
    X,Y  : longint;
    end;

  TRect = Record
    case Integer of
      1 : (X1,Y1,X2,Y2 : longint);
      2 : (Topleft,BottomRight : TPoint);
    end;

Whatever the way you access TRect, the result is always the same.

Michael.






More information about the Lazarus mailing list