• DELPHI程序注册码设计


    在DELPHI下新建一工程,放置Edit1,Edit2,Label1,Label2,Button1组件.具体代码如下:

    unit Unit1;
    interface
    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls,Registry;//在此加上Registry以便调用注册表.
    type
    TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    private
    Function Check():Boolean;
    Procedure CheckReg();
    Procedure CreateReg();
    { Private declarations }
    public
    { Public declarations }
    end;
    var
    Form1: TForm1;
    PName:string; //全局变量,存放用户名和注册码.
    PPass:integer;
    implementation
    {$R *.DFM}
    Procedure TForm1.CreateReg();//创建用户信息.
    var Rego:TRegistry;
    begin
    Rego:=TRegistry.Create;
    Rego.RootKey:=HKEY_USERS;
    rego.OpenKey('.DEFAULT\Software\AngelSoft\Demo',True);//键名为AngelSoft\Demo,可自行修改.
    Rego.WriteString('Name',PName);//写入用户名.
    Rego.WriteInteger('Pass',PPass);//写入注册码.
    Rego.Free;
    ShowMessage('程序已经注册,谢谢!');
    CheckReg; //刷新.
    end;
    Procedure TForm1.CheckReg();//检查程序是否在注册表中注册.
    var Rego:TRegistry;
    begin
    Rego:=TRegistry.Create;
    Rego.RootKey:=HKEY_USERS;
    IF Rego.OpenKey('.DEFAULT\Software\AngelSoft\Demo',False) then
    begin
    Form1.Caption:='软件已经注册';
    Button1.Enabled:=false;
    Label1.Caption:=rego.ReadString('Name');//读用户名.
    Label2.Caption:=IntToStr(Rego.ReadInteger('Pass')); //读注册码.
    rego.Free;
    end
    else Form1.Caption:='软件未注册,请注册';
    end;
    Function TForm1.Check():Boolean;//检查注册码是否正确.
    var
    Temp:pchar;
    Name:string;
    c:char;
    i,Long,Pass:integer;
    begin
    Pass:=0;
    Name:=edit1.Text;
    long:=length(Name);
    for i:=1 to Long do
    begin
    temp:=pchar(copy(Name,i,1));
    c:=temp^;
    Pass:=Pass+ord(c); //将用户名每个字符转换为ASCII码后相加.
    end;
    if StrToInt(Edit2.Text)=pass then
    begin
    Result:=True;
    PName:=Name;
    PPass:=Pass;
    end
    else Result:=False;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    if Check then CreateReg
    else ShowMessage('注册码不正确,无法注册');
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    CheckReg;
    end;
    end.
    <注册器>
      在DELPHI下新建一工程,放置Edit1,Edit2,Button1组件.具体代码如下:
    unit Unit1;
    interface
    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls;
    type
    TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    var
    Form1: TForm1;
    implementation
    {$R *.DFM}
    procedure TForm1.Button1Click(Sender: TObject);
    var
    Temp:pchar;
    Name:string;
    c:char;
    i,Long,Pass:integer;
    begin
    Pass:=0;
    Name:=edit1.Text;
    long:=length(Name);
    for i:=1 to Long do
    begin
    temp:=pchar(copy(Name,i,1));
    c:=temp^;
    Pass:=Pass+ord(c);
    end;
    edit2.text:=IntToStr(pass);
    end;
    end.  
  • 相关阅读:
    第六章类(十一)构造函数4对象初始化器和集合初始化器
    第六章类(十)构造函数3new
    第六章类(九)构造函数2默认构造函数
    Javascript---- 练习八(字符串操作)
    图解CSS3----white-space空白符处理
    图解CSS3----word-break单词断行
    图解CSS3----word-wrap(单词换行)
    图解CSS3----text-overflow(文本溢出属性)
    图解CSS3----vertical-align(文本垂直对齐方式)
    Javascript---- 练习五(函数,事件绑定)
  • 原文地址:https://www.cnblogs.com/sonicit/p/944426.html
Copyright © 2020-2023  润新知