try...except does hit you with a speed penalty, but only if you make use of the except.
Code:
var
count : integer;
loop : integer;
start : cardinal;
fred : TLabel;
begin
count:=0;
fred:=nil;
start:=getTickCount;
for loop:=1 to 1000000 do
begin
inc(count);
if (fred<>nil) then
fred.caption:='Hello';
end;
memo1.lines.add('No Try : '+intToStr(getTickCount-start));
count:=0;
start:=getTickCount;
for loop:=1 to 1000000 do
begin
try
inc(count);
fred.caption:='Hello';
except
end;
end;
memo1.lines.add('Try : '+intToStr(getTickCount-start));
end;
This code snippet... the first loop executes in between 0-10 ticks, the second takes around the 270-290 tick mark. If all references to fred are removed, then they execute in the same time.
My quick test was compiled with Delphi 5 and was done on an Athlon 800.
Bookmarks