var
reg:TRegistry;
begin
reg:=Tregistry.Create;
reg.RootKey:=HKEY_CURRENT_USER;
if not reg.KeyExists('/Software/tt/tt') then //判断是否有主键;
begin
//这里是当不存在要做的程序
end;
reg.closekey;
reg.free;
判断建值是否存在
if not reg.valueExists('user') then
begin
reg.WriteInteger('user',strtoint(edit1.text));
end;
reg.closekey;
reg.free;
一篇利用注册表给程序加入试用期的列子。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, registry;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
var reg:tregistry; const a=10;
begin
reg:=tregistry.Create;
if not reg.KeyExists('ddd/ddd') then
begin
reg.CreateKey('ddd/ddd');
end;
reg.OpenKey('ddd/ddd',true);
if not reg.valueExists('aaa')then
begin
reg.WriteString('aaa','0');
end;
edit1.Text:=reg.Readstring('aaa');
edit3.Text:=inttostr(strtoint(edit1.Text)+strtoint(edit2.Text));
reg.Writestring('aaa',''+edit3.text+'');
reg.CloseKey;
if a<strtoint(edit3.text) then
showmessage('ddddddd');
end;
end.
reg:TRegistry;
begin
reg:=Tregistry.Create;
reg.RootKey:=HKEY_CURRENT_USER;
if not reg.KeyExists('/Software/tt/tt') then //判断是否有主键;
begin
//这里是当不存在要做的程序
end;
reg.closekey;
reg.free;
判断建值是否存在
if not reg.valueExists('user') then
begin
reg.WriteInteger('user',strtoint(edit1.text));
end;
reg.closekey;
reg.free;
一篇利用注册表给程序加入试用期的列子。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, registry;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
var reg:tregistry; const a=10;
begin
reg:=tregistry.Create;
if not reg.KeyExists('ddd/ddd') then
begin
reg.CreateKey('ddd/ddd');
end;
reg.OpenKey('ddd/ddd',true);
if not reg.valueExists('aaa')then
begin
reg.WriteString('aaa','0');
end;
edit1.Text:=reg.Readstring('aaa');
edit3.Text:=inttostr(strtoint(edit1.Text)+strtoint(edit2.Text));
reg.Writestring('aaa',''+edit3.text+'');
reg.CloseKey;
if a<strtoint(edit3.text) then
showmessage('ddddddd');
end;
end.