【例子介绍】Delphi开发的MSSQL管理工具源代码
【相关图片】
【源码结构】
unit setting;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tsetfrm = class(TForm)
CheckBox1: TCheckBox;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
CheckBox2: TCheckBox;
procedure CheckBox1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CheckBox2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
function LoadSetting(Key, Item: String; DefValue: Boolean): Boolean;
procedure SaveSetting(Key, Item: String; Value: Boolean);
procedure RemoveSetting(Key: String);
function LoadStrSetting(Key, Item: String; DefValue: string): string;
procedure SaveStrSetting(Key, Item: String; Value: string);
procedure RemoveStrSetting(Key: String);
public
{ Public declarations }
end;
var
setfrm: Tsetfrm;
implementation
{$R *.dfm}
uses Registry;
const
StartHiddenKey = 'Software\CoolTrayIcon\StartHiddenDemo';
function Tsetfrm.LoadSetting(Key, Item: String; DefValue: Boolean): Boolean;
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(Key);
Result := Reg.ReadBool('', Item, DefValue);
Reg.Free;
end;
procedure Tsetfrm.SaveSetting(Key, Item: String; Value: Boolean);
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(Key);
Reg.WriteBool('', Item, Value);
Reg.Free;
end;
procedure Tsetfrm.RemoveSetting(Key: String);
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(Key);
Reg.EraseSection('');
Reg.Free;
end;
//// ×Ö·û´®
function Tsetfrm.LoadStrSetting(Key, Item: String; DefValue: string): string;
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(Key);
Result := Reg.ReadString('', Item, DefValue);
Reg.Free;
end;
procedure Tsetfrm.SaveStrSetting(Key, Item: String; Value: string);
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(Key);
Reg.WriteString('', Item, Value);
Reg.Free;
end;
procedure Tsetfrm.RemoveStrSetting(Key: String);
var
Reg: TRegIniFile;
begin
Reg := TRegIniFile.Create(Key);
Reg.EraseSection('');
Reg.Free;
end;
procedure Tsetfrm.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
SaveSetting(StartHiddenKey, 'StartHidden', True)
else
RemoveSetting(StartHiddenKey);
end;
procedure Tsetfrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
self.Release;
self.Close;
end;
procedure Tsetfrm.CheckBox2Click(Sender: TObject);
begin
self.Edit1.Enabled:=self.CheckBox2.Checked;
end;
procedure Tsetfrm.FormShow(Sender: TObject);
begin
self.Edit1.Text:= LoadStrSetting(StartHiddenKey, 'ServerPort', '3001');
end;
procedure Tsetfrm.Button1Click(Sender: TObject);
begin
SaveStrSetting(StartHiddenKey, 'ServerPort', trim(self.Edit1.Text));
end;
procedure Tsetfrm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8,#10,#13]) then
begin
key:=#0;
end;
end;
end.
评论