//这个unit就是现成的定义
unit gothread;interfaceuses
  Classes,forms,windows;type
  go = class(TThread)
  private
    fm:tform;
    step1:integer;
    { Private declarations }
  protected
    procedure Execute; override;
    procedure walk;
  public
    constructor create(form:tform;s1:integer);
  end;implementation
{ Important: Methods and properties of objects in VCL can only be used in a
  method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure go.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }{ go }constructor go.create(form:tform;s1:integer);
begin
    inherited create(false);
    fm:=form;
    step1:=s1;
    Priority:=tpIdle;
    freeonterminate:=true;
end;procedure go.walk;
var i,j:integer;
begin
with fm do begin
  left:=0-width;
  visible:=true;
  j:=(screen.Width-width) div 2;
  i:=1;
  repeat
    left:=left+i;
    i:=i+step1;
    inc(step1);
    sleep(2*step1);
  until left+i>j;
end;
end;procedure go.Execute;
begin
  { Place thread code here }
  synchronize(walk);
end;end.//在另一个form中USES GOTHREADprocedure TForm3.FormCreate(Sender: TObject);
const logobmpfile='start.bmp';
VAR RUSH:GO;
begin
if FileExists(logobmpfile) then
begin
  image1.picture.loadfromfile(logobmpfile);
  width:=image1.Picture.Width;
  height:=image1.Picture.Height;
  left:=0-width;
  SetWindowRgn(handle,CreateEllipticRgn(width-clientwidth,height-clientheight,clientwidth,clientheight),true);
  rush:=go.create(self,1);
end
else
begin
    release;
    Application.CreateForm(TForm1, Form1);
end;//form 的create事件中只有 rush:=go.create(self,1);这一句创建了线成并执
行,这个线成是用来控制一个form出现时从做到右加速跑到屏幕中心就停止

解决方案 »

  1.   

    我觉得使用多线程要好,但最好不要使用delphi自带的线程对象
      

  2.   

    delphi自带的和用api createthread其实一样啊,delphi自带也是调用的api,用起来还是很方便的。
      

  3.   

    主要看你的程序的作用是什么了.
    如果你要是一个等待循环,必须得到返回值,那么就用application.processmessages,它是去处理了系统的其他消息.等于把对CPU的控制权交出去.
    而如果你循环等待的东西与你循环完毕之后执行的内容毫无关系,就用多线程,你可以创建一个线程类,就如同 liuhelin(鹤林)说的那样,如果创建一个临时线程,可以直接用Delphi自己的函数,这样比较简单.
      

  4.   

    我人为还是用application.processmessages比较好,简单。我在做数据导入的时候当时我用到的就是这个,当时我也准备用多线程,后来别人要我用这个方法,很简单的。
      

  5.   

    只一个普通的大循环一PROCESS,如果要做别的事就最好是多线程
      

  6.   

    用多线程查MSDN中SDK中的CreateThread() FUNCTION,如果是写类的话就查别的它里面说的够详细了.如果这还不够你就别用多线程了