Delphi完成限定軟件運用時間的辦法。本站提示廣大學習愛好者:(Delphi完成限定軟件運用時間的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是Delphi完成限定軟件運用時間的辦法正文
我們常常看到很多網上下載的試用版軟件,都有運用時間的限制,就其商業角度而言也是處於軟件效益維護的一種措施,可以讓用戶收費試用一段時間,若稱心就可以購置商業軟件。本文所述實例代碼功用就是如何為Delphi所編寫的順序添加運用時間的限制功用,這裡默許的時限為30天。
次要代碼如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Registry, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
registerTemp : TRegistry;
curDate : TDateTime;
begin
registerTemp := TRegistry.Create;
with registerTemp do
begin
RootKey := HKEY_LOCAL_MACHINE;
//判別能否初次運轉順序
if OpenKey('Software\MySoftware',True) then
begin
if ReadBool('Runned') then
//不是第一次運轉
begin
curDate := Date;
if (curDate-ReadTime('LastRunTime'))>=ReadInteger('Duration') then
begin
//以後的零碎時間超出了運用期限
ShowMessage('試用版已到期');
exit;
end
else
begin
DeleteKey('LastRunTime');
WriteTime('LastRunTime',Date);
end;
end
else
begin
//初次運轉順序
DeleteKey('Runned');
WriteBool('Runned',True);
//設置試用期限30天
WriteInteger('Duration',30);
//寫入以後運轉時間
WriteTime('LastRunTime',Date);
end;
end
else
begin
ShowMessage('Fails!');
end;
CloseKey;
end;
end;
end.