Thread View: borland.public.delphi
1 messages
1 total messages
Started by akalb
Thu, 03 Dec 2009 11:12
thread exceptions
Author: akalb
Date: Thu, 03 Dec 2009 11:12
Date: Thu, 03 Dec 2009 11:12
100 lines
3688 bytes
3688 bytes
How can I using the event OnException on a Thread ?
Here is is my code in a thread and in a form I create the thread and
next I assign it this code but the code in the procedure
myOnException does not work.
{ 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;
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads