Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I use ParameterizedThreadStart in thread.create ?

27 views
Skip to first unread message

jack

unread,
Sep 11, 2008, 4:16:55 AM9/11/08
to wangwe...@gmail.com
hi;
I have one procedure computer_func(value:string) with param,I want
to use thread to run this procedure.First I write like this:
t:=system.Threading.Thread.Create(computer_func);
compile error ,error infomation is :
[DCC Error] threadmain.pas(98): E2250 There is no overloaded version
of 'Create' that can be called with these arguments;
then I use Delegate.CreateDelegate to get
ParameterizedThreadStart ,then compile is passed,but excution at the
call Delegate.CreateDelegate is error,the error info is: can't find
method;the code like below:

procedure TForm5.startClick(Sender: TObject);
var num:integer;
I: Integer;
t:thread;
newtp: ParameterizedThreadStart;
mei:MethodInfo ;
systype:system.&Type;
begin
num:=convert.ToInt32(edit1.Text);
for I := 0 to num - 1 do
begin
systype:=self.GetType;
mei:=systype.GetMethod('computer_func');
if mei=nil then
showmessage('err');

try

newtp:=Delegate.CreateDelegate(typeof(ParameterizedThreadStart),form5,'computer_func',true)
as ParameterizedThreadStart ;
except on e:exception do
begin
showmessage(e.Message);
end;

end;

// newtp:=@computer_func;
t:=system.Threading.Thread.Create(newtp);
threadlist.Add(t);
t.Start(i.ToString);
end;
end;

0 new messages