Re: Simulating VB Nothing variant in Delphi



"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.






.



Relevant Pages

  • Re: if I can get a pointer with objptr
    ... I think it was Bill Gates himself who decided that VB and VBA would ... not support pointers ... ... Every variant has a subtype ... ... dim ptr as long ...
    (microsoft.public.access.formscoding)
  • Class properties or function?
    ... I've got a COM add in for Word and I'd like to use VBA macros to process ... Public Property Let myTag(ByVal strReturnValue As Variant) ... Dim frmForm As Form ...
    (microsoft.public.vb.general.discussion)
  • Re: Earliest Date
    ... I must have something wrong because I always get zero. ... I copied the VBA ... > Public Function LeastAs Variant) As Variant ... > Dim min As Variant ...
    (microsoft.public.access.queries)
  • Re: How do I declare a variable as a Variant
    ... Use the Dim statement to declare the variable as a Variant, and then try the operation again. ... >How do I do this in the Design View or the SQL window of the query? ... VBA is one language; ...
    (microsoft.public.access.queries)