I cannot use DataModule1:=TDatamodule.create(self); in the Thread's
constructor because self has to be a Tcomponent and TThread is not.
Is there a way around this?
Can I substitute (Application) for (self)?
or do I need to make an array of :TDataModule variables in my main
application one for each thread?
Wasn't sure which newsgroup to ask.
Thanks in advance for any help received.
DataModule1 := TDataModule.Create( nil );
The TComponent constructor parameter is the Owner. The Owner's
principle responsibility is memory management, i.e. the owner is
responsible for for freeing memory of all owned objects. When you
create a component without an owner (nil) then you are responsible for
freeing the object. In your example, can free the TDatabase in a try
/ finally block in the Thread execute method.
procedure TMyThread.Execute;
begin
DataModule1 := TDataModule.Create( nil );
try
...
finally
DataModule1.Free;
end;
end;
Note that for threaded database operations, you will usually want to
create a TSession object, to assign to the TDatabase Session property
as well.
michael...@mci.com
mci Network Systems Integration Lab
Richardson, Texas
In your example I guess I put my while not terminated loop inside the
try finally:-
try
while not terminated do
begin
end;
finally
DataModule1.Free;
end;
Is this what you meant?
>Thank you,
>yes I have one Tsession component, one Tdatabase component and a number
>of TStoredProc s placed on my DataModule .DFM at design time, but
>configuring their properties at run time.
>Is that ok?
>
>In your example I guess I put my while not terminated loop inside the
>try finally:-
>
> try
> while not terminated do
> begin
>
> end;
> finally
> DataModule1.Free;
> end;
>
>Is this what you meant?
>
Correcto.