关于动态获取系统时间和MAINMENU的问题(100分)

  • 主题发起人 主题发起人 kensou
  • 开始时间 开始时间
K

kensou

Unregistered / Unconfirmed
GUEST, unregistred user!
需要两个时钟程序
一个是console程序
我的代码如下program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
aaa,bbb:string;
begin
{ TODO -oUser -cConsole Main : Insert code here }
Present:= Now;
DecodeDate(Present, Year, Month, Day);
aaa := 'DATE is:' + IntToStr(YEAR) + ' nian '
+ IntToStr(Month) + ' yue ' + IntToStr(day)+' ri ';
DecodeTime(Present, Hour, Min, Sec, MSec);
bbb := 'TIME is:' + IntToStr(HOUR) + ':'
+ IntToStr(min)+':'+inttostr(sec);
writeln (' ####################################');
writeln (' # '+aaa+' #');
writeln (' # '+bbb+' #');
writeln (' # press ctrl+C to exit #');
writeln (' ####################################');
readln;
end.
问题很明显 ,不能动态刷新数据,请高手帮忙修改
第二个要求在mainmenu的菜单项目的caption动态显示当前时间和日期
我的代码如下
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
d,t:string;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
mainmenu1.items[2].Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
mainmenu1.items[3].Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
end;
end.
我觉得这么做不对,但又想不到其他办法
调试时会出现list out of bonds 错误
到底该怎样做呢
望各位高手指点迷津

 
有这么复杂么? formatdatetime不就可以,当前时间now
 
1,先清除
2,list out of bonds 错误是指超界错误,如你给mainmenu1.items[3].Caption 赋值,
而mainmenu1.items[3]不存在,这时就出现这个错误。
 
谢谢两位

程序已经通过
 
后退
顶部