•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 429,898 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,351 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 1856 | Replies: 8
![]() |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
hi everybody,
i'm going to set the procedure for OnTimer event runtime but i don't know how...
i've written the following (WRONG) program, can someone help me?
var
Timer1: TTimer;
procedure PROC(Sender: TObject);
begin .. end;
begin
Timer1.Create(Timer1) ;
Timer1.Interval := 2000;
Timer1.OnTimer := PROC;
end;
i'm going to set the procedure for OnTimer event runtime but i don't know how...
i've written the following (WRONG) program, can someone help me?
var
Timer1: TTimer;
procedure PROC(Sender: TObject);
begin .. end;
begin
Timer1.Create(Timer1) ;
Timer1.Interval := 2000;
Timer1.OnTimer := PROC;
end;
•
•
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 71
Reputation:
Rep Power: 3
Solved Threads: 4
•
•
•
•
i'm going to set the procedure for OnTimer event runtime but i don't know how...
i've written the following (WRONG) program, can someone help me?
see, from the help:
delphi Syntax (Toggle Plain Text)
type TNotifyEvent = procedure (Sender: TObject) of object;
delphi Syntax (Toggle Plain Text)
... type TMainForm = class(TForm) ... public procedure OnTimeEvent(Sender :TObject); end; var MainForm :TMainForm; implementation ... procedure TMainForm.OnTimeEvent(Sender :TObject); begin ... // your code here end; ...
delphi Syntax (Toggle Plain Text)
var Timer1: TTimer; begin Timer1.Create(nil); Timer1.Interval := 2000; Timer1.OnTimer := MainForm.OnTimerEvent; end;
Bye
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)
Brazil - Blumenau
Brazil - Blumenau
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Maybe i've found the solution to my problem using API function SetTimer with TimerProc CALLBACK but i do not know how i can use it...i need an example to follow...
UINT SetTimer(
HWND hWnd, // handle of window for timer messages
UINT nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc // address of timer procedure
);
VOID CALLBACK TimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
);
to execute every 2000 msec my procedure TMyTimer.TimerEvent(Sender:TObject)
i'm trying to use this statement:
SetTimer(0, 0, 2000, addr(Timer1.TimerEvent(Timer1)));
but i get this error:
VARIABLE REQUIRED
???!?!?!?
where? when? why?
AAAAAHHHHHHHHHHHHHHHH
help me please!!!!
UINT SetTimer(
HWND hWnd, // handle of window for timer messages
UINT nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc // address of timer procedure
);
VOID CALLBACK TimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
);
to execute every 2000 msec my procedure TMyTimer.TimerEvent(Sender:TObject)
i'm trying to use this statement:
SetTimer(0, 0, 2000, addr(Timer1.TimerEvent(Timer1)));
but i get this error:
VARIABLE REQUIRED
???!?!?!?
where? when? why?
AAAAAHHHHHHHHHHHHHHHH
help me please!!!!
•
•
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 71
Reputation:
Rep Power: 3
Solved Threads: 4
•
•
•
•
however, for this project, i've not any form, i do use only program source code
mfran2002, You can use SetTimer API function to do this and pass 0 (null) to function in hwnd param.
But is necessary that You use the GetMessage and DispatchMessage API's functions in order to keep message windows system unchanged.
You can test this sample:
delphi Syntax (Toggle Plain Text)
program AppTimer; {$APPTYPE CONSOLE} uses Dialogs, Windows, WinTypes; var Counter :Integer; // callback function for Timer procedure TimerProc(wnd :HWND; // handle of window for timer messages uMsg :UINT; // WM_TIMER message idEvent :UINT; // timer identifier dwTime :DWORD // current system time ); stdcall; // use stdcall when declare callback functions begin Inc(Counter); WriteLn('OnTimer passed...', Counter); end; var Number :Integer; TimeHandle :UINT; Msg :TMSG; begin Counter := 0; TimeHandle := SetTimer(0, 0, 1000, @TimerProc); if TimeHandle > 0 then try while (Counter < 10) do begin GetMessage(Msg, 0, 0, 0); DispatchMessage(Msg); // uncomment this code portion and see the result // Write('Input some number: '); Readln(Number); end; finally KillTimer(0, TimeHandle); end; end.
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)
Brazil - Blumenau
Brazil - Blumenau
•
•
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 71
Reputation:
Rep Power: 3
Solved Threads: 4
•
•
•
•
the last question: is it possible to launch console application like an icon on taskbar? or iconized?
Put a icon in systray will exige a window handle to interaction with your application (I think). Is possoble create a invisible window to do this but I haven't a sample to you. Search for AllocateHWnd and Shell_NotifyIcon.
Bye
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)
Brazil - Blumenau
Brazil - Blumenau
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: dijkstra algorithm
- Next Thread: Problems with code


)
Linear Mode