CodeTyphon自带例子源码:限制运行日期

原创 2015年11月18日 21:23:00


C:\codetyphon\CodeOcean\OnGuard\samples\exdys30

    这个例子演示了直接在代码中写入超期日期。软件第一次运行时,生成ini文件并写入超期时间,例如2015-11-30,如果当前运行时间超过改时间,则提示并退出。






{**********************************************************************
 CodeOcean
 Demo for Package pl_OnGuard.pkg
 This unit is part of CodeTyphon Project (http://www.pilotlogic.com/)
***********************************************************************}
(*
  This program uses the TOgDaysCode component. The first time the
  program is run, the necessary information is created and stored
  in an INI file. In addition, the program is given a "drop dead"
  date, i.e., regardless of how many days the program has been used,
  it cannont be used after that date (2014-12-31).

  NOTE:   *** This feature has now been disable in OnGuard ***
  InvalidCount is set to 3, user is allowed to 3 times break the rules,
  for example changing date back to execute program after trial period expired.
*)
unit Exdys30u;

interface

uses
  SysUtils, Classes, Controls,
  Forms, Dialogs,LResources, StdCtrls, Buttons,
  OnGuard,OgUtil,IniFiles;

const
  CKey : TKey = ($E5,$8F,$84,$D6,$92,$C9,$A4,$D8,
                 $1A,$FA,$6F,$8D,$AB,$FC,$DF,$B4);

type

  { TForm1 }

  TForm1 = class(TForm)
    Memo1: TMemo;
    CloseBtn: TBitBtn;
    OgDaysCode1: TOgDaysCode;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure OgDaysCode1GetKey(Sender: TObject; var Key: TKey);
    procedure OgDaysCode1GetCode(Sender: TObject; var Code: TCode);
    procedure OgDaysCode1ChangeCode(Sender: TObject; Code: TCode);
    procedure OgDaysCode1Checked(Sender: TObject; Status: TCodeStatus);
  private
    codeinvalid : Boolean;
  public
    { Public declarations }
    TheDir  : string;
    IniFile : TIniFile;
  end;

var
  Form1: TForm1;

implementation



{==========================================================================}

procedure TForm1.OgDaysCode1GetKey(Sender: TObject; var Key: TKey);
begin
  Key := CKey;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    codeinvalid := false;
end;

{==========================================================================}

procedure TForm1.OgDaysCode1GetCode(Sender: TObject; var Code: TCode);
var
  S       : string;
  Expires : TDateTime;
  L       : integer;
begin
  {force the INI file to be in the same directory as the application}
  TheDir := ExtractFilePath(ParamStr(0));
  {
  L := Length(TheDir);
  if (L > 3) and (TheDir[L] <> '\') then
    TheDir := TheDir + '\';}

  {open Ini File}
  IniFile := TIniFile.Create(TheDir + 'Days30.INI');
  try
    {try to read release code}
    S := IniFile.ReadString('Codes', 'DaysCode', 'NoCode');

    {If default string returned, create code on the fly}
    if (S = 'NoCode') then begin
      { force absolute ("drop dead") expiration date of 2014-12-31 }
      Expires := EncodeDate(2015, 11, 30);
      InitDaysCode(CKey, 12, Expires, Code,3);

      {save string representation of release code to Ini File}
      S := BufferToHex(Code, SizeOf(Code));
      IniFile.WriteString('Codes', 'DaysCode', S);
    end else
      {convert retrieved string to a code}
      HexToBuffer(S, Code, SizeOf(Code));
  finally
    IniFile.Free;
  end;
end;

{==========================================================================}

procedure TForm1.OgDaysCode1ChangeCode(Sender: TObject; Code: TCode);
var
  S       : string;
begin
  if codeinvalid then
    Exit;
  IniFile := TIniFile.Create(TheDir + 'Days30.ini');
  try
    {convert Code to string for writing to INI file}
    S := BufferToHex(Code, SizeOf(Code));
    IniFile.WriteString('Codes', 'DaysCode', S);
  finally
    IniFile.Free;
  end;
end;

{==========================================================================}

procedure TForm1.OgDaysCode1Checked(Sender: TObject; Status: TCodeStatus);
var
  S : string;
begin
  case Status of
    ogValidCode    : begin
                       Label1.Caption := 'Days Remaining: '
                                       + IntToStr(OgDaysCode1.GetValue);
                       Exit;
                     end;

    ogInvalidCode  :
    begin
     S := 'Invalid Code';
     codeinvalid := true;
    end;

    ogDayCountUsed : S := 'Program used more than 30 days' + #13 +
                          'Please register NOW';

    ogCodeExpired  : S := 'Evaluation period expired' + #13 +
                          'Please register NOW';
  end;
  ShowMessage(S);
  Application.Terminate;
end;

initialization
{$i exdys30u.lrs}

end.



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Android中如何编译运行系统自带桌面Launcher2源码

原文地址::http://blog.sina.com.cn/s/blog_4b650d650100nstz.html     Android的源码包,压缩文件大概有3个G左右,要使用其中自带的一...

将系统自带的Launcher2源码导入eclipse中编译运行

1.将Launcher2项目导入eclipse中。 这时候Launcher2工程已经导入到eclipse中了,不过这时候会有100多个错误. 2.添加Launcher2使用的包文件。 ...

hadoop基础----hadoop实战(三)-----hadoop运行MapReduce---对单词进行统计--经典的自带例子wordcount

ass

Caffe学习系列(9):运行caffe自带的两个简单例子

为了程序的简洁,在caffe中是不带练习数据的,因此需要自己去下载。但在caffe根目录下的data文件夹里,作者已经为我们编写好了下载数据的脚本文件,我们只需要联网,运行这些脚本文件就行了。 ...

运行caffe自带的两个简单例子

为了程序的简洁,在caffe中是不带练习数据的,因此需要自己去下载。但在caffe根目录下的data文件夹里,作者已经为我们编写好了下载数据的脚本文件,我们只需要联网,运行这些脚本文件就行了。 注意...

spark 自带的例子在eclipse下运行的方法

spark 自带java例子在eclipse下运行。

Google Protocol Buffers自带c++,java,python例子程序编译运行

在我的前一篇文章《Protocol Buffers的安装使用和C++/Python入门示例》中提到google protocol buffers自带了examples,里面有c++,java,...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)