function and procedure |
Top Previous Next |
function and procedure
Declaration of functions and procedures are similar to Object Pascal in Delphi, with the difference you don't specify variable types. Just like OP, to return function values, use implicited declared result variable. Parameters by reference can also be used, with the restriction mentioned: no need to specify variable types.
Examples:
function TodayAsString; begin result:=DateToStr(Date); end;
function Max(A,B); begin if A>B then result:=A else result:=B; end;
procedure HelloWord; begin ShowMessage('Hello world!'); end;
procedure UpcaseMessage(Msg); begin ShowMessage(Uppercase(Msg)); end;
procedure SwapValues(var A, B); var Temp; begin Temp:=A; A:=B; B:=Temp; end;
|