Using const allows the compiler to optimize code for structured- and string-type parameters.
It also provides a safeguard against unintentionally passing a parameter by reference to
another routine.
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
lStart,lEnd:integer;
tempStr :string;
begin
Label2.Caption:='';
lStart:=GetTickCount;
for i:=0 to 1000 do
begin
tempStr:=inttostr(i);
TestConst(tempStr);
// TestVar(tempStr);
end;
lEnd:=GetTickCount;
Label1.Caption:=FloatToStr((lEnd-lStart)/1000.0)
end;
procedure TForm1.TestConst(const str: string);
begin
Label2.Caption:=Label2.Caption+str;
end;
procedure TForm1.TestVar(var str: string);
begin
Label2.Caption:=Label2.Caption+str;
end;