• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

Date of compilation?

Hello,
Is there a way for me to include the date of compilation (eg. display as label1.caption) in a program without typing it every time before compilation?
Thanks!
(D2, Win95)
0
yingkit
Asked:
yingkit
  • 8
  • 4
  • 3
  • +1
1 Solution
 
viktornetCommented:
well what you could do is the following...

the DOF file that is generated as you compile the app, contains the information you need... it is an INI file so you can use TIniFile object to read the needed info... just create a sample project, save it, and compile, and take a look at the DOF file and see what it contains...

You can read the info in OnCreate() of the form...

Good Luck!!

..-=ViKtOr=-..
0
 
intheCommented:
...
0
 
yingkitAuthor Commented:
Can you give me some sample codes?  As I am only a beginner.
Thx
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
yingkitAuthor Commented:
Viktor,
I think you have misunderstood my question, by examining the .DOF file, I can't find any date.
Maybe I need to clarify my question.  What I want to do is, when compiling, for examples, the label1.caption will be changed automatically to the current date(eg. 19, Jul, 1999).

Thanks.
0
 
viktornetCommented:
I don't think there is an easy way of doing that... you can write the current date to a file and read it every time I guess... but you would have to run the app and not only compile it in order for this method to work... is that okay for you?
0
 
intheCommented:
here is a easy way:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function GetFileDate(TheFileName: string): string;
    var
      FHandle:integer ;
    begin
      FHandle := FileOpen(TheFileName, 0);
      try
        Result := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));
      finally
        FileClose(FHandle);
      end;
    end;

function GetCompileDateTime(const FileName: string): TDateTime;
var
  FHandle: Integer;
  CompTime1, CompTime2: TFileTime;
  SysTime: TSystemTime;
  begin
  Result := 0.0;
  FHandle := CreateFile(PChar(FileName),
                        0,FILE_SHARE_READ or FILE_SHARE_WRITE,
                        nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
  if FHandle >= 0 then
    try
      if GetFileTime(FHandle, nil, nil, @CompTime2) then
        if FileTimeToLocalFileTime(CompTime2, CompTime1) then begin
          FileTimeToSystemTime(CompTime1, SysTime);
          Result := SystemTimeToDateTime(SysTime);
        end;
    finally
      CloseHandle(FHandle);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=DateTimeToStr(GetCompileDateTime(ParamStr(0)));
end;

end.




Regards Barry
0
 
intheCommented:
ignore the getfiledate function that didnt work very well ,it woulnt work eith paramstr(0) <-- that gives you the path to the exefile
anyway you just use this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function GetCompileDateTime(const FileName: string): TDateTime;
var
  FHandle: Integer;
  CompTime1, CompTime2: TFileTime;
  SysTime: TSystemTime;
  begin
  Result := 0.0;
  FHandle := CreateFile(PChar(FileName),
                        0,FILE_SHARE_READ or FILE_SHARE_WRITE,
                        nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
  if FHandle >= 0 then
    try
      if GetFileTime(FHandle, nil, nil, @CompTime2) then
        if FileTimeToLocalFileTime(CompTime2, CompTime1) then begin
          FileTimeToSystemTime(CompTime1, SysTime);
          Result := SystemTimeToDateTime(SysTime);
        end;
    finally
      CloseHandle(FHandle);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=DateTimeToStr(GetCompileDateTime(ParamStr(0)));
end;

end.
0
 
yingkitAuthor Commented:
Hello,
It seems that D2 doesn't have the function "SystemTimeToDateTime", is it possible for me to "extract" the year, month, and day from the variable "SysTime" ??

Thanks.
0
 
intheCommented:
Hi YingKit
sorry about that,
just change the result of the GetCompileDateTime function to equal:
Result := systime.wYear + systime.wmonth + systime.wday;

now should work ok on d2 and give the result what you want , please tell me if ok
Regards Barry
0
 
yingkitAuthor Commented:
Hi Barry,
After modifying the codes, the program can be compiled.  However, the date output seems incorrect.  For instance, when the BIOS date is 19, July, 1999, the compiled codes gave me an output '1905/7/17' but not '1999/7/19'
What's wrong?
0
 
intheCommented:
no its not correct its showing delphis systemtime which means this aint gonna work with d2 youll have to use:

function GetFileDate(TheFileName: string): string;
    var
      FHandle:integer ;
    begin
      FHandle := FileOpen(TheFileName, 0);
      try
        Result := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));
      finally
        FileClose(FHandle);
      end;
    end;

on the buttonclick or whatever do
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption:=getfiledate('c:\string_path_to_the_file');
end;

please tell me that works in d2 :-)
0
 
kretzschmarCommented:
hi barry,

what, if someone like me change the filedate of the exe-file ?

meikl ;-)


0
 
intheCommented:
then i would teach yingkit to use the setfiledate function to put it back then come round your house and kick your a** ;-)
0
 
kretzschmarCommented:
;-) haha
0
 
intheCommented:
;-) should be filesetdate

actually yingkit be careful if your making commercial/shareware software using d2 date functions as they are not guaranteed to be millenium friendly..
see inprise site for more details but they only supporting the latest versions of d3 & d4 if i remember right.
dont go worrying just thought i mention it so you are aware..



0
 
viktornetCommented:
Barry, what do you think this was??


"....... you can write the current
     date to a file and read it every time I guess... but you would have to run the
     app and not only compile it in order for this method to work... is that okay for
     you?"

?!?!
0
 
intheCommented:
i dunno viktor what is it ? a comment?
what does the above comment mean?
i didnt steal your points or something just gave a workable answer?when you comment a question unless the comment directl;y contains the answer you dont own the question..thats like saying
"mr questioner please dont let anyone answer except me"
what is the problem with my answer anyway. ,there no need to write the date to a file and read that...when you can read from the exe with paramstr(0).geez ya try and help someone and all ya get is mista moody biting ya ankles off ... :-[


yingkit another one:

procedure TForm1.Button1Click(Sender: TObject);
 Var
  S1 : String;
  F1 : File;
  FStruct : TOFSTRUCT;
  TheDate : TDateTime;
  Han1 : Integer;
  I : Integer;
begin
  S1 := paramstr(0);
  Han1 := OpenFile(PChar(S1), FStruct, OF_SHARE_DENY_NONE);
  I := FileGetDate(Han1);
  TheDate := FileDateToDateTime(I);
  Label1.Caption := DateTimeToStr(TheDate);
 _lclose(Han1);
end;

0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 8
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now