🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.language.delphi.dotnet
1 messages
1 total messages Started by jack Thu, 11 Sep 2008 08:16
How can I use ParameterizedThreadStart in thread.create ?
#191
Author: jack
Date: Thu, 11 Sep 2008 08:16
45 lines
2592 bytes
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;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads