PDA

View Full Version : Procedure RunWithDelay(timeout: integer;proc:procedure(v:variant))



CynicRus
07-03-2012, 05:36 AM
Procedure RunWithDelay - performs a procedure Proc with delay Timeout( in ms).
Procedure:

Procedure RunWithDelay(timeout: integer;proc:procedure());
var
iStart, iStop: integer;
begin
iStart := GetTickCount;
repeat
iStop := GetTickCount;
until (iStop - iStart) >= timeout;
proc();
end;

How to use:

var v: variant;
procedure Display();
begin
WriteLn(ToStr(v));
end;

begin
v:=1000;
RunWithDelay(10000,@Display)
end.

Le Jingle
07-03-2012, 06:02 AM
Something like this? :s


Var v: variant;
Function Display: Boolean;
Begin
WriteLn(ToStr(v));
Result := True;
End;

Function RunWithDelay(TimeOut: Integer): Boolean;
Var
iStart, iStop: Integer;
Begin
iStart := GetTickCount;
Repeat
iStop := GetTickCount;
Until((iStop - iStart) >= TimeOut);
If ((iStop - iStart) >= TimeOut) Then
Result := Display;
End;

Begin
SetupSRL;
v := 1000;
RunWithDelay(1000);
End.

masterBB
07-03-2012, 07:01 AM
Lol jingle. He posted a piece of code that works. It is a snippet.

Looks good but isn't it the same as:
procedure RunWithDelay(timeout: integer; proc: procedure());
begin
wait(timeout);
proc();
end;

Le Jingle
07-03-2012, 07:13 AM
Doh! >,< didn't know you could have a proc in a proc like that. Plus I didn't compile/search his code; I accuse the progressing night. However, thanks for teaching me something new! :>

CynicRus
07-03-2012, 07:47 AM
Wow-))) I liked the way masterBB-)

masterBB
07-03-2012, 07:52 AM
Wow-))) I liked the way masterBB-)

Well the problem with this code, and the reason it is not part of SRL afaik is that it only saves one line and you loose the ability to add parameters to your procedure.