Re: Simulating VB Nothing variant in Delphi
- From: "Ian Hinson" <pparagon@xxxxxxxxxxxxxx>
- Date: Thu, 22 Jun 2006 09:36:10 +1000
"Mike Shkolnik" <mshkolnik2002@xxxxxxx> wrote in message
news:4499a17d@xxxxxxxxxxxxxxxxxxxxxxxxx
UnAssigned in Delphi is the same as Nothing in VB
cat.ActiveConnection := UnAssigned;
Have to disagree on that, sorry.
The Unassigned function returns a variant with VType varEmpty,
whereas the Nothing variant in VBA is a variant with VType varDispatch.
I examined an actual "Nothing" variant by passing it from VBA into
a DLL that I wrote in Delphi in order to discover its characteristics.
Here's the code I used. (It works fine.)
procedure AnalyseVariant(v: OLEVariant; szResult: PChar); stdcall;
begin
if VarType(v) = varEmpty then
StrPCopy(szResult, 'The variant is empty.')
else if VarType(v) = varDispatch then
StrPCopy(szResult, IntToHex(integer(TVarData(v).VDispatch), 8))
else // extra analysis could be added here
StrCopy(szResult, 'Neither empty or an Object variant');
end;
exports
AnalyseVariant;
When called from VBA with Nothing as the "v" parameter it shows
that the v parameter is not empty, but instead is a Nil "Object".
Object is a generic root class commonly used in VBA to store
dispatchable COM objects of any type.
Best regards,
Ian.
--
With best regards, Mike Shkolnik
E-mail: mshkolnik@xxxxxxxxxxxxx
WEB: http://www.scalabium.com
"Ian Hinson" <pparagon@xxxxxxxxxxxxxx> wrote in message
news:44994410$1@xxxxxxxxxxxxxxxxxxxxxxxxx
Often in VB code you see statements like:
Set cmd.ActiveConnection = Nothing
or
Set dbs = Nothing
To simulate Nothing in Delphi use:
var
vntNothing: OLEVariant;
begin
TVarData(vntNothing).VType := varDispatch;
TVarData(vntNothing).VDispatch := Nil;
// then you can do things like..
cat.Set_ActiveConnection(vntNothing);
without getting a data type mismatch.
Ian.
.
- Follow-Ups:
- Re: Simulating VB Nothing variant in Delphi
- From: Steve Zimmelman
- Re: Simulating VB Nothing variant in Delphi
- References:
- Simulating VB Nothing variant in Delphi
- From: Ian Hinson
- Re: Simulating VB Nothing variant in Delphi
- From: Mike Shkolnik
- Simulating VB Nothing variant in Delphi
- Prev by Date: Re: Simulating VB Nothing variant in Delphi
- Next by Date: CDS, Query and Access
- Previous by thread: Re: Simulating VB Nothing variant in Delphi
- Next by thread: Re: Simulating VB Nothing variant in Delphi
- Index(es):
Relevant Pages
|