Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a function

Status
Not open for further replies.

Froskoy

Programmer
Jul 25, 2009
18
GB
Hi,

I've got a local variable A contained within a procedure.

I've got a function A which I want the value of to be assigned to the local variable A:

Code:
function A (b:Integer) : Integer;
begin
  blah
end;
Code:
procedure ThisProcedure;
var A,b : Integer;
begin
  blah 
  A:=A(b);
end;

Obviously the compiler does not like this, but it is pretty essential for understanding of the code that the local variable and the function have the same name. How do I go about doing this? Many thanks.
 
Rename the variable to varA or the function to funA.
They can not have the same name, only in case-sensitive languages you could choose the lowercase and uppercase variants for the 'same' thing, so the variable could be 'a' and the function 'A'.

You could switch to C# as that caters very nicely for getters and setters on class members.
 
You can do this, but you must prefix the function name with the unit name. eg;

Code:
A := Unit1.A(B);
 
Many ways:

(1) Prefix the function name with the enclosing unit name:

A := ThisUnit.A(foo);




(2) Declare a function type variable:

type
ft = function (b:Integer) : Integer;
var
AAA: ft;

procedure ThisProcedure;
var A,b : Integer;
begin
blah
A := AAA(foo);
end;

initialization
AAA := @A;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top