線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2230
推到 Plurk!
推到 Facebook!

GetSystemTime

答題得分者是:st33chen
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-01-21 07:18:05 IP:222.70.xxx.xxx 訂閱
我做个了提醒程序,但是有些问题,我想设置每当系统时间等于DateTimePicker1.Time的时间时,则弹出相应的对话框,但是我用DateToStr(DateTimePicker1.Time)=GetSystemTime(st),好像总是不行,有哪位高手帮我看看吗?
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-01-21 08:26:52 IP:122.116.xxx.xxx 未訂閱
您好,

GetSystemTime API 函數的 宣告如下 :
VOID GetSystemTime(LPSYSTEMTIME lpst)
是 VOID 型, 也就是沒有直接回傳值, 他是由 LPSYSTEMTIME 型的 lpst 指標回傳的

要取用的話是您例中的 st.year, st.hour, ... 等等

何不用 delphi 內建的 now ?
if formatdatetime('hhnnss', datetimepicker1.time)=formatdatetime('hhnnss', now)
我想, 沒有用 formatdatetime 轉一下, 兩個時間(因為精確度的關係)要相等可能有點難.
參考一下


------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-01-21 09:50:18 IP:218.80.xxx.xxx 訂閱
没有用啊,大大,还是不起作用,帮我看看,下面的代码是否有问题啊?

[code delphi]
procedure TForm1.RadioButton2Click(Sender: TObject);
var t:TdateTime;
begin
if radiobutton2.Checked then
datetimepicker1.Enabled :=true;
t:=datetimepicker1.Time ;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin
timer3.enabled:=true;
if formatdatetime('hhnn', t)=formatdatetime('hhnn', now) then
text1:=labelededit2.Text ;
text2:=labelededit3.Text ;
cooltrayicon1.ShowBalloonHint(text1,text2,bitinfo,10);

[/code]
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
編輯記錄
zhouying82 重新編輯於 2009-01-21 09:51:08, 註解 無‧
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-01-21 10:31:14 IP:122.116.xxx.xxx 未訂閱
您提供的程式不是很完整, 不能了解您要做什麼, 我嘗試猜一下您的問題所在, 請注意以下紅色部份(<-- 部份, 他沒變紅色)
===================引 用 zhouying82 文 章===================
没有用啊,大大,还是不起作用,帮我看看,下面的代码是否有问题啊?

[code delphi]
procedure TForm1.RadioButton2Click(Sender: TObject);
var t:TdateTime;
begin
if radiobutton2.Checked then <-- 有何用途, 且 then 若沒有 begin ... end 包起來, 只做其後一列.
datetimepicker1.Enabled :=true; <-- 是否是 timer3.enabled := true;
t:=datetimepicker1.Time ;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin
timer3.enabled:=true; <-- 有何用途, 觸動以後再開? 如果原本 enabled 為 false, 永遠不會執行這一段.
<-- 是否是 timer3.enabled := false;
if formatdatetime('hhnn', t)=formatdatetime('hhnn', now) then <-- then 若沒有 begin ... end 包起來, 只做其後一列.
text1:=labelededit2.Text ;
text2:=labelededit3.Text ;
cooltrayicon1.ShowBalloonHint(text1,text2,bitinfo,10);
<-- 是否加 timer3.enabled := true;

[/code]
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
編輯記錄
st33chen 重新編輯於 2009-01-21 10:32:31, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-01-21 12:14:28 IP:218.80.xxx.xxx 訂閱
老大,好像还是不行吗?我重新设置了代码,您帮我看看呢?谢谢了。

[code delphi]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
DateTimePicker1: TDateTimePicker;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if formatdatetime('hhmmss',datetimepicker1.time)=formatdatetime('hhmmss', now) then
showmessage('hello,world');
end;
end.

[/code]
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#6 引用回覆 回覆 發表時間:2009-01-21 12:44:09 IP:122.116.xxx.xxx 未訂閱
您好,

我這麼測, 可行, 參考一下
new project, 拉 label1, label2, timer1, datetimepicker1, button1

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
DateTimePicker1: TDateTimePicker;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
datetimepicker1.DateTime := now 1/24/60; // 一分鐘(就是 1/24/60)後 showmessage
timer1.Enabled := true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
LABEL1.Caption := FORMATDATETIME('HHNNSS', DATETIMEPICKER1.TIME);
LABEL2.Caption := FORMATDATETIME('HHNNSS', NOW);
if label1.Caption = label2.caption then begin
timer1.enabled := false;
showmessage('time up');
end;
end;
end.
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
編輯記錄
st33chen 重新編輯於 2009-01-21 12:46:48, 註解 無‧
st33chen 重新編輯於 2009-01-21 16:21:33, 註解 無‧
st33chen 重新編輯於 2009-01-23 10:04:54, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#7 引用回覆 回覆 發表時間:2009-01-21 13:29:40 IP:218.80.xxx.xxx 訂閱
上面的1/24/60,这个是什么意思啊?
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
jrsty
一般會員


發表:1
回覆:11
積分:7
註冊:2008-10-31

發送簡訊給我
#8 引用回覆 回覆 發表時間:2009-01-23 08:54:48 IP:60.249.xxx.xxx 訂閱
個人小見解...

推st33chen大大用法~~~~

下面人個人寫法@@

[code delphi]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Timer1: TTimer;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TimeStr: string; //用來存showmessage的時間
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if(TimeStr=formatdatetime('hhmm',now()))then showmessage('hello.world');
//判斷時間=現在時日則showmessage 格式為hhmm
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TimeStr:=edit1.Text; //設定要顯示之時間 格式為 hhmm
timer1.Interval:=10000;
timer1.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled:=false;
end;
end.
[/code]


小弟不才 初學程式.......

如果要判斷到秒~~ 那就把timer時間改短~~

再把hhmm改為hhmmss 應該就可以~~~~ (應該吧@@)
chenyk
高階會員


發表:14
回覆:95
積分:171
註冊:2002-07-08

發送簡訊給我
#9 引用回覆 回覆 發表時間:2009-01-23 20:10:53 IP:123.195.xxx.xxx 訂閱
now()函數 輸出的數值是以天為單位,所以如果要延遲一分鐘
要先把 轉成以天為單位:
1分鐘 = 1/(24小時 * 60分鐘) = 1/24/60 天
編輯記錄
chenyk 重新編輯於 2009-01-23 20:12:02, 註解 無‧
chenyk 重新編輯於 2009-01-23 20:15:12, 註解 無‧
系統時間:2024-05-16 8:04:44
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!