DelphiFAQ Home Search:

How to get the compile Date into the executable

 

comments6 comments. Current rating: 4 stars (3 votes). Leave comments and/ or rate it.

It's very nice to have a number say in the about box that the customer can read you, and you can immediately find the version.

Write a program which outputs the current date to a text file called something like 'today.inc' and include it with {$include today.inc} in each of your units.
Then integrate this little tool into your Delphi IDE and run it every time you make a new build.

// by Martin Larsson, martin.larsson@delfi-data.msmail.telemax.no
// include file "today.inc"
const
   _day   : string[10] = 'Monday';
   _date  : word = 12;
   _month : word = 8;
   _year  : word = 1996;

Content-type: text/html

Comments:

2007-01-29, 19:38:08
anonymous from Korea (R)  
'Then integrate this little tool into your Delphi IDE and run it every time you make a new build.'

Running that little tool manually isn't a matter. But is there a way to run it automatically before building?
2008-02-06, 19:07:40
anonymous from Hong Kong  
rating
well, I don't see any post or pre build events in my Delphi 7 contrary to VS2005. Am I missing something or this is just wishfull thinking.
2008-03-20, 16:01:04
ksi@telkomsa.net from South Africa  
An easier and neater way is to use the compiled project exe file date. In VB .NET 2003 this is easily done with

Inports System.IO
,
,
,

dim strDate as string
dim fName as string

fName = Application.StartupPath & '\YourProjectFilename.exe'

strDate= File.GetLastWriteTime(fName)

QED
2008-04-17, 19:44:12
periander@hotmail.com from Australia  
I would not suggest using the last write time if you are depending on the version for things such as database restructuring, (i.e., if you're using version 20080401 but the exe says it's version 20080418). The reason for this is that your executable's 'Date Modified' can be altered fairly easily, and as such does not represent the actual compilation date always.

That being said, it will work most of the time, and it is a fairly neat way.

The first suggestion is probably better, basically having a const hard coded to a date and/or time stamp.
2009-07-05, 00:47:45
Jim08@aapcb.com  
rating
...That being said, it will work most of the time, and it is a fairly neat way.

I agree, but here's what I'm doing. (Thanks for the idea!) Use an .ini file to *store* the CompileDate every time that you compile&run. When the About uses the 'CompileDate' variable, it will be accurate to the minute of the last compile & run. Be sure to include the .ini file in the initial distribution and updates.

Var
tempStr : string;
tempDate : tdatetime;

Begin

myIniFile := TIniFile.Create('MyName.ini'); // gen and/or open the .ini

// get the timestamp
TempStr := path + name + '.dproj';
if FileAge(TempStr, tempDate) = true then // get the true compile date
MyIniFile.WriteFloat ('Defaults', 'CompileDate', tempDate);
End;

(results found in the ini file)
[Defaults]
CompileDate=39998.9106561806

(when reading the .ini)
strCompileDate := FloatToStr(MyIniFile.Readfloat('Defaults', 'CompileDate',0.0));

Yes, since 'FileAge' as a single variable syntax is deprecated. I'm using the newer overloaded version that sets a Tdatetime variable. Nice.

In fini... it is unfortunate that using a second file (ini) for updates, will LOSE the true date if only the exe is distributed. GACK! I'm afraid that 'updates' (newer compiledates) may require a non-visible label with the 'release date' MANUALLY embedded. Now...if only I knew how to change a label.caption and have it SAVED when I save the form. Any help there?
2009-08-04, 11:44:59
[hidden] from Longmont, United States  
rating
Per my previous message, I did learn how to embed the compile date into a form.

Add a blank form to your project. I called it 'Compile_Date'. After the first compile you'll also have a Compile_Date.DFM which is something you can modify *BEFORE* you do...
Application.CreateForm(TCompile_date, Compile_date); {in your main.DFM}

So, in the CreateForm event for the MAIN form, you can include the following, which will automatically update the 'Compile_date.DFM' only while you are running it in your development environment. (FileExists)

procedure TmainForm.formcreate(Sender: TObject);
var
slVersion : tstringlist;
i : integer;
const
Version : string = 'Compile_Date.DFM';
begin
slVersion := tstringlist.create;
if FileExists(Version) = true then
begin
slVersion.LoadFromFile(Version);
for i := 0 to slVersion.Count - 1 do
if pos('Caption',slVersion[i]) > 0 then
SLVersion[i] := 'Caption = ''' + DateTimeToStr(now) + '' ;
slVersion.SaveToFile(Version);
end;
end;

Bottom line: its an easy solution, but I'll go one better. The folks at Embarcadero (Delphi) now have a TCompile Unit!!! It has MUCH more than just a compile date. :)

The unit file 'Project.pas' contains the following constants:
PROJECT_NAME: The name of the project.
EXE_FILENAME: The file name of the project.
DATE_CREATED: The date that the project was originally created.
AUTHORS_NAME: The name of the people who wrote the code for the project.
CONTACT_INFO: Contact information: eMail, phone number, address, etc.
COMPILE_DATE: Date project last ran inside Delphi.
COMPILE_TIME: Time project last ran inside Delphi.
BUILD_NUMBER: Number of times the project has been ran from inside Delphi.
UNIQUE_IDKEY: Unique identifier for the project. It has the ProjectName, CompileDate and CompileTime. NOTE: This constant is updated every compile to reflect the current compile date and time.

http://cc.embarcade..tem/25359

The only negative I can see is that you need to also embed your project path. So, don't move the puppy!

Regards,
Jim8's


 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: