procedure RunAnonymousThread;
var
FThread: TAnonymousThread<Boolean>;
begin
FThread := TAnonymousThread<Boolean>.Create(
function: Boolean
begin
// Runs in separate thread
// run your thread safe code
// example:
//RESTClient.Execute;
// remember in a thread any graphical changes have to be wrapped in Synchronize()
//Synchronize(
//procedure
// begin
// Form1.Memo1.Lines.Add('Begin Execution');
// end);
Result := True;
end,
procedure(AResult: Boolean)
begin
// Runs in main thread
// process the result from above
end,
procedure(AException: Exception)
begin
// Runs in main thread
// do something if there is an exception
end,
False);
end;
You can read the full blog post about anonymous threads here.