50分……请问DELPHI中怎么得到编译的时间,类似于C++中的__DATE__ __TIME__(50分)

A

acjin

Unregistered / Unconfirmed
GUEST, unregistred user!
请问DELPHI中怎么得到编译的时间,类似于C++中的__DATE__ __TIME__
 
怎么都没人回答阿?
 
timetostr(time);
 
to 小羽
这只能得到当前的时间,而不是程序的编译时间
 
使用命令行倒是可以。
?:/Program Files/Borland/Delphi5/Projects>dcc32 project1.dpr
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
Unit1.pas(176)
Project1.dpr(14)
192 lines, 1.38 seconds, 316756 bytes code, 7437 bytes data.
 
不会是dcu的时间吧?
如果是exe的时间就很容易了。
 
噢,你要得到程序是什么时候产生的?这个真的很容易
 
这个就可以。
function GetFileTimes(const FileName: string;
var Created: TDateTime;
var Accessed: TDateTime;
var Modified: TDateTime): Boolean;
var
h: THandle;
Info1, Info2, Info3: TFileTime;
SysTimeStruct: SYSTEMTIME;
TimeZoneInfo: TTimeZoneInformation;
Bias: do
uble;
begin
Result := False;
Bias := 0;
h := FileOpen(FileName, fmOpenRead or fmShareDenyNone);
if h > 0 then
begin
try
if GetTimeZoneInformation(TimeZoneInfo) <> $FFFFFFFF then
Bias := TimeZoneInfo.Bias / 1440;
// 60x24
GetFileTime(h, @Info1, @Info2, @Info3);
if FileTimeToSystemTime(Info1, SysTimeStruct) then
Created := SystemTimeToDateTime(SysTimeStruct) - Bias;
if FileTimeToSystemTime(Info2, SysTimeStruct) then
Accessed := SystemTimeToDateTime(SysTimeStruct) - Bias;
if FileTimeToSystemTime(Info3, SysTimeStruct) then
Modified := SystemTimeToDateTime(SysTimeStruct) - Bias;
Result := True;
finally
FileClose(h);
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Date1, Date2, Date3: TDateTime;
begin
if GetFileTimes(Edit1.Text, Date1, Date2, Date3) then
begin
ShowMessage('Created: ' + DateTimeToStr(Date1));
ShowMessage('Last Accessed: ' + DateTimeToStr(Date2));
ShowMessage('Last Modified: ' + DateTimeToStr(Date3));
end;
end;
 
谢谢各位,我补充几点:
我想在ABOUT窗口中自动的加入程序编译日期和时间
在C++中有一个_ _DATE_ _ _ _TIME_ _ 的宏定义可以实现这个目的
但是在DELPHI中,我不知道是不是有类似的宏定义
用API获取文件信息的方法太麻烦,有没有简单些的方法?
 
目前知道的就是这个API了[:(]
 
结账了,决定采用yzhshi的方法
 

Similar threads

顶部