BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Simulating VB Nothing variant in Delphi

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Ian Hinson
Guest





PostPosted: Wed Jun 21, 2006 5:56 pm    Post subject: Simulating VB Nothing variant in Delphi Reply with 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
Mike Shkolnik
Guest





PostPosted: Thu Jun 22, 2006 12:39 am    Post subject: Re: Simulating VB Nothing variant in Delphi Reply with quote



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





PostPosted: Thu Jun 22, 2006 4:36 am    Post subject: Re: Simulating VB Nothing variant in Delphi Reply with quote



"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), Cool)
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





PostPosted: Fri Jun 23, 2006 5:51 pm    Post subject: Re: Simulating VB Nothing variant in Delphi Reply with 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...
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





PostPosted: Sat Jun 24, 2006 8:11 am    Post subject: Re: Simulating VB Nothing variant in Delphi Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.