Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function from a function pointer in Delphi

I'm trying to build a generic worker thread in Delphi, one that I can pass a function/procedure (doesn't matter) as an argument and let it execute.

My guess is to add a field in the TThread class and call it from TThread.Execute.

So the code outside the thread is gonna be:

  MyThread := TWorkerThread.Create(True);
  Mythread.CallBackF := @Foo;
  try
    MyThread.Resume;
  except
    MyThread.Free;
  end;

How do I keep a reference of @foo in the TWorkerThread and call it from inside Execute?

like image 516
Ed.C Avatar asked Dec 08 '22 01:12

Ed.C


1 Answers

Also, a good start into using generic threads would be AsyncCalls or Omni Thread Library.

like image 157
skamradt Avatar answered Dec 14 '22 23:12

skamradt