Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Location
    China GuangZhou
    Posts
    2

    Red face Unanswered: How to create Thread in delphi (window2000 OS)

    Can you help me ?
    I spent considerable time to try create a thread in delphi
    (base on os win2000) ,but failed.
    I know that ,if (base on os win98) ,create a thread in delphi,
    it is easy.
    Thanks !!!
    help me please..

  2. #2
    Join Date
    Jan 2004
    Location
    Saint Louis /USA
    Posts
    8

    Re: How to create Thread in delphi (window2000 OS)

    Originally posted by LEMON
    Can you help me ?
    I spent considerable time to try create a thread in delphi
    (base on os win2000) ,but failed.
    I know that ,if (base on os win98) ,create a thread in delphi,
    it is easy.
    Thanks !!!
    help me please..
    This is a counter. I thing that would be enought to give you an ideea of how it works.
    Regards

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type

    mit = class(TThread)
    private
    i: Byte;
    protected
    procedure execute; override;
    procedure dosomething;
    procedure DoVisual;
    public
    constructor Create;
    end;

    TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    private
    MyThread: mit;
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    { mit }

    constructor mit.Create;
    begin
    inherited Create(False);
    end;

    procedure mit.DoVisual;
    begin
    Form1.label1.Caption := IntToStr(i);
    end;

    procedure mit.execute;
    begin
    dosomething;
    end;

    procedure mit.dosomething;
    var
    j: Byte;
    begin
    repeat
    for j := 1 to 50 do
    begin
    i := j;
    Synchronize(dovisual);
    if Terminated then
    begin
    i:=0;
    synchronize(dovisual);
    Exit;
    end;
    sleep(500);
    end;
    until True;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    MyThread := mit.Create;
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    Mythread.Terminate;
    end;

    procedure TForm1.Button3Click(Sender: TObject);
    begin
    Mythread.Suspend;
    end;

    procedure TForm1.Button4Click(Sender: TObject);
    begin
    Mythread.Resume;
    end;

  3. #3
    Join Date
    Jan 2004
    Location
    China GuangZhou
    Posts
    2

    Talking thank you

    thanks for your help

  4. #4
    Join Date
    Jan 2004
    Posts
    31
    See also the thread demo in your delphi demos directory

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •