+ -
当前位置:首页 → 问答吧 → 在编译生成exe时,如何将系统时间写入程度,供实施人员在界面上查看。

在编译生成exe时,如何将系统时间写入程度,供实施人员在界面上查看。

时间:2011-09-28

来源:互联网

编译exe时,将系统时间写入程序中,编译后,打开exe后,可在界面上查看编译时间。

目前我是使用右击exe文件,查看属性中的修改时间来查看。

作者: seleron   发布时间: 2011-09-28

DateTimeToStr(FileDateToDateTime(FileAge(Application.ExeName)))

作者: sonicer   发布时间: 2011-09-28

程序运行时,读取一下自己的修改时间,显示给人看

作者: sz_haitao   发布时间: 2011-09-28

“右击exe文件,查看属性中的修改时间”跟“DateTimeToStr(FileDateToDateTime(FileAge(Application.ExeName)))”其实是一码事,

写字程序里又能如何?公司竟然要求写在程序了,真牛!

作者: seleron   发布时间: 2011-09-28

别告诉我你用的是Delphi7.最新的几个版本Delphi都有编译事件.可一直指定编译前做什么,编译后做什么.
你可以编译前执行一个批处理把时间输出到一个文本中.
在你的Delphi源代码中要用到时间的地方用{$I 文件名}即可把你的文件内容插入到该处,

作者: wr960204   发布时间: 2011-09-28

Delphi(Pascal) code
procedure TForm1.FormCreate(Sender: TObject);
var
  h: THandle;
  w, l: TFileTime;
  s: TSystemTime;
begin
  h := CreateFile(PChar(ParamStr(0)), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
    nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  if h = INVALID_HANDLE_VALUE then raise Exception.Create('CreateFile Error!');

  try
    if not GetFileTime(h, nil, nil, @w) then raise Exception.Create('GetFileTime Error!');

    if not FileTimeToLocalFileTime(w, l) then raise Exception.Create('FileTimeToLocalFileTime Error!');

    if not FileTimeToSystemTime(l, s) then raise Exception.Create('FileTimeToSystemTime Error!');

    Text := Format('%d-%d-%d %d:%d:%d', [s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond]);
  finally
    CloseHandle(h);
  end;
end;

作者: s11ss   发布时间: 2011-09-28

看一下预编译指令集,好多啊。。。

作者: hongss   发布时间: 2011-09-28