Bueno, aqui te dejo un ejemplo muy simple de como usar un thread.
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
TMiThread = class(TThread)
protected
procedure Execute; override;
public
constructor Create;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MiThread: TMiThread;
begin
MiThread:= TMiThread.Create;
ShowMessage('Pulsa aceptar para terminar');
Mithread.Terminate;
end;
constructor TMiThread.Create;
begin
inherited Create(FALSE);
FreeOnTerminate:= TRUE;
end;
procedure TMiThread.Execute;
begin
repeat
Windows.Beep(500,100);
Sleep(1000);
until Terminated;
end;
end.
En el ejemplo anterior, hacemos sonar un pitido a intervalos de un segundo. Como ves, el bucle se tiene que insertar en el método "Execute" del TThread.