1
[Code]
type
  TSystemTime = record
    wYear: Word;
    wMonth: Word;
    wDayOfWeek: Word;
    wDay: Word;
    wHour: Word;
    wMinute: Word;
    wSecond: Word;
    wMilliseconds: Word;
  end;

procedure GetLocalTime(var lpSystemTime: TSystemTime);  external 'GetLocalTime@kernel32.dll';

function DateToInt(ATime: TSystemTime): Cardinal;
begin
  //Converts dates to a integer with the format YYYYMMDD, 
  //which is easy to understand and directly comparable
  Result := ATime.wYear * 10000 + aTime.wMonth * 100 + aTime.wDay;
end;


function InitializeSetup(): Boolean;
var
  LocTime: TSystemTime;
begin
  GetLocalTime(LocTime);
  if DateToInt(LocTime) > 20121001 then //(10/1/2012)
  begin
    Result := False;
    MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
  end;
end;

Is this was what I needed, an installer with an expiration date. I added this code: it works when the date has passed and give the message, but not when the date is valid not boot the installer.

gives the message: InitializeSetup returned False; aborting. Got EAbort exception. Deinitializing Setup. ***Setup exit code: 1

can you help me? thanks

Sweeper
  • 465
  • 1
  • 4
  • 15
  • 1
    Note that adding an expiry date to the installer is easily defeatable. I'm not saying that it's worthless, but you should not be relying on it for licensing/trials/betas. – Miral Nov 13 '13 at 09:06
  • The code from this question was taken from [this question](http://stackoverflow.com/a/13222717/588306). I'd prefer to remove the code as irrelevent and strip it down to "I return false and get an EAbort error". Any thoughts? – Deanna Nov 13 '13 at 14:41
  • If any of the answers helped answer your question, please mark it as the accepted answer. If they didn't, please provide some more information so it can be, – Deanna Nov 22 '13 at 23:08

2 Answers2

3

When InitializeSetup exists in your script the default value of result is false, i.e. if you want your installer to continue you have to explicitly set the result value to true.

May I also suggest you simplify your code and use the built-in date routine GetDateTimeString. The following code should do the job. Hope this helps.

[Code] 

const MY_EXPIRY_DATE_STR = '20131112'; //Date format: yyyymmdd

function InitializeSetup(): Boolean;
begin
  //If current date exceeds MY_EXPIRY_DATE_STR then return false and exit Installer.
  result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), MY_EXPIRY_DATE_STR) <= 0;

  if not result then
    MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end;
Lars
  • 1,428
  • 1
  • 13
  • 22
  • I've just posted a correction to the [previous answer](http://stackoverflow.com/a/13222717/588306) where this code came from. – Deanna Nov 13 '13 at 14:44
1

You will get that message when running the setup in the IDE and the InitializeSetup() event function returns false. This will not effect the compiled setup.

Deanna
  • 23,876
  • 7
  • 71
  • 156