收录日期:2019/02/17 00:14:56 时间:2016/05/29 18:11:47 标签:VCL组件开发及应用
我要在线程中运行自己定义的函数fun,如何实现??
从定义开始,谢谢
定义一个线程类
TYourThread = Class(TThread)
private
  function fun: YourType;
protected
  procedure Execute; override;
end;

TYourThread.Execute;
begin
  fun;
end;

然后在需要的地方创建这个线程类就可以了

var
  YourThread : TYourThread; 
begin
  YourThread := TYourThread.Create(False);
end;
mk!
unit Unit2;

interface

uses
  Classes,SysUtils;

type
  TmyThread = class(TThread)
  private
    { Private declarations }
    fa:Tstrings;
  protected
    procedure Execute; override;
  public
     constructor Create(CreateSuspended: Boolean;a:Tstrings);
  end;

implementation
constructor TmyThread.Create(CreateSuspended: Boolean;a:Tstrings);
begin
  fa:=a;
  inherited create(CreateSuspended);
end;
procedure test(a:Tstrings);
var i:integer;
begin
  for i:=0 to 100 do
  begin
    a.Add(inttostr(i));
  end;
end;
procedure TmyThread.Execute;
begin
  { Place thread code here }
  test(fa);
end;

end.
var   ff:TmyThread;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  ff:=TmyThread.Create(false,memo1.Lines);
end;

如何将自己的控制面板程序集成到系统控制(如显示属性对话框)? Response.Write(\"