UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;typeTForm1=class(tform) Button1:tbutton; Edit1:tedit; Edit2:tedit; procedureButton1Click (Sender:tobject); Private {Private Declarations} Public {Public Declarations} End;type //Thread ClassTmythread =class(TThread)PrivatePNum1, Pnum2:integer; Myedit:tedit; protected procedureExecute;Override; Public Constructorctreate (Num1, Num2:integer; edit:tedit); End;varForm1:tform1;Implementation{$R *.DFM}Constructor Tmythread. Ctreate (Num1, Num2:integer; edit:tedit);beginPNUM1:=Num1; PNUM2:=Num2; Myedit:=edit; Freeonterminate:=True; inherited Create(False);End;procedureTmythread.execute;varI, K:integer;begin //where the thread executes, you can change it to your own computational process or function .K: =0; forI: =0 to 10000000 DoK:= k + PNum1 * i + PNum2 *i; Myedit.text:=IntToStr (k);End;procedureTform1.button1click (sender:tobject);varMycalc:tcalc;beginMycalc:= Tcalc.ctreate (1,1, edit1); Mycalc:= Tcalc.ctreate (1,1, edit2);End;End.
Delphi Simple Threading Example