 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ian Hinson Guest
|
Posted: Wed Jun 21, 2006 5:56 pm Post subject: Simulating VB Nothing variant in Delphi |
|
|
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. |
|
| Back to top |
|
 |
Mike Shkolnik Guest
|
Posted: Thu Jun 22, 2006 12:39 am Post subject: Re: Simulating VB Nothing variant in Delphi |
|
|
UnAssigned in Delphi is the same as Nothing in VB
cat.ActiveConnection := UnAssigned;
--
With best regards, Mike Shkolnik
E-mail: mshkolnik (AT) scalabium (DOT) com
WEB: http://www.scalabium.com
"Ian Hinson" <pparagon (AT) bigpond (DOT) net.au> wrote in message
news:44994410$1 (AT) newsgroups (DOT) borland.com...
| Quote: | 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.
|
|
|
| Back to top |
|
 |
Ian Hinson Guest
|
Posted: Thu Jun 22, 2006 4:36 am Post subject: Re: Simulating VB Nothing variant in Delphi |
|
|
"Mike Shkolnik" <mshkolnik2002 (AT) ukr (DOT) net> wrote in message
news:4499a17d (AT) newsgroups (DOT) borland.com...
| Quote: | 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), )
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.
| Quote: |
--
With best regards, Mike Shkolnik
E-mail: mshkolnik (AT) scalabium (DOT) com
WEB: http://www.scalabium.com
"Ian Hinson" <pparagon (AT) bigpond (DOT) net.au> wrote in message
news:44994410$1 (AT) newsgroups (DOT) borland.com...
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.
|
|
|
| Back to top |
|
 |
Steve Zimmelman Guest
|
Posted: Fri Jun 23, 2006 5:51 pm Post subject: Re: Simulating VB Nothing variant in Delphi |
|
|
Mike is correct. Use UnAssigned when using COM and OleVariants.
********************
From Delphi Help:
********************
In the code fragment shown below, the statement that assigns Unassigned to the
MSWord variable causes the OLE Automation Object that was created to interface
with Word to be released.
var
MSWord: Variant;
begin
...
MSWord := CreateOleObject('Word.Basic');
...
MSWord := Unassigned;
...
end;
********************
In VB it would be [Set MSWord = Nothing].
-Steve-
"Ian Hinson" <pparagon (AT) bigpond (DOT) net.au> wrote in message
news:4499d7fb (AT) newsgroups (DOT) borland.com...
| Quote: | "Mike Shkolnik" <mshkolnik2002 (AT) ukr (DOT) net> wrote in message
news:4499a17d (AT) newsgroups (DOT) borland.com...
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. |
|
|
| Back to top |
|
 |
Viatcheslav V. Vassiliev Guest
|
Posted: Sat Jun 24, 2006 8:11 am Post subject: Re: Simulating VB Nothing variant in Delphi |
|
|
In most cases Unassigned (or Null) will work, however in few special cases
IDispatch(nil) should be used instead of Unassigned (some ActiveX components
may have different actions for these two).
//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Steve Zimmelman" <skz (AT) charter (DOT) nospam.net> сообщил/сообщила в новостях
следующее: news:449bd5c9$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Mike is correct. Use UnAssigned when using COM and OleVariants.
********************
From Delphi Help:
********************
In the code fragment shown below, the statement that assigns Unassigned to
the MSWord variable causes the OLE Automation Object that was created to
interface with Word to be released.
var
MSWord: Variant;
begin
...
MSWord := CreateOleObject('Word.Basic');
...
MSWord := Unassigned;
...
end;
********************
In VB it would be [Set MSWord = Nothing].
-Steve-
"Ian Hinson" <pparagon (AT) bigpond (DOT) net.au> wrote in message
news:4499d7fb (AT) newsgroups (DOT) borland.com...
"Mike Shkolnik" <mshkolnik2002 (AT) ukr (DOT) net> wrote in message
news:4499a17d (AT) newsgroups (DOT) borland.com...
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.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|