Wednesday, January 5, 2011

Adding An Expiration Date To An Application

unit Unit1;

interface

uses
  Windows, SysUtils, Classes, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
 
implementation

{$R *.DFM}     

procedure TForm1.FormShow(Sender: TObject);
var
  TheYear, TheMonth, TheDay : Integer;
begin
{ Set the expiration date information here. }
  TheYear  := 2001;
  TheMonth := 12;
  TheDay   := 1;
{ Take the desired action below if the current
  date is greater than the expiration date.
  In this example, we close the application;
  but you might also just disable buttons or
  or other elements of the application. }
  if (Date >= EncodeDate(TheYear, TheMonth, TheDay)) then
     begin
        ShowMessage('This application demo has expired.');
        Close;
     end;
end;

end.






SysUtils includes a function called EncodeDate which makes it simple to compare dates.  In this example we use the native Date function to get the current system date, and then compare it to a reference date set with the variables TheYear, TheMonth, and TheDate.  If the current date is greater then the reference date, then we close the application.
In practice, you'd probably disable various buttons or other controls in the application to limit functionality, rather than close the application; as you'd most likely want to provide a means for the application user to register or purchase the product.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum