标签:private obj create classes nil graphic inter form nes
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Unit2; type TMyProc = procedure of object; { TForm1 } TForm1 = class(TForm) CheckBox1: TCheckBox; Frame1_1: TFrame1; Label1: TLabel; procedure FormCreate(Sender: TObject); private procedure DoWork; public procedure Exec; end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure UpdateTime; begin while not Form1.CheckBox1.Checked do begin TThread.Synchronize(nil, @Form1.Exec); TThread.Sleep(500); end; end; procedure TForm1.FormCreate(Sender: TObject); type PThreadMethod = ^TThreadMethod; var Method: TMethod; Proc: TThreadMethod; procedure NestedProc; begin while not Form1.CheckBox1.Checked do begin TThread.Synchronize(nil, @Exec); TThread.Sleep(500); end; end; begin Method.Data := @Self; Method.Code := @NestedProc; //可以 Method.Code := @UpdateTime; //可以 Proc := PThreadMethod(@Method)^; TThread.ExecuteInThread(Proc); end; procedure TForm1.DoWork; begin while not CheckBox1.Checked do begin TThread.Synchronize(nil, @Exec); TThread.Sleep(500); end; end; procedure TForm1.Exec; begin Label1.Caption := DateTimeToStr(Now); end; end.
标签:private obj create classes nil graphic inter form nes
原文地址:https://www.cnblogs.com/Jiaojiawang/p/14332681.html