🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #2139

CoInitialize/CoUninitialize placement

#2139
From: Ted Byers
Date: Wed, 22 Oct 2003 20:26
29 lines
1931 bytes
I pulled an ADO example project off BDN.  I am puzzled by the following two
functions.

void __fastcall TForm1::FormActivate(TObject *Sender)
{
CoInitialize(NULL);
Form1->Catalog=Variant::CreateObject("ADOX.Catalog");
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::FormDeactivate(TObject *Sender)
{
CoUninitialize();
}

Yes, it is fairly obvious as to what they are supposed to do, but why place
calls to CoInitialize and CoUninitialize in FormActivate/FormDeactivate?
Does this provide any advantage or is it just a question of the style and
habits of the person who developed this particular example?

Would it not be better/safer to put calls to CoInitialize and CoUninitialize
in the constructor and destructor of a singleton class, instaniated in a
global static variable?  If I could do this, then I'd put the statement
"Form1->Catalog=Variant::CreateObject("ADOX.Catalog");" into TForm1's
constructor (and get rid of the unnecessary "Form1->").

Cheers,

Ted
Technical Details
Message-ID: <3f96e8cd@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,6f95adbac89050a,start
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-10-22 13:40:11 PST
From: "Ted Byers" <r.ted.byers@sympatico.ca>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: CoInitialize/CoUninitialize placement
Date: Wed, 22 Oct 2003 16:26:22 -0400
Lines: 31
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 65.95.242.89
Message-ID: <3f96e8cd@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1066854605 65.95.242.89 (22 Oct 2003 13:30:05 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail