Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TThread.Queue overload not found

Tags:

delphi

This simple program doesn't compile. [Tested with XE5 and D10.]

program Project10;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.Classes;

function MakeProc: TThreadProcedure;
begin
  Result := procedure begin end;
end;

begin
  TThread.Queue(nil, MakeProc);
end.

Compiler reports error

[dcc32 Error] Project10.dpr(16): E2250 There is no overloaded version of 'Queue' that can be called with these arguments

in the TThread.Queue call.

Class TThread implements two Queue overloads.

class procedure Queue(const AThread: TThread; AMethod: TThreadMethod); overload; static;
class procedure Queue(AThread: TThread; AThreadProc: TThreadProcedure); overload; static;

I'm pretty sure that my code should match the second overload.

The only workaround I was able to find is this:

TThread.Queue(nil, procedure begin MakeProc; end);

Am I doing something wrong or is this a compiler bug? Is there a better workaround than my ugly hack?

like image 562
gabr Avatar asked May 02 '26 13:05

gabr


1 Answers

The compiler evidently thinks you're trying to pass MakeProc itself as the argument. You can tell the compiler that you intend to call that function instead by adding parentheses, just as you would if the function took parameters:

TThread.Queue(nil, MakeProc());

Your workaround wouldn't seem to work. It would compile and run, but the function returned by MakeProc would never execute. Instead, the anonymous method wrapping MakeProc would run, call MakeProc, and then discard that function's result. (Since the function's result doesn't do anything in the code you've provided, you might not have noticed the difference.)

like image 78
Rob Kennedy Avatar answered May 05 '26 02:05

Rob Kennedy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!