Jump to content
TroisVerites

Passing a function to a function to a function ...Need Heelp

Recommended Posts

[sCAR]

program New;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function RR(Min, Max: Integer): Integer;

Contributors: Freddy, Wanted.

Description: Outputs a value within a range.

Date Created: September 22nd, 2011. By Wanted

Last Modification: November 3rd, 2011. By Wanted

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

function RR(Min, Max: Integer): Integer;

begin

Result := RandomRange(Min, Max);

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

procedure WaitRR(Min, Max: LongInt);

Contributors: Wanted

Description: Waits/sleeps a random amount of time.

Date Created: August 10th, 2011. By Wanted

Last Modified: August 10th, 2011. By Wanted

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

procedure WaitRR(Min, Max: LongInt);

var

T: LongInt;

begin

T := RR(Min, Max);

if (T > 9999) then

Sleep(T)

else

Wait(T);

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function WaitFunc(Func: function: Boolean; DesiredResult: Boolean; MinWait, MaxWait, MinTotalWait, MaxTotalWait: LongInt): Boolean;

Contributors: Wanted

Description: Repeats a function until DesiredResult.

Date Created: August 10th, 2011. By Wanted

Last Modified: September 26th, 2011. By Wanted

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

function WaitFunc(Func: function: Boolean; DesiredResult: Boolean; MinWait, MaxWait, MinTotalWait, MaxTotalWait: LongInt): Boolean;

var

T: LongInt;

begin

Result := True;

T := GetSystemTime + RR(MinTotalWait, MaxTotalWait);

while (GetSystemTime < T) do

if (Func() = DesiredResult) then

Exit

else

WaitRR(MinWait, MaxWait);

Result := False;

end;

 

 

function WaitTrue(func: function: Boolean; timeout: Integer): Boolean;

begin

Result := WaitFunc(func, True, 500,500,timeout,timeout);

end;

 

function Testfunc(): Boolean;

begin

Result := true;

end;

 

begin

WaitTrue( @Testfunc,60000);

end.

[/sCAR]

 

Compiler error : type mismatch ; Line 57

 

Any Help ?

Edited by TroisVerites
Link to comment
Share on other sites

HI

 

The first parameter of WaitTrue is func: function: Boolean , And I passed a function 'function Testfunc(): Boolean;' , I think it is correct.

 

But The compiler error is at line 57 in the WaitTrue .

 

I do a simple Test with Scar 3.31

 

[sCAR]

 

program New;

 

procedure WaitTrueA(func: function: Boolean);

begin

end;

 

procedure WaitTrueB(func: function: Boolean);

begin

WaitTrueA(func);

end;

 

function Testfunc(): Boolean;

begin

Result := true;

end;

 

begin

WaitTrue(@Testfunc);

end.

[/sCAR]

 

the compiler error is in WaitTrueB , perhaps there is a special way to pass a function to another.

Link to comment
Share on other sites

[scar]program New;

 

type

TBoolFunc = function: Boolean;

 

procedure WaitTrueA(func: TBoolFunc);

begin

end;

 

procedure WaitTrueB(func: TBoolFunc);

begin

WaitTrueA(func);

end;

 

function Testfunc(): Boolean;

begin

Result := true;

end;

 

begin

WaitTrueA(@Testfunc);

end.[/scar]

Link to comment
Share on other sites

HI

 

Enfin , j'ai trouvé une solution. Peut être pas la meilleure.

---

Finally, I found a solution. Maybe not the best.

 

[sCAR]

program New;

 

type

TTrueFunct = function():Boolean;

 

procedure WaitTrueA(func: TTrueFunct);

begin

end;

 

procedure WaitTrueB(func: TTrueFunct);

begin

WaitTrueA(func);

end;

 

function Testfunc(): Boolean;

begin

Result := true;

end;

 

begin

WaitTrueB(@Testfunc);

end.

[/sCAR]

Edited by Freddy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...