为了学习线程,特出此贴。
我找过了多线程中的所有贴子。然后自已又试了很多次,但总是有很多问题。
现求一程序功能如下:
   1、采用线程;
   2、在Memo中增加100行。内容随便。
请各位高手帮忙。感谢!

解决方案 »

  1.   

    C:\Program Files\Borland\Delphi7\Demos\Threadsdelphi 帶的 demo 中應該就是你要的
      

  2.   

    我很菜的。
    下面有一段,但出错。
    帮看看。
    unit Unit2;
    interface
    uses
      Classes,SysUtils;
    type
      MyThread = class(TThread)
      private
        { Private declarations }
        procedure AddLineToMemo;
      protected
        procedure Execute; override;  end;implementation
    uses Unit1;
    { Important: Methods and properties of objects in VCL or CLX can only be used
      in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure MyThread.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ MyThread }procedure MyThread.AddLineToMemo;
    begin
      form1.memo1.lines.add('=============');
    end;procedure MyThread.Execute;
    var
      i :integer;
    begin
      { Place thread code here }
      for i := 1 to 100 do
        Synchronize(AddLineToMemo);end;end.在单击事件中有。
    var 
      mythread1:MyThread;
    begin 
      mythread1.create(true);
      mythread1.FreeOnTerminate:=true;
      mythread1.resume;
    end;但
    那个mythread1.resume;的时候出错了。什么内存地址不应该为xxxxxx.
    编译时有一warning.说mythread1没有初始化。
    还是没有成功。请高手再次,赐教。感谢。
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TMyThread = class(TThread)
      private
        FMemo:TMemo;
      protected
        procedure Execute; override;
      public
        constructor Create(Memo:TMemo);
        destructor Destroy; override;
      end;  TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      MyThread :TMyThread;
    begin
      MyThread := TMyThread.Create(Memo1);
    end;{ TMyThread }constructor TMyThread.Create(Memo: TMemo);
    begin
      FMemo := Memo;
      FreeOnTerminate := False;
      inherited Create(False);
    end;destructor TMyThread.Destroy;
    begin  inherited;
    end;procedure TMyThread.Execute;
    var
      i:integer;
    begin
      inherited;
      for i:=1 to 100 do
        FMemo.Lines.Add('Lines'+IntToStr(i));
    end;end.
      

  4.   

    谢谢  bee2518(迷茫ing)   ,   aiirii(ari-爱的眼睛) 
    结帖。