Hi all
Hi all,
in this code: https://gist.github.com/jkour/4263ddf4cb97ae3b40b548593f992dfa
shouldn't I be able to get the value of i while the thread is running?
Shouldn't the Thread wait for the completion before freeing the object?
Thanks a lot for any input.
https://gist.github.com/jkour/4263ddf4cb97ae3b40b548593f992dfa
in this code: https://gist.github.com/jkour/4263ddf4cb97ae3b40b548593f992dfa
shouldn't I be able to get the value of i while the thread is running?
Shouldn't the Thread wait for the completion before freeing the object?
Thanks a lot for any input.
https://gist.github.com/jkour/4263ddf4cb97ae3b40b548593f992dfa
I can't access Memo1 directly. But this is the whole point of what I am trying to achieve---to call an external procedure
ReplyDeleteI mean to use that inside the TForm.Update method.
ReplyDeleteJust to give an idea how a non-blocking solution would look like:
ReplyDeleteconstructor TDemo.Create (const aUpdate: TUpdate);
var
dbTask: ITask;
dbTaskArray: array [0..0] of ITask;
begin
fUpdate:= aUpdate;
TTask.Create(
procedure
begin
dbTask:= TTask.Create(
procedure
function CatchValue(progress:Integer): TThreadProcedure;
begin
Result := procedure
begin
fUpdate(progress.ToString);
end;
end;
var
i: Integer;
begin
for i := 0 to 10000 do
begin
TThread.Queue(nil,CatchValue(i));
end;
end
);
dbTaskArray[0]:=dbTask;
dbTask.Start;
TTask.WaitForAll(dbTaskArray);
TThread.Synchronize(nil, procedure begin fUpdate('Done'); end);
end).Start;
end;
It wraps the for..in task in a new task and when the for..in task is done, it adds a message to the memo.