{ Public declarations }
procedure myOnException(Sender:TObject);
procedure TMainForm.Button1Click(Sender: TObject);
begin
//creo il thread
ThreadDataCheck := TthrDataCheck.CreateIt;
ThreadDataCheck.OnException:=myOnException;
end;
procedure TMainForm.myOnException(Sender: TObject);
begin
Panel5.Caption:=ThreadDataCheck.LastException;
end;
---------------------------------------------------------------
type
TthrDataCheck = class(TThread)
private
{ Private declarations }
FOnException: TNotifyEvent;
FException: Exception;
procedure DoHandleException;
protected
{ protected declarations }
procedure Execute; override;
procedure HandleException; virtual;
public
{ public declarations }
LastException:string;
published
{ published declarations }
constructor CreateIt;
property OnException:TNotifyEvent read FOnException write
FOnException;
end;
procedure TthrDataCheck.DoHandleException;
begin
// Cancel the mouse capture
if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0,
0);
// gestisco la visualizzazione dell' exception
if FException is Exception then
Application.ShowException(FException)
else
SysUtils.ShowException(FException, nil);
LastException:= FException.Message;
if Assigned(Self.FOnException)then
Self.FOnException(Self);
end;
end;
procedure TthrDataCheck.HandleException;
begin
FException := Exception(ExceptObject);
try
// non visualizzo il messaggio "EAbort"
if not (FException is EAbort) then
Synchronize(DoHandleException);
finally
FException := nil;
end;
end;
constructor TthrDataCheck.CreateIt;
begin
inherited Create (True); // Create thread suspended
FreeOnTerminate := True;
Priority := tpNormal;
FException := nil;
try
Application.MainForm.Caption:=FloatToStr(StrToFloat
(Application.MainForm.Caption) / 2);
except on E: Exception do
begin
LastException:='prova 1 - ';
HandleException;
end;
end;
Suspended := False;
end;