使用多线程实现打字效果

使用多线程实现打字效果
 
 
使用多线程实现打字效果

使用多线程实现打字效果


unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    Button2: TButton;
     procedure Button1Click(Sender: TObject);
     procedure Button2Click(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }   procedure DisplaySlowText ();
   end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  TThread.CreateAnonymousThread(DisplaySlowText).Start; //!!!

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  TThread.CreateAnonymousThread(DisplaySlowText).Terminate;     //无效
end;

procedure TForm1.DisplaySlowText();
var
   i : Integer;
   S : String;
begin
    s :=Memo2.Text;
     for i := 1 to Length(S) do
      begin
         Memo1.SelStart :=Length(Memo1.Text);
         Memo1.SetSelText(s[i]);
         Sleep ( 50);
      end;
      Memo1.SetFocus;
end;



end.




你可能感兴趣的:(多线程)