Functions, compile and check the dependencies

Hi All,

I have the following script as source file and load with loadfromfile into the Scripter:

function AMD(Par: String): Variant;
begin
ShowMessage(UltimoDiaMes(3,4));
end;

// here there are others functions in the same script file, like the following:

function UltimoDiaMes(P1,P2: Variant): Variant;
begin
Result := P1 + P2;
end;

So, when I to compile the Scripter, it's show me the next error:

image

is possible do not check the dependencies ?

Thanks in advance,

Adrián

@adrian the problem you are having is that. In Pascal, in order for a procedure/function to call another procedure/function that is in the same unit file. It has to know about the procedure/function before it can call the procedure/function.

There is two ways to do this in Pascal:

  1. Place the procedure/function that is being called by a procedure/function. Someplace prior to the procedure/function that is calling that procedure/function.
function UltimoDiaMes(P1,P2: Variant): Variant;
begin
    Result := P1 + P2;
end;

// here there are others functions in the same script file, like the following:

function AMD(Par: String): Variant;
begin
    ShowMessage(UltimoDiaMes(3,4));
end;
  1. Defining a forward for the procedure/function.
function AMD(Par: String): Variant; forward;
function UltimoDiaMes(P1,P2: Variant): Variant; forward;

function AMD(Par: String): Variant;
begin
    ShowMessage(UltimoDiaMes(3,4));
end;

// here there are others functions in the same script file, like the following:

function UltimoDiaMes(P1,P2: Variant): Variant;
begin
    Result := P1 + P2;
end;

Which of the two ways to use is up to you. But, understand that there will come a time when you will create a procedure/function that is calling a procedure/function. And it is also being called by another procedure/function. Or you will create a procedure/function that will use two, or more, procedures/functions. In either case you will find that you are unable to place of this procedure/function so that it can see the other procedures/function. And/Or it can not be seen by other procedures/function that might being calling it.

It is with this in mind that I would recommend that you would use the second way. As this will ensure that all procedures/functions have a forward defined for them prior to any other procedure/function that may call them. Thus allowing any procedure/function to call another procedure/function. No matter where in the unit file the calling procedure/function is in relation to the procedure/function it is calling.

1 Like

Thank you so much Michael !

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.