?
Solved

Date of compilation?

Posted on 1999-07-18
17
Medium Priority
?
339 Views
Last Modified: 2010-04-06
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
Comment
Question by:yingkit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 3
  • +1
17 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1389455
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
 
LVL 17

Expert Comment

by:inthe
ID: 1389456
...
0
 

Author Comment

by:yingkit
ID: 1389457
Can you give me some sample codes?  As I am only a beginner.
Thx
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:yingkit
ID: 1389458
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1389459
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
 
LVL 17

Accepted Solution

by:
inthe earned 60 total points
ID: 1389460
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
 
LVL 17

Expert Comment

by:inthe
ID: 1389461
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
 

Author Comment

by:yingkit
ID: 1389462
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
 
LVL 17

Expert Comment

by:inthe
ID: 1389463
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
 

Author Comment

by:yingkit
ID: 1389464
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
 
LVL 17

Expert Comment

by:inthe
ID: 1389465
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1389466
hi barry,

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

meikl ;-)


0
 
LVL 17

Expert Comment

by:inthe
ID: 1389467
then i would teach yingkit to use the setfiledate function to put it back then come round your house and kick your a** ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1389468
;-) haha
0
 
LVL 17

Expert Comment

by:inthe
ID: 1389469
;-) 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
 
LVL 10

Expert Comment

by:viktornet
ID: 1389470
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
 
LVL 17

Expert Comment

by:inthe
ID: 1389471
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question