Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Thread & DataModule

374 views
Skip to first unread message

Wynne Carter

unread,
Dec 7, 1998, 3:00:00 AM12/7/98
to
I wish to create an instance of a DataModule for each of my threads with
DataModule1:TdataModule; in the private decs of my thread object;

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.

Michael Godeck

unread,
Dec 7, 1998, 3:00:00 AM12/7/98
to
You could simply pass nil as the constructor parameter.

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

Wynne Carter

unread,
Dec 7, 1998, 3:00:00 AM12/7/98
to
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?

Michael Godeck

unread,
Dec 8, 1998, 3:00:00 AM12/8/98
to
On Mon, 07 Dec 1998 16:58:37 -0800, Wynne Carter
<N.W.C...@Dundee.ac.uk> wrote:

>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.

0 new messages