Board index » delphi » Help: Thread question.

Help: Thread question.

I have been playing about with threads, and think I have got the hang
of them (fun aren't they!)
Anyway, I now have to create some workspace in the thread for a
Tstring...
I have already got a custom contructor which reads.....

  constructor tmythread.create(somedata:string);
  begin
    localdata:=somedata;
    status:=tstringlist.create;
    inherited create(true); //thread does not start until resumed.
  end;

Which creates a stringlist.... I have this nagging feeling I need to
do a free on this when I finish the thread, so I guess that's a custom
destructor... Trouble is I can't find any example of one of these
beasts... could someone tell me how I would do it with this example?

I tried

  destructor tmythread.terminate;
  begin
    status.free;
    inherited terminate;
  end;

But it sort of went POP!

Many Thanks

Dodgy.

 

Re:Help: Thread question.


Quote
Dodgy wrote:
> Which creates a stringlist.... I have this nagging feeling I need to
> do a free on this when I finish the thread, so I guess that's a custom
> destructor... Trouble is I can't find any example of one of these
> beasts... could someone tell me how I would do it with this example?

You do it like any other class.  Override the destructor Destroy

destructor TMyThread.Destroy;
begin
    status.free;
    inherited Destroy;
end;

--
Bob Lee
High Performance Delphi - http://www.econos.com/optimize/

Re:Help: Thread question.


Hi !

I think you've been mixing "terminate" with "destroy". "Terminate" method of TThread isn't a
destructor. If you set FreeOnTerminate to true, the destructor is invoked on termination of the
thread. Otherwise you'll have to make an explicit call to TMyThread.free;.The natural place to put
the Status.free is in the destructor. The thread needs to be freed somehow, and then is your
TStringList freed, as well.

--

Bjoerge

<<Dodgy skrev i meldingen <378f26db.5335...@news.clara.net>...
I have been playing about with threads, and think I have got the hang
of them (fun aren't they!)
Anyway, I now have to create some workspace in the thread for a
Tstring...
I have already got a custom contructor which reads.....

  constructor tmythread.create(somedata:string);
  begin
    localdata:=somedata;
    status:=tstringlist.create;
    inherited create(true); //thread does not start until resumed.
  end;

Which creates a stringlist.... I have this nagging feeling I need to
do a free on this when I finish the thread, so I guess that's a custom
destructor... Trouble is I can't find any example of one of these
beasts... could someone tell me how I would do it with this example?

I tried

  destructor tmythread.terminate;
  begin
    status.free;
    inherited terminate;
  end;

But it sort of went POP!

Many Thanks

Dodgy.

Quote

Re:Help: Thread question.


On Sat, 17 Jul 1999 04:11:37 +0200, "Bj?rge S?ther"
<REMOVE_bsaet...@online.no> waffled on about something:

Quote
>Hi !

>I think you've been mixing "terminate" with "destroy". "Terminate" method of TThread isn't a
>destructor. If you set FreeOnTerminate to true, the destructor is invoked on termination of the
>thread. Otherwise you'll have to make an explicit call to TMyThread.free;.The natural place to put
>the Status.free is in the destructor. The thread needs to be freed somehow, and then is your
>TStringList freed, as well.

Thanks, I think that might be what I have been doing....

Dodgy.

Other Threads