Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2000-04

"Variant" variable ?

19 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Weustink
to dvortex: That's what i was afraid of :o) well, for the FPC guys: if i put a "record type" together…

+ From: dvortex
+
+ That's what i was afraid of :o)
+
+ well, for the FPC guys: if i put a "record type" together that is a
+ equivalent to the variant, how hard would it be to put that in the fpc
+ compiler ? (it can be usefull, althoug i would understand not
+ wanting to put such a hack in the compiler :o)

A variant is just a TVarData. The compiler puts type checking/conversion stuff around it. I can imagine that you don't want to put this in a compiler. (Let the developer put some code around it).

You can also use the good old TVarRec

Marc

Reply by email

Michael Van Canneyt
to dvortex: I just found a type "variant" in typinfo as "pointer" I'm going to get my own class to do…
dvortex wrote
I just found a type "variant" in typinfo as "pointer" I'm going to get my own class to do this, it will be a little more "clean" we will see.

Actually, the best and easiest would be to use TVarRec and use overloaded operators. This can then
1) Be used immediatly.
2) Be inserted in the compiler at a later stage with little effort.

It was on my todo list to start this after we release 1.0, but if you can do the overloaded stuff already, then this would definitely get used.

Using the overloaded stuff means that all Delphi expressions using variants would work.

Michael.

Reply by email

dvortex

Hello.
I am working on a "object inspector" with the LCL (just to see how far i can go). This form/object only check the properties of an object you tell it to "inspect". it is also possible to change the value of a property, etc...)

now, I have some questions:
I was wondering if there is any kind of "variant" type possible (the type in delphi where you can put anythiing :o) , or even some variant array type support with fpc ?

Thanks

Reply by email

Michael Van Canneyt
to dvortex
dvortex wrote 10 lines
Hello. I am working on a "object inspector" with the LCL (just to see how far i can go). This form/object only check the properties of an object you tell it to "inspect". it is also possible to change the value of a property, etc...) now, I have some questions: I was wondering if there is any kind of "variant" type possible (the type in delphi where you can put anythiing :o) , or even some variant array type support with fpc ?

No, it is not available.

Variant is a VERY UGLY construct which goes against all that pascal stands for, i.e. strong type checking and such.
We'll add support for it, one day - but not soon, and only because we want to be Delphi compatible. So it's definitely not going to be soon.

Michael.

Reply by email

dvortex
to Baeseman, Cliff: There is no variant type in FPC but as a workaround you could create a record that…

That's what i was afraid of :o)

well, for the FPC guys: if i put a "record type" together that is a equivalent to the variant, how hard would it be to put that in the fpc compiler ? (it can be usefull, althoug i would understand not wanting to put such a hack in the compiler :o)

Ho well.. back hacking... :o)
Jok

Cliff wrote 37 lines
There is no variant type in FPC but as a workaround you could create a record that contains each type and use that as your variant. Cliff -----Original Message----- From: dvortex Sent: Wednesday, April 26, 2000 9:32 AM To: Subject: [lazarus] "Variant" variable ? Hello. I am working on a "object inspector" with the LCL (just to see how far i can go). This form/object only check the properties of an object you tell it to "inspect". it is also possible to change the value of a property, etc...) now, I have some questions: I was wondering if there is any kind of "variant" type possible (the type in delphi where you can put anythiing :o) , or even some variant array type support with fpc ? Thanks _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus

Reply by email

dvortex
to Marc Weustink: There isn't much. If you realy want to use Variants declare them as TVarData. Assign them…

I just found a type "variant" in typinfo as "pointer"

I'm going to get my own class to do this, it will be a little more "clean" we will see.

Jok
---
Nothing is foolproof to a
sufficiantly talented fool.

Marc Weustink wrote 24 lines
At 10:51 26-04-2000 -0700, dvortex wrote: >On Wed, 26 Apr 2000, Marc Weustink wrote: > > > A variant is just a TVarData. The compiler puts type checking/conversion > > stuff around it. I can imagine that you don't want to put this in a > > compiler. (Let the developer put some code around it). > > > > You can also use the good old TVarRec > > > >Where can i get some info on that (i've been trying to scroll though the >docs, but can't find much...) There isn't much. If you realy want to use Variants declare them as TVarData. Assign them trought the Vxx members and set the type. Marc _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus

Reply by email

Baeseman, Cliff

There is no variant type in FPC but as a workaround you could create a record that contains each type and use that as your variant.

Cliff

Earlier message 26 lines
-----Original Message----- From: dvortex Sent: Wednesday, April 26, 2000 9:32 AM To: Subject: [lazarus] "Variant" variable ? Hello. I am working on a "object inspector" with the LCL (just to see how far i can go). This form/object only check the properties of an object you tell it to "inspect". it is also possible to change the value of a property, etc...) now, I have some questions: I was wondering if there is any kind of "variant" type possible (the type in delphi where you can put anythiing :o) , or even some variant array type support with fpc ? Thanks _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus

Reply by email

dvortex
to Marc Weustink: + From: dvortex + + That's what i was afraid of :o) + + well, for the FPC guys: if i put…
Marc Weustink wrote 15 lines
+ From: dvortex + + That's what i was afraid of :o) + + well, for the FPC guys: if i put a "record type" together that is a + equivalent to the variant, how hard would it be to put that in the fpc + compiler ? (it can be usefull, althoug i would understand not + wanting to put such a hack in the compiler :o) A variant is just a TVarData. The compiler puts type checking/conversion stuff around it. I can imagine that you don't want to put this in a compiler. (Let the developer put some code around it). You can also use the good old TVarRec

Where can i get some info on that (i've been trying to scroll though the docs, but can't find much...)

Thanks.
Jok

Reply by email

Marc Weustink
to Marc Weustink: + From: dvortex + + That's what i was afraid of :o) + + well, for the FPC guys: if i put…
dvortex wrote 11 lines
On Wed, 26 Apr 2000, Marc Weustink wrote: > A variant is just a TVarData. The compiler puts type checking/conversion > stuff around it. I can imagine that you don't want to put this in a > compiler. (Let the developer put some code around it). > > You can also use the good old TVarRec > Where can i get some info on that (i've been trying to scroll though the docs, but can't find much...)

There isn't much. If you realy want to use Variants declare them as TVarData. Assign them trought the Vxx members and set the type.

Marc

Reply by email

dvortex
to Michael Van Canneyt: Actually, the best and easiest would be to use TVarRec and use overloaded operators. This…

2 things:

Where is TVarRec declared ?
(so i can start from there and overload it ... --hehehe i love that word--)

Can someone tell me if this is correct:

Load typinfo.pp from ./rtl/objpas.pp
go to line 90
this is the declaration of a type called TTypeData (if i read this right). The first line under (line 91) is a case statement (sort of like what i asked earlier). i do not understand how this works. it doesn't make any sense to me. i visualize this as having a record that has different property depending of the value of one.

for instance, if mastervalue is "175" then there will also be a property called "subvalue" of a certain type, which would be different is mastervalue had a different value. In this case (the typinfo.pp), i don't see the "mastervalue" element/property...

someone care to spend some time to explain to me this ?

Thanks :o)
---
Nothing is foolproof to a sufficiantly talented fool.

Michael Van Canneyt wrote 26 lines
On Wed, 26 Apr 2000, dvortex wrote: > I just found a type "variant" in typinfo as "pointer" > > I'm going to get my own class to do this, it will be a little more "clean" > we will see. Actually, the best and easiest would be to use TVarRec and use overloaded operators. This can then 1) Be used immediatly. 2) Be inserted in the compiler at a later stage with little effort. It was on my todo list to start this after we release 1.0, but if you can do the overloaded stuff already, then this would definitely get used. Using the overloaded stuff means that all Delphi expressions using variants would work. Michael. _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus

Reply by email

Michael Van Canneyt
to Marc Weustink: + From: ]On + Behalf Of Michael Van Canneyt + + + > Is there a check on this? I allways…
Marc Weustink wrote 21 lines
+ From: ]On + Behalf Of Michael Van Canneyt + + On Thu, 27 Apr 2000, Marc Weustink wrote: + + > 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) Ah, as I thought. A is like a reminder for you as developer which filed to use.

Yes. And in the Variant, this is used to determine the type of the currently stored value.

Michael.

Reply by email

Michael Van Canneyt
to dvortex: That's exactly what is confusing to me .... so how does this one work ? (i'm just curious…
dvortex wrote 43 lines
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.

Reply by email

Michael Van Canneyt
to dvortex: 2 things: Where is TVarRec declared ? (so i can start from there and overload it ...…
dvortex wrote 15 lines
2 things: Where is TVarRec declared ? (so i can start from there and overload it ... --hehehe i love that word--) Can someone tell me if this is correct: Load typinfo.pp from ./rtl/objpas.pp go to line 90 this is the declaration of a type called TTypeData (if i read this right). The first line under (line 91) is a case statement (sort of like what i asked earlier). i do not understand how this works. it doesn't make any sense to me. i visualize this as having a record that has different property depending of the value of one.

Correct.

Show quoted text 5 lines
for instance, if mastervalue is "175" then there will also be a property called "subvalue" of a certain type, which would be different is mastervalue had a different value. In this case (the typinfo.pp), i don't see the "mastervalue" element/property...

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.

someone care to spend some time to explain to me this ?

Have a look at the docs.

Michael.

Reply by email

dvortex
to Michael Van Canneyt: There is no check; you must do the check. The point is that there are 2 constructs Case A…
Michael Van Canneyt wrote 38 lines
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 ? (i'm just curious here, because i will be using the second one, although now i am going towards a TVariant class type object with that sort of construct... :o)

ok, back at hacking ...

Jok

Reply by email

Unknown author

Well, is you want to be Delphi Compatible, you should use the same definition which is:

const
  vtInteger    = 0;
  vtBoolean    = 1;
  vtChar       = 2;
  vtExtended   = 3;
  vtString     = 4;
  vtPointer    = 5;
  vtPChar      = 6;
  vtObject     = 7;
  vtClass      = 8;
  vtWideChar   = 9;
  vtPWideChar  = 10;
  vtAnsiString = 11;
  vtCurrency   = 12;
  vtVariant    = 13;
  vtInterface  = 14;
  vtWideString = 15;
  vtInt64      = 16;
type
  PVarRec = ^TVarRec;
  TVarRec = record
    case Byte of
      vtInteger:    (VInteger: Integer; VType: Byte);
      vtBoolean:    (VBoolean: Boolean);
      vtChar:       (VChar: Char);
      vtExtended:   (VExtended: PExtended);
      vtString:     (VString: PShortString);
      vtPointer:    (VPointer: Pointer);
      vtPChar:      (VPChar: PChar);
      vtObject:     (VObject: TObject);
      vtClass:      (VClass: TClass);
      vtWideChar:   (VWideChar: WideChar);
      vtPWideChar:  (VPWideChar: PWideChar);
      vtAnsiString: (VAnsiString: Pointer);
      vtCurrency:   (VCurrency: PCurrency);
      vtVariant:    (VVariant: PVariant);
      vtInterface:  (VInterface: Pointer);
      vtWideString: (VWideString: Pointer);
      vtInt64:      (VInt64: PInt64);
end;

Hope his help

Vital Tremblay

Reply by email

Michael Van Canneyt
to Marc Weustink: Is there a check on this? I allways thought that 1 and 2 are just placeholders? Marc
Marc Weustink wrote 14 lines
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.

Michael.

Show quoted text 11 lines
Marc _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.miraclec.com/list_archives/lazarus

Reply by email

Marc Weustink
to Michael Van Canneyt

+ From: ]On
+ Behalf Of Michael Van Canneyt
+
+ On Thu, 27 Apr 2000, Marc Weustink wrote:
+
+ > 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)

Ah, as I thought. A is like a reminder for you as developer which filed to use.

Marc

Reply by email

Marc Weustink
to Michael Van Canneyt: Actually, the best and easiest would be to use TVarRec and use overloaded operators. This…
dvortex wrote 5 lines
2 things: Where is TVarRec declared ? (so i can start from there and overload it ... --hehehe i love that word--)

They are defined in system.pas (Delphi) and as part of system.pp in objpash.inc (FPC)

Show quoted text 9 lines
Can someone tell me if this is correct: Load typinfo.pp from ./rtl/objpas.pp go to line 90 this is the declaration of a type called TTypeData (if i read this right). The first line under (line 91) is a case statement (sort of like what i asked earlier). i do not understand how this works. it doesn't make any sense to me. i visualize this as having a record that has different property depending of the value of one.

Nope, these values are a kind of placeholders. AFAIK they don't have a meaning (exept for the developer). Fields are reffered through their name (and therefore must be unique)

someone care to spend some time to explain to me this ?

See my other mail.

Marc

Reply by email