ShowerThoughts
2010-02-04 05:32:07
Yeah, shame on me, but I need the simple wait function from Scar in Delphi, I know he had some functions on his site, but atm I am not able to find them.
Can someone link me or post it here?
Thank you!
I need this Wait because it does not laggs the mainthread like sleep.
ShowerThoughts
2010-02-04 05:39:30
Is this the same lagg free one?
Craig`
2010-02-04 05:44:41
oh sorry I didn't read your first post fully, I don't have any pascal/delphi knowledge (except for understanding of syntax), I thought that you only wanted a wait function.
apologies, and I don't know if this is "lag free."
~ Craig` :)
marpis
2010-02-04 15:15:17
procedure Wait(Ms: Cardinal);
var
t: Cardinal;
begin
t := GetTickCount + Ms;
while (t > GetTickCount) do
Application.ProcessMessages;
end;
Or you can just call
Sleep()
bullzeye95
2010-02-04 16:16:21
From: marpis
procedure Wait(Ms: Cardinal);
var
t: Cardinal;
begin
t := GetTickCount + Ms;
while (t > GetTickCount) do
Application.ProcessMessages;
end;
You need to put a sleep(1) or something in the loop or it will eat a lot of CPU.
Frement
2010-02-05 09:33:52
From: marpis
Nahh, don't think so
Atleast in C++ that would use alot of CPU. Better to be safe then sorry :)
Wizzup?
2010-02-05 09:58:54
This should give you a general idea. If you are running it on an other thread than the main thread, don't call Application.ProcessMessages();
procedure Wait(t: Integer); extdecl;
var
EndTime : DWord;
begin
EndTime := GetTickCount + t;
while (GetTickCount < EndTime) do
Sleep(16);
Application.ProcessMessages();
end;
end;
nielsie95
2010-02-05 09:59:14
Here's the one I use:
procedure ScriptThread.Wait(Milliseconds: Integer);
var
Tick: DWORD;
Event: THandle;
begin
if Terminated then
Exit;
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWORD(Milliseconds);
while (Milliseconds > 0) and
(MsgWaitForMultipleObjects(1, Event, False, Min(250, Milliseconds),
QS_ALLINPUT) <> WAIT_FAILED) do
begin
Application.ProcessMessages;
Milliseconds := Tick - GetTickCount;
if (Terminated) then
Break;
end;
finally
CloseHandle(Event);
end;
end;
ShowerThoughts
2010-02-10 09:57:27
Everyone, thank you.
Wizzup Interesting, I meant not using Sleep(msecs); because that would block the whole mainthread. Running only Application.ProccesMessages would lagg the shit out of the program?
The actual Wait function code(from SCAR) is in the first post right?
Nielsie what is the exact difference from the one you have and the ones posted before your post? Because the one from the second post, sounds very logic to me that it should work, but somehow it does not do its job.
Anyways, I will try it, we are having a assignment for IT at school(not in delphi). Some friend claimed that something was not possible(a traffic light system) cause you won't be able to click on anything from the GUI when the wait loop is going, I was like almost sure it is possible.
So after a long time of not Delphi coding, I am going to hit Delphi at school in next period.
I hope it's going to be lots of fun and that I can use the things I've learned here. :D
Greetings,
Hermen
marpis
2010-02-10 11:46:52
From: Hermen
Everyone, thank you.
Wizzup Interesting, I meant not using Sleep(msecs); because that would block the whole mainthread. Running only Application.ProccesMessages would lagg the shit out of the program?
The actual Wait function code(from SCAR) is in the first post right?
Nielsie what is the exact difference from the one you have and the ones posted before your post? Because the one from the second post, sounds very logic to me that it should work, but somehow it does not do its job.
Anyways, I will try it, we are having a assignment for IT at school(not in delphi). Some friend claimed that something was not possible(a traffic light system) cause you won't be able to click on anything from the GUI when the wait loop is going, I was like almost sure it is possible.
So after a long time of not Delphi coding, I am going to hit Delphi at school in next period.
I hope it's going to be lots of fun and that I can use the things I've learned here. :D
Greetings,
Hermen
Calling ProcessMessages doesn't lag the shit out of you, at least it didn't when I used Wait like that when I wanted a picture to move slowly on screen when pressing arrow keys. When I wanted it faster I reduced Wait(X) and when I wanted it slower I increased Wait(X)