SRL Archive - Help

Forward Question


DeSnob

2010-06-11 07:58:13

I've seen things like
Procedure TickleMyPickle; Forward; 
What is the forward used for?

nielsie95

2010-06-11 08:09:10

It means that the function is declared somewhere further down the script. Normally you can only use functions that are above the current function, but sometimes you need one that's below it.


program New;

procedure test;
begin
test2;
end;

procedure test2;
begin
WriteLn('hoi');
end;

begin
test;
end.

Doesn't work, because test2 is beneath test.


program New;

procedure test2; forward;

procedure test;
begin
test2;
end;

procedure test2;
begin
WriteLn('hoi');
end;

begin
test;
end.

works :)

Dgby714

2010-06-11 08:11:04

Example…
porgram ForwardExample;

function Num3: string; forward;

procedure Num1;
begin
WriteLn(Num3);
end;

function Num2: string;
begin
Result := 'Boo!...';
end;

function Num3: string;
begin
Result := Num2;
end;

DeSnob

2010-06-11 08:14:22

Thanks! I just found out that'll be extremely useful in my script! :)

Dgby714

2010-06-11 08:21:09

From: DeSnob
Thanks! I just found out that'll be extremely useful in my script! :)

Its good practice not to use it =) most of the time you can just rearrange procedures

Frement

2010-06-11 08:26:54

From: Dgby714
Its good practice not to use it =) most of the time you can just rearrange procedures


Whats the downside of using it?

nielsie95

2010-06-11 08:30:55

Increase of compiling time and it can be annoying to maintain both of the declarations, but it's not that bad to use it :)