Wilfried Mestdagh wrote:
> I use TriggerXXX in my objects to Trigger an event. For example:
>
> procedure TSomeObj.TriggerError(E: Exception);
> begin
>   if Assigned(FOnError) then
>     FOnError(Self, E);
> end;

I see. Typically, a method that only executes event handlers has a "Do"
prefix. DoError. See the VCL source code for lots of examples.

> This codes very fast and reliable, also for maintance. Is this not a
> good technique ?

It's fine. I would go a step further and make it optional for the event
handler to swallow the exception.

type
  TOnErrorEvent = procedure(Sender: TObject; Exception: TObject; var
Handled: Bool) of object;

function TSomeObj.DoError(E: TObject): Boolean;
begin
  Result := False;
  if Assigned(OnError) then
    OnError(Self, E, Result);
end;

try
  // ...
except
  on E: TObject do
    if not DoError(E) then raise;
end;

This way, if the component doesn't handle the exception, it will propagate
up the call stack to something else that is prepared to handle it.

-- 
Rob

__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to