Board index » delphi » can compiler add a timestamp ?

can compiler add a timestamp ?

Hi,

different C compiler expand the variables __TIME__ and
__DATE__ to the current time and date, which allows
setting nice timestamps e.g. in an about box.

 a.) Is there anything similar in Delphi?

 b.) if not, is these a way do define an EXE file executed
     everytime the compiler is stadtet (from IDE and command
     line). This EXE file could crate a unit which defindes
     this variables and this unit is then compiles into
     the projects.

 c.) if not, are therey any compiler switched which which
     refer to a specific date? Would be an ugly solution
     but if this workes...?

 or is there any other way?

 The last solution would be to read the apps EXE file itself,
 since the PE header contains such a value....

regards, Axel

 

Re:can compiler add a timestamp ?


within the C++ Builder - Package ( I have version 3) there is the

touch.exe

which creates a timestamp (and more)!

I don't know why it is not included in Delphi, but perhaps you can download
it samewhere or I can emial it to you...
I think it will work on any PC because its a DOS-Application!

MArtin

Re:can compiler add a timestamp ?


"Axel Heider" <axel.hei...@towitoko.de> skrev i melding
news:3B4C3E2A.6AB4925F@towitoko.de...

Quote
> Hi,

> different C compiler expand the variables __TIME__ and
> __DATE__ to the current time and date, which allows
> setting nice timestamps e.g. in an about box.

>  a.) Is there anything similar in Delphi?

>  b.) if not, is these a way do define an EXE file executed
>      everytime the compiler is stadtet (from IDE and command
>      line). This EXE file could crate a unit which defindes
>      this variables and this unit is then compiles into
>      the projects.

>  c.) if not, are therey any compiler switched which which
>      refer to a specific date? Would be an ugly solution
>      but if this workes...?

>  or is there any other way?

>  The last solution would be to read the apps EXE file itself,
>  since the PE header contains such a value....

Isn't it strange, what kinds of questions may get your head working ?

I created a component that stores Compile Time (credits to Ray Lischner for
revealing the toolsAPI in his famous "Hidden Paths of Delphi 3").

A Requirement when using this component is allways to have the unit
containing it open in the editor when compiling.
A sideeffect from using this component is that the unit containing the
component is rewritten upon every compile.

A simpler approach may be creating the notifier like I did here, but instead
have it write a resource file, and have this compiled into the project.

I believe this is the oddest lines of code I've written this month...;-)

------------
unit CompileTime;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  toolsAPI, DsgnIntf, ToolIntf, ExptIntf, EditIntf;

type
  TCompileTime = class;

  TCompileNotifier = class(TIAddInNotifier)
  private
    FCompileTime: TCompileTime;
  public
    constructor Create(AOwner: TCompileTime);
    destructor destroy; override;
    procedure EventNotification(NotifyCode: TEventNotification; var Cancel:
boolean); override;
    procedure FileNotification(NotifyCode: TFileNotification; const FileName:
string; var Cancel: boolean); override;
  end;

  TCompileTime = class(TComponent)
  private
    FCompileTime: TDateTime;
    FNotifier: TCompileNotifier;
    procedure SetCompileTime(const Value: TDateTime);
    function GetCompileTime: TDateTime;
    procedure SetUnitModified;
  protected
  published
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property CompileTime: TDateTime read GetCompileTime write SetCompileTime;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Vici', [TCompileTime]);
end;

{ TCompileTime }

constructor TCompileTime.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FNotifier:=TCompileNotifier.Create(Self);
  CompileTime:=Now;
  SetUnitModified;
end;

procedure TCompileTime.SetUnitModified;
var
  EI: TIEditorInterface;
  MI: TIModuleInterface;
  FI: TIFormInterface;
begin
  if Assigned(ToolServices) then begin

MI:=ToolServices.GetModuleInterface(ChangeFileExt(ToolServices.GetCurrentFile
, '.pas'));
    if MI <> nil then begin
      EI:=MI.GetEditorInterface;
      if EI <> nil then
        EI.MarkModified;
      FI:=MI.GetFormInterface;
      if FI <> nil then
        FI.MarkModified;
    end;
  end;
end;

destructor TCompileTime.Destroy;
begin
  FNotifier.Free;
  inherited Destroy;
end;

function TCompileTime.GetCompileTime: TDateTime;
begin
  result:=FCompileTime;
end;

procedure TCompileTime.SetCompileTime(const Value: TDateTime);
begin
  FCompileTime := Value;
end;

{ TCompileNotifier }

constructor TCompileNotifier.Create(AOwner: TCompileTime);
begin
  inherited Create;
  FCompileTime:=AOwner;
  if Assigned(ToolServices) then begin
    ToolServices.AddNotifierEx(Self);
  end;
end;

destructor TCompileNotifier.destroy;
begin
  if Assigned(ToolServices) then
    ToolServices.RemoveNotifier(Self);
  inherited Destroy;
end;

procedure TCompileNotifier.EventNotification(
  NotifyCode: TEventNotification; var Cancel: boolean);
begin
  if NotifyCode = enBeforeCompile then begin
    FCompileTime.CompileTime:=Now;
    FCompileTime.SetUnitModified;
  end;
end;

procedure TCompileNotifier.FileNotification(NotifyCode: TFileNotification;
  const FileName: string; var Cancel: boolean);
begin
end;

end.
---------------

--
Bjoerge Saether
Consultant / Developer
http://www.itte.no
Asker, Norway
bjorgeremovet...@itte.no (remove the obvious)

Re:can compiler add a timestamp ?


Im Artikel <9iil6m$ikki...@ID-68456.news.dfncis.de>, "Martin Meeser"
<vielevielebuntemar...@yahoo.de> schreibt:

Quote
>touch.exe

only sets the date of it's argument (file name) to the current date/time. It's
often used to force recompilation of source files, by making the source file
younger than it's object file.

But it won't help in adding a time stamp to a program :-(

I'd suggest an batch file for building the application, where a program creates
an unit with a const of the current time. It shouldn't be hard to write a
program, which creates that unit. That unit should be part of the project, of
course.

DoDi

Other Threads