Registriert seit: 6. Apr 2005
10.109 Beiträge
|
Re: Anwendung wird durch Herunterfahren abgewürgt...
17. Apr 2008, 20:48
Hallo Daniel,
warum arbeitest du nicht mit den VCL-Ereignissen?
Delphi-Quellcode:
unit CustThread;
interface
uses
Classes;
type
TCustomThread = class(TThread)
private
procedure ShowProgress;
procedure AfterTermination(Sender: TObject);
protected
procedure Execute; override;
public
constructor Create;
end;
implementation
uses
SysUtils,
MainFrm;
constructor TCustomThread.Create;
begin
inherited Create(True);
OnTerminate := AfterTermination;
end;
procedure TCustomThread.AfterTermination(Sender: TObject);
begin
Sleep(5000);
end;
procedure TCustomThread.ShowProgress;
begin
MainForm.Panel.Caption := TimeToStr(Now);
end;
procedure TCustomThread.Execute;
begin
while not Terminated do
Synchronize(ShowProgress);
end;
end.
Und hier noch das Testbett:
Delphi-Quellcode:
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, CustThread;
type
TMainForm = class(TForm)
Panel: TPanel;
procedure PanelClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
CustomThread: TCustomThread;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.PanelClick(Sender: TObject);
begin
Panel.OnClick := nil;
CustomThread := TCustomThread.Create;
CustomThread.Resume;
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CustomThread.Terminate;
CustomThread.Free;
CanClose := True;
end;
end.
Grüße vom marabu
|
|
Zitat
|