Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VarType() - Delphi 5 vs 6

156 views
Skip to first unread message

Brian Drennan

unread,
Nov 20, 2001, 2:50:04 PM11/20/01
to
It appears the implicit typecast done when passing a constant or enumerated
type to a method with a parameter of type Variant, has changed from Delphi 5
to Delphi 6.

For example, create a new application, double-click the Form1 object to
create a FormCreate() event handler and add the following line:
ShowMessage(IntToStr(VarType(1)));

Under Delphi 5, this shows '3' which corresponds to varInteger. However,
under Delphi 6 (with or without Update Pack 1) '17' is shown which
corresponds to varByte. The same problem occurs if you pass an enumerated
type.

We discovered this problem while using TopGrid 2.20 with Delphi 6. Trying to
assign a Variant parameter to cbChecked (one of the TCheckBoxState
enumeration constants) ends up raising an exception because the TopGrid code
depends on the result of a call to VarType().

This means any code which depends on the result of a call to VarType() when
a constant or enumerated type is passed, will fail under Delphi 6. It could
be argued that code should not have such a dependency since the 'type' of an
enumeration constant should be considered undefined. However, if this change
was made, it would have been nice if it was documented.

We have submitted this as a bug to Borland and are awaiting a response. Has
anyone else come across this problem?

Brian Drennan

Jeff Overcash (TeamB)

unread,
Nov 20, 2001, 2:58:33 PM11/20/01
to

Brian Drennan wrote:
>
>
> We have submitted this as a bug to Borland and are awaiting a response. Has
> anyone else come across this problem?
>

This is not a bug. Variants were totally rewritten under D6. Unlike D5
Variants, the D6 Variants has a much higher granularity. So the VarType of 1 is
a byte because this is the smallest granularity that 1 fits in. The D5 Variants
the smallest granularity is an integer.

You can find Eddie Churchill's explanation at
http://www.mers.com/MERLIST/BORLAND/PUBLIC/DELPHI/UPGRADE/2460.HTML

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
The fool escaped from paradise will look over his shoulder and cry
Sit and chew on daffodils and struggle to answer why?
As you grow up and leave the playground
Where you kissed your Prince and found your frog
Remember the jester that showed you tears, the script for tears. (Fish)

Brian Drennan

unread,
Nov 20, 2001, 3:19:21 PM11/20/01
to
> This is not a bug. Variants were totally rewritten under D6. Unlike D5

Fair enough. Though it would have been nice to have been documented
somewhere- anywhere!

> http://www.mers.com/MERLIST/BORLAND/PUBLIC/DELPHI/UPGRADE/2460.HTML

A most useful link. Thanks for your reply.

Brian Drennan


John Herbster

unread,
Nov 20, 2001, 4:23:25 PM11/20/01
to
"Brian Drennan" <bdre.n...@guardall.com> wrote

> It appears the implicit typecast done when passing a constant or
enumerated type to a method with a parameter of type Variant, has changed
from Delphi 5 to Delphi 6.

> ShowMessage(IntToStr(VarType(1)));

> Under Delphi 5, this shows '3' which corresponds to varInteger. However,
under Delphi 6 (with or without Update Pack 1) '17' is shown which
corresponds to varByte.

Brian, Different, yes; but I would consider that they both are correct.and
thus neither should be classified as a bug. If there is a problem, I
suggest that it may be with routines that do not correctly interprete the
variant types. Regards, JohnH


0 new messages