Log in

View Full Version : Saving function argument of type function : boolean



slushpuppy
12-08-2012, 04:05 PM
why does this throw a mismatch error? http://pastebin.com/My4Cxw87
line 17

Brandon
12-08-2012, 04:26 PM
Calling function walkuntil is missing brackets.. Also the Record should be holding a boolean which is the return value of the function. I'm not too sure why you want to pass the function as a parameter rather than calling the global function directly. But oh well.. Up to you. The fix is below just in case you still want to call it via parameter.


type
RW_CheckPoint = Record
till: Boolean;
color,tolerance : Integer;
end;

function RW_noop : Boolean;
begin
Result := false;
end;


function RW_Point(c,t : Integer; WalkUntil : function : Boolean) : RW_CheckPoint;
begin
with Result do
begin
color := c;
t := tolerance;
till := WalkUntil();
end;
end;

slushpuppy
12-09-2012, 03:31 AM
Actual fix:

type
RW_TBoolFunc = function : Boolean;
RW_TPoint = Record
dir : extended;
till : RW_TBoolFunc;
color,tolerance : Integer;
end;
var
RW_Accuracy : Integer;

function RW_noop : Boolean;
begin
Result := false;
end;
procedure RW_setAccuracy(lvl : Integer);
begin
RW_Accuracy := lvl;
end;
procedure RW_setup;
begin
RW_setAccuracy(5);
end;
function RW_Point(direction : char;c,t : Integer; WalkUntil : RW_TBoolFunc) : RW_TPoint;
begin
with Result do
begin
color := c;
t := tolerance;
till := WalkUntil;
dir := variantToDirection(direction);
end;

end;



You will need to create a 'typedef' for function type. Thanks dgby :D

Brandon
12-09-2012, 03:42 AM
Looks no different from what I previously said :S. Only difference is you declared it as a type instead of passing it directly as a parameter. You don't "NEED" to create any typedef for the function.

Its the same as the answers I posted previously and on this thread: http://villavu.com/forum/showthread.php?t=93566