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;
你可以编译前执行一个批处理把时间输出到一个文本中.
在你的Delphi源代码中要用到时间的地方用{$I 文件名}即可把你的文件内容插入到该处,
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;
现在使用的还是delphi7,看来我也得使用新版本的delphi了,不知道D7的程序升级到高版本的Delphi麻风不!
这是因为最终用户可能并不懂从快捷方式如何找到exe的操作,不懂右击之类的操作,
在诸如 关于 帮助之类的窗口中显示编译时间是个好办法
另外,查看文件属性的时间是不准确的,随时随地可能被修改.例如,你从这里拷贝到那里,那里的创建时间就变了.
thanks,
拷贝文件只能影响它的创建时间,他的修改时间不会变的。
const
csapp='xxxx';
csver='00.0098';
csbuild='11092801';