如何設計可自動顯示時間的 Label |
答題得分者是:william
|
bruce0211
版主 發表:157 回覆:668 積分:279 註冊:2002-06-13 發送簡訊給我 |
我找到一些資料關於設計可自動顯示時間的 Label 元件 source
但都是動態建立一個 TTimer 做時間的顯示
而我卻想利用 WinAPI - SetTimer() 來做時間的顯示的驅動器
以下為我的元件程式碼
但在傳入參數 Handle 的部分一直出現錯誤
我猜是因為繼承 TLabel 沒有 Handle 的原因
但如此就無法使用SetTimer() 了嗎 ?
另外,繼承 TLabel 的元件,不需要 destructor TMyTimerLabel.Destroy; 這個解構函式嗎 ? 我看別人的元件範例都沒有,但此例我還是把它加入 ...
unit MyTimerLabel; interface uses SysUtils, Classes, Controls, StdCtrls, Messages, Windows; type TMyTimerLabel = class(TLabel) private { Private declarations } protected { Protected declarations } procedure WMTimer(var Message:TMessage); message WM_TIMER; public { Public declarations } constructor Create(AOwner : TComponent); override; destructor Destroy; override; published { Published declarations } end; procedure Register; implementation constructor TMyTimerLabel.Create(AOwner : TComponent); begin inherited Create(AOwner); SetTimer(Handle,1,1000,nil); end; destructor TMyTimerLabel.Destroy; begin KillTimer(Handle,1); inherited Destroy; end; procedure TMyTimerLabel.WMTimer(var Message:TMessage); var S:string; begin s:=DateTimeToStr(Now); Caption:=s; end; procedure Register; begin RegisterComponents('MyWay', [TMyTimerLabel]); end; end. |
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
unit MyTimerLabel; interface uses SysUtils, Classes, Controls, StdCtrls, Messages, Windows; type TMyTimerLabel = class(TLabel) private { Private declarations } Handle: THandle; protected { Protected declarations } procedure WMTimer(var Message:TMessage); |
bruce0211
版主 發表:157 回覆:668 積分:279 註冊:2002-06-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |