dormky 2 Posted Wednesday at 01:33 PM Consider : program ProjectThreadProc; {$APPTYPE CONSOLE} {$R *.res} uses System.Classes, Winapi.Windows; type TMyRecord = class data: Integer; class procedure Queue(const AThread: TThread; AMethod: TThreadMethod); end; class procedure TMyRecord.Queue(const AThread: TThread; AMethod: TThreadMethod); begin OutputDebugString(PChar('In TMyRecord.Queue')) end; begin TThread.Queue(nil, procedure begin OutputDebugString(PChar('Hello !')) end); TMyRecord.Queue(nil, procedure begin OutputDebugString(PChar('Hello !')) end); end. This will give you, under 10.3 : [dcc32 Error] ProjectThreadProc.dpr(25): E2010 Incompatible types: 'TThreadMethod' and 'Procedure' Notice that the line for TThread has no problems, and this compiles if you comment the call to TMyRecord.Queue. Problem is, on the face of it those two functions have the exact same signature : So why does TMyRecord.Queue not compile ? I'm baffled. The end goal here is to pass an anonymous function to a thread, to be executed there. Share this post Link to post
Lajos Juhász 293 Posted Wednesday at 01:54 PM program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.Classes, Winapi.Windows; type TMyRecord = class data: Integer; class procedure Queue(const AThread: TThread; AMethod: TThreadProcedure); end; class procedure TMyRecord.Queue(const AThread: TThread; AMethod: TThreadProcedure); begin OutputDebugString(PChar('In TMyRecord.Queue')) end; begin TThread.Queue(nil, procedure begin OutputDebugString(PChar('Hello !')) end); TMyRecord.Queue(nil, procedure begin OutputDebugString(PChar('Hello !')) end); end. It should be TThreadProcedure not method. 1 Share this post Link to post
dormky 2 Posted Wednesday at 02:09 PM Here I was sitting and wondering how the hell it was compiling TThread when it should be TThreadProcedure for it too... Before noticing the overload beneath the function Delphi navigated to. God bless Delphi's function navigation, somehow worse at it than Christopher Colomb. Good job noticing this ! Share this post Link to post
Remy Lebeau 1392 Posted Wednesday at 05:45 PM In general, RTL types named TXXXMethod refer to non-static class methods, and TXXXProcedure types refer to anonymous procedures. Share this post Link to post