Ah, my mistake. I overwrote it.
I use trunk on Windows 10 64-bit.
Here:
TRunFunction<T> = class(TThread)
protected
MyName: string; // threadfunction.pas(43,11) Error: Internal error 200204175
MyQueue: TResultQueue;
MyFunction: TThreadFunction<T>;
MyPara: T;
procedure Execute; override;
public
constructor Create(ThisName: string; ThisQueue: TResultQueue;
ThisFunction: TThreadFunction<T>; ThisPara: T);
function PostMessage(ThisValue: Variant; ThisReference: TObject = nil):
Boolean;
end;
I changed it like this:
unit ThreadFunction;
{$mode Delphi}{$H+}
{
Requires PasMP.TPasMPUnboundedQueue in the calling thread!
}
interface
uses
Classes, SysUtils, PasMP, Variants;
type
TRunFunction = class;
{ TRunResult }
TRunResult = class(TObject)
protected
MyName: string;
public
Value: Variant;
Reference: TObject;
property Name: string read MyName;
constructor Create(ThisName: string);
end;
{ TResultQueue }
TResultQueue = class(TPasMPUnboundedQueue<TRunResult>);
{ TThreadFunction }
TThreadFunction = function(ThisThread: TRunFunction; Para1, Para2: Variant;
Para3: TObject): TRunResult of object;
{ TRunFunction }
TRunFunction = class(TThread)
protected
MyName: string;
MyQueue: TResultQueue;
MyFunction: TThreadFunction;
MyPara1: Variant;
MyPara2: Variant;
MyPara3: TObject;
procedure Execute; override;
public
constructor Create(ThisName: string; ThisQueue: TResultQueue;
ThisFunction: TThreadFunction; Para1, Para2: Variant; Para3: TObject = nil);
function PostMessage(ThisValue: Variant; ThisReference: TObject = nil):
Boolean;
end;
implementation
{ TRunResult }
constructor TRunResult.Create(ThisName: string);
begin
MyName := ThisName;
Value := Null;
Reference := nil;
end;
{ TRunFunction }
procedure TRunFunction.Execute;
var
r: TRunResult;
begin
if Assigned(MyFunction) then
begin
r := MyFunction(Self, MyPara1, MyPara2, MyPara3);
if Assigned(MyQueue) then MyQueue.Enqueue(r);
end;
end;
constructor TRunFunction.Create(ThisName: string; ThisQueue: TResultQueue;
ThisFunction: TThreadFunction; Para1, Para2: Variant; Para3: TObject);
begin
inherited Create(True);
FreeOnTerminate := True;
MyName := ThisName;
MyQueue := ThisQueue;
MyFunction := ThisFunction;
MyPara1 := Para1;
MyPara2 := Para2;
MyPara3 := Para3;
Start;
end;
function TRunFunction.PostMessage(ThisValue: Variant; ThisReference: TObject
): Boolean;
var
r: TRunResult;
begin
Result := False;
if Assigned(MyQueue) then
begin
r := TRunResult.Create(MyName);
r.Value := ThisValue;
r.Reference := ThisReference;
MyQueue.Enqueue(r);
Result := True;
end;
end;
end.
With two variants and an object as parameters. That works. But I would prefer a generic version.