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

關於行事曆提醒一問

 
bill lin
一般會員


發表:1
回覆:2
積分:0
註冊:2002-04-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-06-20 23:54:40 IP:61.30.xxx.xxx 未訂閱
請各位前輩指教: 我想要一個類似行事曆提醒ㄉ功能,StringGrid其中一欄為提醒時間, 假設有3筆提醒時間分別為PM 01:20:00,PM 01:40:00,PM 02:30:00請問這 樣ㄉ程式要如何寫???
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-06-21 08:07:41 IP:211.22.xxx.xxx 未訂閱
小弟的想法, 用 Timer, Interval 設 1 秒:
procedure TForm1.Timer1Timer(Sender: TObject);
var hh, nn, ss, ms: DWORD;
begin
  DecodeTime(Now, hh, nn, ss, ms);
  if (hh = 13) and (nn = 20) and (ss = 0) then
    ShowMessage('PM 01:20:20');
  if (hh = 13) and (nn = 40) and (ss = 0) then
    ShowMessage('PM 01:40:20');
  if (hh = 14) and (nn = 20) and (ss = 0) then
    ShowMessage('PM 02:30:20');
end; 
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-06-21 08:14:30 IP:192.168.xxx.xxx 未訂閱
引言: 小弟的想法, 用 Timer, Interval 設 1 秒:
procedure TForm1.Timer1Timer(Sender: TObject);
var hh, nn, ss, ms: DWORD;
begin
  DecodeTime(Now, hh, nn, ss, ms);
  if (hh = 13) and (nn = 20) and (ss = 0) then
    ShowMessage('PM 01:20:20');
  if (hh = 13) and (nn = 40) and (ss = 0) then
    ShowMessage('PM 01:40:20');
  if (hh = 14) and (nn = 20) and (ss = 0) then
    ShowMessage('PM 02:30:20');
end; 
這樣做可能會有Lose的機會,應該用 >= 再加上已顯示的旗標判斷 否則Timer並不一定保證該秒鐘一定會執行喔! ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
bill lin
一般會員


發表:1
回覆:2
積分:0
註冊:2002-04-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-06-21 13:08:36 IP:61.30.xxx.xxx 未訂閱
感謝hagar兄及站長大人,小弟寫了一個Demo可是卻有問題,能否請各位前輩幫忙指點. Thanks. unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, ExtCtrls; type TForm1 = class(TForm) StrGrd: TStringGrid; Edit1: TEdit; Label1: TLabel; Label2: TLabel; Edit2: TEdit; Button1: TButton; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; Y : integer; implementation {$R *.DFM} Procedure CheckState; var NowTime,WarningTime : TTime; i : Integer; Begin for i := 1 to 4 do //假設StringGrid只有4筆資料 begin if Form1.StrGrd.Cells[2,i] = '1' then //狀態 0 : 已提醒, 1 : 未提醒 begin NowTime := Now; WarningTime := StrToTime(Form1.StrGrd.Cells[0,i]); if NowTime >= WarningTime Then ShowMessage (Form1.StrGrd.Cells[1,i]); Form1.StrGrd.Cells[2,i] := '0' //狀態 0 : 已提醒, 1 : 未提醒 end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin Y :=1; StrGrd.Cells[0,0] := '提醒時間'; StrGrd.Cells[1,0] := '提醒訊息'; StrGrd.Cells[2,0] := '狀態'; // 0 : 已提醒, 1 : 未提醒 end; procedure TForm1.Button1Click(Sender: TObject); begin StrGrd.Cells[0,Y] := Edit1.Text; //取得提醒時間 StrGrd.Cells[1,Y] := Edit2.Text; //取得提醒訊息 StrGrd.Cells[2,Y] := '1'; //感謝站長建議,我多加了這一個欄位 Y := Y 加 1; //為什麼預視的時候加號顯示出不來ㄋㄟ... 只好用國字代替 Edit1.Text := ''; Edit2.Text := ''; end; procedure TForm1.Timer1Timer(Sender: TObject); begin CheckState; end; end. 問題如下: 1. Timer, Interval 設 1 秒:只要新增第一筆資料,就馬上秀出新增ㄉ提醒訊息,可是提醒時間上未到ㄚ???是我的Procedure CheckState邏輯上有問題嗎? 2. 時間的比對一定要像hagar兄那樣把它切的這麼細嗎?可否用像以下方式: NowTime := PM 12:01:00 WarningTime ;= PM 12:00:00 if NowTime > WarningTime then ..... 對不起,因為我不知道系統在作時間比對是用什麼方式. 3.如果StringGrid在新增一筆資料時,因資料列已滿,有方法可以判斷出來後再動態產生一列嗎?(如何判斷,如何新增)
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-06-21 14:12:50 IP:211.22.xxx.xxx 未訂閱
1.Debug 以下這段程式, 會 ShowMessage 的原因是   if NowTime >= WarningTime 這個判斷式成立   檢查 NowTime 跟 WarningTime 的值就知道了
for i := 1 to 4 do 
begin
  if Form1.StrGrd.Cells[2,i] = '1' then //狀態 0 : 已提醒, 1 : 未提醒
  begin
    NowTime := Now;
    WarningTime := StrToTime(Form1.StrGrd.Cells[0,i]);
    if NowTime >= WarningTime Then
      ShowMessage (Form1.StrGrd.Cells[1,i]);
    Form1.StrGrd.Cells[2,i] := '0' //狀態 0 : 已提醒, 1 : 未提醒
  end;
end;
2.日期時間在 Delphi 來說是個浮點數 其中整數部份為日, 小數部份為時/分/秒/毫秒 3.判斷 TStringGrid.Cells[TStringGrid.ColCount-1, i] 是否有值 至於新增的話, 就直接改變 TStringGrid 的 RowCount 就好了 例: TStringGrid.RowCount := TStringGrid.RowCount 1;
ccchen
版主


發表:61
回覆:940
積分:1394
註冊:2002-04-15

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-06-21 14:52:19 IP:163.29.xxx.xxx 未訂閱
稍微修改一下你的程式
procedure TForm1.Button1Click(Sender: TObject);
begin
  StrGrd.Cells[0,Y] := Edit1.Text; //取得提醒時間
  StrGrd.Cells[1,Y] := Edit2.Text; //取得提醒訊息
  StrGrd.Cells[2,Y] := '1'; //感謝站長建議,我多加了這一個欄位
  Y := Y   1; //為什麼預視的時候加號顯示出不來ㄋㄟ... 只好用國字代替

  if strGrd.RowCount < y then
    strGrd.RowCount:=y;      Edit1.Text := '';
  Edit2.Text := '';
end;    Procedure TForm1.CheckState;
var
  NowTime,WarningTime : TTime;
  i : Integer;
Begin
  for i:=1 to strgrd.rowcount 1 do//假設StringGrid只有4筆資料
  begin
    if Form1.StrGrd.Cells[2,i] = '1' then //狀態 0 : 已提醒, 1 : 未提醒
    begin          NowTime := now - Trunc(Now);          WarningTime := StrToTime(Form1.StrGrd.Cells[0,i]);          if NowTime >= WarningTime Then begin
        Form1.StrGrd.Cells[2,i] := '0'; //狀態 0 : 已提醒, 1 : 未提醒
        ShowMessage (Form1.StrGrd.Cells[1,i] '  ' TimeTostr(nowtime) '  ' TimeTostr(WarningTime));
      end;        end;
  end;
end;    procedure TForm1.FormCreate(Sender: TObject);
begin
  Y :=1;
  StrGrd.Cells[0,0] := '提醒時間';
  StrGrd.Cells[1,0] := '提醒訊息';
  StrGrd.Cells[2,0] := '狀態'; // 0 : 已提醒, 1 : 未提醒
end;    procedure TForm1.Timer1Timer(Sender: TObject);
begin
  CheckState;
end;
1. TTime, TDateTime實際上之DataType均為Double, 小數點前代表日其,小數部分代表時間, 故if NowTime > WarningTime then 為最有效率之比較方式 2. now取得之值, 為日期含時間, Trunc(now)使其只剩整數部分, now-Trunc(now)則為小數部分. 3. StringGrid之rowcount可增加如上 4. 其實可用TClientDataSet及DBGrid
bill lin
一般會員


發表:1
回覆:2
積分:0
註冊:2002-04-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-06-21 18:19:10 IP:61.30.xxx.xxx 未訂閱
非常感謝hagar及ccchen兩位前輩熱心指導,感恩不盡...< >< >
系統時間:2024-04-25 12:50:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!