Mega Code Archive

 
Categories / Delphi / Examples
 

Adding the compile date automatically to a project

Create a mini app (30k) called TODAY.EXE with the following code (note this is a .DPR-file with the main form removed from the project !): Program Today; USES Windows,SysUtils; {$R *.RES} VAR f : TextFile; i : Integer; dd,mm,yy: word; BEGIN DecodeDate(Date,yy,mm,dd); AssignFile(f,'c:\windows\Today.inc'); Rewrite(f); WRITELN(f,'CONST'); WRITELN(f,'_Day : WORD = '+IntToStr(dd)+';'); WRITELN(f,'_Month: WORD = '+IntToStr(mm)+';'); WRITELN(f,'_Year : WORD = '+IntToStr(yy)+';'); CloseFile (F); END. Compile this project and move the resulting TODAY.EXE to the Windows directory. Edit WIN.INI and add the following line to the [windows] section: { assuming "windows" as the name of your Win-Dir: } run=c:\windows\today.exe This executes TODAY.EXE each time windows is booted (presumed daily) and updates the constants which are stored in "c:\today.inc" (an include file). Now all you have to do to access these constants is to add the include file to the unit you wish to use them in with the following statement: {$I c:\windows\today.inc} { Now you could do the following...} LblCompileDate.Caption := IntToStr(_Day)+'/'+IntToStr(_Month)+'/'+IntToStr(_Year);