View Full Version : Forward Question
DeSnob
06-11-2010, 11:58 AM
I've seen things like Procedure TickleMyPickle; Forward; What is the forward used for?
nielsie95
06-11-2010, 12:09 PM
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
06-11-2010, 12:11 PM
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
06-11-2010, 12:14 PM
Thanks! I just found out that'll be extremely useful in my script! :)
Dgby714
06-11-2010, 12:21 PM
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
06-11-2010, 12:26 PM
Its good practice not to use it =) most of the time you can just rearrange procedures
Whats the downside of using it?
nielsie95
06-11-2010, 12:30 PM
Increase of compiling time and it can be annoying to maintain both of the declarations, but it's not that bad to use it :)
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.