Hi Gerben,
EnterMethod/LeaveMethod is correct in this context. What Dennis meant is that TrackMethod always acts like a combination of EnterMethod/LeaveMethod with a try/finally block. Since this might not be the desired behavior in some cases, TrackMethod might not always be applicable. I think this is best explained with an example. Imagine the following code snippet:
procedure TForm1.Button1Click(Sender: TObject);
begin
SiMain.TrackMethod(Self, 'Button1Click');
// ...
end;
The way the TrackMethod method works, you are always using a try/finally block implicitly/automatically. The code snippet above is therefore equivalent to the following lines:
procedure TForm1.Button1Click(Sender: TObject);
begin
SiMain.EnterMethod(Self, 'Button1Click');
try
// ...
finally
SiMain.LeaveMethod(Self, 'Button1Click');
end;
end;
As I mentioned, this might not always be the desired behavior. It is sometimes advisable to use EnterMethod/LeaveMethod without a try/finally block. Imagine an exception in the body of the try/finally block. When you are using EnterMethod/LeaveMethod with a try/finally block, then the code in the finally section is nonetheless called and it can be difficult to find the exact location in the log where the exception occurred. This is not the case if you omit the try/finally block like in the following examples:
procedure TForm1.Button1Click(Sender: TObject);
begin
SiMain.EnterMethod(Self, 'Button1Click');
// ...
SiMain.LeaveMethod(Self, 'Button1Click');
end;
When using EnterMethod/LeaveMethod this way, the call to LeaveMethod will not be executed when an exception occurs between EnterMethod and LeaveMethod. This way it is usually easier to tell in which method the exception occurred.
I hope I could answer your question to your satisfaction.