unit view.Server.Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 =
class( TForm )
Button1 : TButton;
procedure Button1Click( Sender : TObject );
procedure FormCloseQuery( Sender : TObject;
var CanClose : Boolean );
private
fThreadDemo : TThread;
fFormCloseRequest : Boolean;
procedure ThreadDestroy( Sender : TObject );
public
end;
var
Form1 : TForm1;
implementation
uses
thread.Demo;
{$R *.dfm}
procedure TForm1.Button1Click( Sender : TObject );
begin
if Assigned( fThreadDemo )
then
Exit;
fThreadDemo := TThreadDemo.Create( True );
with TThreadDemo( fThreadDemo )
do
begin
FreeOnTerminate := True;
OnDestroy := Self.ThreadDestroy;
Start;
end;
end;
procedure TForm1.FormCloseQuery( Sender : TObject;
var CanClose : Boolean );
begin
if Assigned( fThreadDemo )
then
begin
fThreadDemo.Terminate;
if not fFormCloseRequest
then
begin
fFormCloseRequest := True;
with TPanel.Create( Self )
do
begin
Parent := Self;
Left := 0;
Top := 0;
Width := Self.ClientWidth;
Height := Self.ClientHeight;
Caption := '
Wir müssen noch auf den Thread warten!';
end;
end;
CanClose := False;
end;
end;
procedure TForm1.ThreadDestroy( Sender : TObject );
begin
if fThreadDemo = Sender
then
begin
fThreadDemo :=
nil;
if fFormCloseRequest
then
Close;
end;
end;
end.