Changing a variable inside of TThread from outside of the Thread.
- From: Landiin@xxxxxxxxx
- Date: 19 Oct 2006 20:46:19 -0700
I'm very new to Threading and playing around with them to try and learn
them.
I've ran into an access violation when trying to change a variable in
the thread from out side the thread.
What I doing is having a thread process some large XML files. In stead
of having the main thread looked in loops I've decided to try my hand
at threading.
Here is the basic/simplified thread code
Type
MyThread = class(TThread)
private
FCancel: Boolean;
...
protected
procedure Execute; override;
public
constructor Create(APath: String; ACallBack: TSyncCallback);
procedure Cancel;
end;
implementation
constructor MyThread.Create(APath: String; ACallBack: TSyncCallback);
begin
inherited Create(True);
...
resume;
end
procedure Execute;
begin
while SomeNode <> nil do
begin
....
if FCancel then Breake;
....
end;
end
procedure Cancel;
begin
FCancel := True;
end;
When ever I do MyThread.Cancel from the forms main thread I get an
access violation when execution reaches FCancel := True;
Keep in mind I am new to Threads and mostly new to programing. But
having a blast learning.
.
- Follow-Ups:
- Re: Changing a variable inside of TThread from outside of the Thread.
- From: Tom de Neef
- Re: Changing a variable inside of TThread from outside of the Thread.
- From: alanglloyd@xxxxxxx
- Re: Changing a variable inside of TThread from outside of the Thread.
- Prev by Date: Re: How to delete from palette
- Next by Date: Re: Changing a variable inside of TThread from outside of the Thread.
- Previous by thread: How to delete from palette
- Next by thread: Re: Changing a variable inside of TThread from outside of the Thread.
- Index(es):
Relevant Pages
|