?? commonunit.pas
字號:
unit CommonUnit;
interface
uses
Inifiles,Forms ,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs,StdCtrls, Mask; // Buttons,
type
TOperator=Class //操作員信息
public
OperatorID:string[8];
OperatorPWD:string[8];
OperatorName:string[8];
OperatorPower:Array[1..4] of boolean;
end;
//清空輸入的值
TClearValue=Class(Tobject)
public
procedure Clear(form:TForm);
end;
TSetupConfig=Class(Tobject) //系統配置
private
FileName:string;
iniFile:TIniFile;
ConnString:string;
OperatorID:string;
bgImg:string;
LeftBar:boolean;
ToolBar:boolean;
LogoImg:boolean;
LeftBarStyle:integer;
ImgNo:integer;
host:string;
DataBaseName:string;
public
procedure ReadConfig(); //讀取配置信息
procedure SaveConfig(); //保存配置信息
constructor Create(filename:string);
property LastOperatorID:string read OperatorID write OperatorID; //上次登錄用戶
property ConnectionString:string read connString write connString;//連接字符串
property BackGroundImage:string read bgImg write bgImg;//背景圖片
property ShowLeftBar:boolean read LeftBar write LeftBar;//是否顯示左邊的工具欄
property ShowToolBar:boolean read ToolBar write ToolBar;//是否顯示工具欄
property ShowLogoImg:boolean read LogoImg write logoImg;//是否顯示Logo
property SetLeftBarStyle:integer read leftBarStyle write leftBarStyle; //左側工具欄樣式
property SetImgNo:integer read ImgNo write ImgNo; //左側工具欄樣式
property SetHost:string read Host write Host;
property SetDataBaseName:string read DataBaseName write DataBaseName;
end;
type //檢查Edit中的值是否為0
TCheckValue=Class(Tobject)
public
procedure checkEditValue(Edit1:TEdit;flag:string);
procedure checkMaskEditValue(MaskEdit1:TMaskEdit);
end;
implementation
//檢查合法性
procedure TCheckValue.checkEditValue(Edit1:TEdit;flag:string);
var
v1:integer;
v2:real;
begin
//判斷是否為空
if trim(Edit1.Text)='' then
begin
Application.MessageBox('輸入的值不能為空格','提示',mb_ok);
Edit1.SetFocus;
end;
if flag='int' then
v1:=StrToIntDef(edit1.Text,0)
else
v2:=StrToFloatDef(edit1.Text,0) ;
//判斷值是否為0
if ((v1=0) or (v2=0)) then
begin
Application.MessageBox('輸入的值非法,或為0!','提示',mb_ok);
Edit1.SetFocus;
end;
end;
//
procedure TCheckValue.checkMaskEditValue(MaskEdit1:TMaskEdit);
var
V:real;
begin
if MaskEdit1.Text='' then
begin
Application.MessageBox('輸入的值不能為空格','提示',mb_ok);
MaskEdit1.SetFocus;
end
else
V:=StrtoIntDef(MaskEdit1.Text,0);
if v=0 then
begin
end
else
begin
end;
end;
procedure TClearValue.Clear(Form:TForm);
var
i:integer;
begin
for i:=0 to Form.ComponentCount-1 do
begin
{if Form.Components[i] is TEdit then
(Form.Components[i] as TEdit).Text:=''
else
if Form.Components[i] is TCheckBox then
(Form.Components[i] as TCheckBox).Checked:=false; }
end;
end;
//定義配置文件類的方法
Constructor TSetupConfig.Create(fileName:string);
begin
self.FileName:=fileName;
iniFile:=TIniFile.Create(fileName);
end;
//讀取配置信息
procedure TSetupConfig.ReadConfig();
var
connstr:string;
begin
// connstr:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Book;Data Source=127.0.0.1';
DataBaseName:=iniFile.ReadString('DataBaseSetting','DataBaseName','book');
Host:=iniFile.ReadString('DataBaseSetting','Host','127.0.0.1');
LastOperatorID:=iniFile.ReadString('LastOperator','OperatorID','admin');
ConnectionString:=iniFile.ReadString('Connection','ConnectionString',connstr);
BackGroundImage:=iniFile.ReadString('BackGroundImage','bgImg','bgImages\bgImage1.jpg');
ShowLeftBar:=iniFile.ReadBool('Settings','LeftBar',true);
ShowToolBar:=iniFile.ReadBool('Settings','ToolBar',false);
ShowLogoImg:=iniFile.ReadBool('Settings','LogoImg',true);
SetLeftBarStyle:=iniFile.ReadInteger('LeftBarStyles','Style',1);
ImgNo:=iniFile.ReadInteger('BgImageNo','No',-1); //-1:無背景,1-3:背景1-3 ,0:自定義背景
connstr:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog='+DataBaseName+';Data Source='+Host;
end;
//保存配置信息
procedure TSetupConfig.SaveConfig();
begin
iniFile.WriteString('LastOperator','OperatorID',LastOperatorID);
iniFile.WriteString('Connection','ConnectionString',ConnectionString);
iniFile.WriteString('BackGroundImage','bgImg',BackGroundImage);
iniFile.WriteBool('Settings','LeftBar',ShowLeftBar);
iniFile.WriteBool('Settings','ToolBar',ShowToolBar);
iniFile.WriteBool('Settings','LogoImg',ShowLogoImg);
iniFile.WriteInteger('LeftBarStyles','Style',LeftBarStyle);
iniFile.WriteInteger('BgImageNo','No',ImgNo);
iniFile.WriteString('DataBaseSetting','DataBaseName',DataBaseName);
iniFile.WriteString('DataBaseSetting','Host',Host);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -