TroisVerites Posted March 10, 2012 Share Posted March 10, 2012 (edited) [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 March 10, 2012 by TroisVerites Quote Link to comment Share on other sites More sharing options...
FHannes Posted March 10, 2012 Share Posted March 10, 2012 In WaitTrue "func" is defined as "function", you're trying to pass "TestFunc" which is defined as "function: Boolean", the parameter and the function you pass have to be the same type. Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted March 10, 2012 Author Share Posted March 10, 2012 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. Quote Link to comment Share on other sites More sharing options...
FHannes Posted March 10, 2012 Share Posted March 10, 2012 [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] Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted March 10, 2012 Author Share Posted March 10, 2012 (edited) 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 March 10, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...