Page 1 of 1
CoInitialize with IntraWeb
Posted: Wed 14 Jun 2006 14:37
by Sawlmgsj
Do you have a code snippet to show the syntax I need to get started with IntraWeb?
I get the message that CoInitialize has not been called, although I have included that as:
CoInitialize(nil);
Where should that go in my code?
Delphi 7 + IntraWeb 7 trial.
Thanks,
Steve.
Posted: Thu 15 Jun 2006 08:06
by Jackson
You need to call CoInitialize(nil) from unit ActiveX.pas before first connection. Also do not forget to call CoUnInitialize after work is done.
Position of CoInitialize
Posted: Thu 15 Jun 2006 10:56
by Sawlmgsj
Many thanks for you help.
I have written this code snippet and called CoInitialize in the main form create event. Then set my connection string. A grid does populate from the table.
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
CoInitialize(nil);
myConnection.ConnectString:='Data Source=SERVER;Initial Catalog=Equity;Integrated Security=SSPI';
myConnection.Connected:=True;
MSTable1.Active:=True;
end;
Is this the correct way to do it?
Where should I call CoUnInitialize?
Do I have to do this for every form in my web application?
Thanks,
Steve.
Posted: Fri 16 Jun 2006 09:38
by Jackson
You can call CoUnInitialize, for example, in OnDestroy event or in finalization section.
In fact you need to call CoInitialize for each thread before first connection and CoUnInitialize at the end of thread.
IntaWeb
Posted: Fri 16 Jun 2006 13:47
by Sawlmgsj
Many thanks for your help.
Steve.
Posted: Tue 18 Jul 2006 14:42
by Guest
I found a more elegant solution as the whole problem originated from using Intraweb, I rather get Intraweb to initialise com for me. This sorts it out nicely.
When using your MS SQL DbExpress driver or ADO driver with Intraweb, you must set the ComInitialization property in the ServerController to ‘ciMultiThreaded’.
This will eliminates the "CoInitialize has not been called" error.