这是我的一个程序中的Setup Form,我用它来传递全局变量,也用它来进行参数设置。
在主窗口的OnCreate中,建立gParameter:
procedure TMainForm.FormCreate(Sender: TObject);
begin
gParameter := TParameter.Create(Application);
end;
以下是setup.pas:
unit setup;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
MStringGrid, ExtCtrls, Grids, StdCtrls, ComCtrls, Spin, iniFiles,
Mask, ToolEdit, FileCtrl;
type TSpliteType = (stByVolume,stByChapter,stByNumberOnly,stByNumberAndDot,stByBracketAndNumber,stByAlphabet,stByString);
type TEnglishType = (stEnglishNone,stEnglishLittle,stEnglishLarge,stEnglishExchange);
type TDoubleType = (stDoubleNone,stDoubleSingle,stDoubleDouble);
type TAreaType = (stAreaTotal,stAreaSelected);
type TSaveToType = (stLastDirectory,stOwnDirectory,stDefaultDirectory);
type
TParameter = class(TForm)
....//跟设置值有关的控件,因为我用这个Form来进行参数设置。
private
{ Private declarations }
public
tslPassword :TStringList;
boolShowChildrenList :boolean;
boolSendOneFile :boolean;
boolSkipBBSHead :boolean;
boolDelTerminalBlank :boolean;
boolDelAllBlank :boolean;
boolDelDouble :boolean;
boolReplaceDouble :boolean;
boolSpliteByReturn :boolean;
boolSpliteByChar :boolean;
boolReplaceMultichar :boolean;
boolReplaceString :boolean;
boolChangeBracket :boolean;
boolFirstMiddle :boolean;
boolAddReturn :boolean;
boolWordWrap :boolean;
intLineLength :integer;
intSkipNumber :integer;
intTabNumber :integer;
strEndChar :String;
strNotFirstChar :String;
strNotFirstLineChar :String;
strNotEndLineChar :String;
strDoubleChar :String;
strSingleChar :String;
tslBBSHeads :TStringList;
tslFindStrings :TStringList;
tslReplaceStrings :TStringList;
tslFindMultichars :TStringList;
tslReplaceMultichars :TStringList;
tslHtmlTags :TStringList;
strINIFilePath :String;
strDragDropExt :string;
boolSkipAllClose :boolean;
boolStopSendingMail :boolean;
intSpliteType :integer;
strSpliteType :string;
//Change Type
intEnglishType :integer;
intDoubleType :integer;
intAreaType :integer;
//SaveTo Parameter
intSaveTo :integer;
strLastDirectory :string;
boolUseDefaultOpenDirectory:boolean;
strDefaultOpenDirectory :string;
boolUseDefaultSaveDirectory:boolean;
strDefaultSaveDirectory :string;
boolUseDefaultSaveHtmlDirectory :boolean;
strDefaultSaveHtmlDirectory:string;
aFont :TFont;
boolAllowOnlyOneApplication:boolean;
boolAlwaysOnTop :boolean;
procedure ReadParameter;
procedure WriteParameter;
end;
var
gParameter: TParameter;
implementation
uses MyFunction, Childwin, Main;
{$R *.DFM}
procedure TParameter.FormCreate(Sender: TObject);
begin
boolSkipAllClose := false;
strDoubleChar := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
strSingleChar := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
strINIFilePath := ExtractFilePath(Application.ExeName) + 'BBSSword.ini';
tslBBSHeads := TStringList.Create;
tslFindStrings := TStringList.Create;
tslReplaceStrings := TStringList.Create;
tslFindMultichars := TStringList.Create;
tslReplaceMultichars := TStringList.Create;
tslHtmlTags := TStringList.Create;
tslPassword := TStringList.Create;
aFont := TFont.Create;
ReadParameter;
end;
procedure TParameter.FormDestroy(Sender: TObject);
begin
WriteParameter;
tslBBSHeads.Free;
tslFindStrings.Free;
tslReplaceStrings.Free;
tslFindMultichars.Free;
tslReplaceMultichars.Free;
tslHtmlTags.Free;
tslPassword.Free;
aFont.Free;
end;
procedure TParameter.ReadParameter;
var
BBSSwordini:TIniFile;
i:integer;
FontString:string;
boolSelected:boolean;
begin
BBSSwordIni := TIniFile.Create(strINIFilePath);
strDragDropExt := BBSSwordIni.ReadString('General','DragDropExt','.HTM|.HTML|.TXT');
boolShowChildrenList := BBSSwordIni.ReadBool('Windows','ShowChildrenList',false);
boolWordWrap := BBSSwordIni.ReadBool('Editor','WordWrap',false);
boolSkipBBSHead := BBSSwordIni.ReadBool('Format','SkipBBSHead',true);
boolReplaceDouble := BBSSwordIni.ReadBool('Format','ReplaceDouble',false);
boolDelTerminalBlank := BBSSwordIni.ReadBool('Format','DelTerminalBlank',true);
boolDelAllBlank := BBSSwordIni.ReadBool('Format','DelAllBlank',false);
boolDelDouble := BBSSwordIni.ReadBool('Format','DelDouble',true);
boolSpliteByReturn := BBSSwordIni.ReadBool('Format','SpliteByexit',true);
boolSpliteByChar := BBSSwordIni.ReadBool('Format','SpliteByChar',true);
boolReplaceMultichar := BBSSwordIni.ReadBool('Format','ReplaceMultichar',false);
boolReplaceString := BBSSwordIni.ReadBool('Format','ReplaceString',false);
boolChangeBracket := BBSSwordIni.ReadBool('Format','ChangeBracket',false);
boolFirstMiddle := BBSSwordIni.ReadBool('Format','FirstMiddle',true);
boolAddReturn := BBSSwordIni.ReadBool('Format','Addexit',true);
intLineLength := StrToInt(BBSSwordIni.ReadString('Format','LineLength','72'));
intSkipNumber := StrToInt(BBSSwordIni.ReadString('Format','SkipNumber','0'));
intTabNumber := StrToInt(BBSSwordIni.ReadString('Format','TabNumber','4'));
strEndChar := BBSSwordIni.ReadString('Format','EndChar','。?!…」”)');
strNotFirstChar := BBSSwordIni.ReadString('Format','NotFirstChar','。?!」”)');
strNotFirstLineChar := BBSSwordIni.ReadString('Format','NotFirstLineChar','。?!」”)、,');
strNotEndLineChar := BBSSwordIni.ReadString('Format','NotEndLineChar','“(');
intSpliteType := BBSSwordIni.ReadInteger('Format','SpliteType',Ord(stByVolume));
intEnglishType := BBSSwordIni.ReadInteger('Change','EnglishType',Ord(stEnglishNone));
intDoubleType := BBSSwordIni.ReadInteger('Change','DoubleType',Ord(stDoubleNone));
intAreaType := BBSSwordIni.ReadInteger('Change','AreaType',Ord(stAreaTotal));
intSaveTo := BBSSwordIni.ReadInteger('SaveTo','SaveTo',Ord(stLastDirectory));
strLastDirectory := BBSSwordIni.ReadString('SaveTo','LastDirectory','');
boolUseDefaultOpenDirectory := BBSSwordIni.ReadBool('SaveTo','bUseDefaultOpenDirectory',false);
strDefaultOpenDirectory := BBSSwordIni.ReadString('SaveTo','DefaultOpenDirectory','');
boolUseDefaultSaveDirectory := BBSSwordIni.ReadBool('SaveTo','bUseDefaultSaveDirectory',false);
strDefaultSaveDirectory := BBSSwordIni.ReadString('SaveTo','DefaultSaveDirectory','');
boolUseDefaultSaveHtmlDirectory := BBSSwordIni.ReadBool('SaveTo','bUseDefaultSaveHtmlDirectory',false);
strDefaultSaveHtmlDirectory := BBSSwordIni.ReadString('SaveTo','DefaultSaveHtmlDirectory','');
boolAllowOnlyOneApplication := BBSSwordIni.ReadBool('General','AllowOnlyOneApplication',true);
boolAlwaysOnTop := BBSSwordIni.ReadBool('General','AlwaysOnTop',false);
FontString := BBSSwordIni.ReadString('General','Font','宋体,134,9,,[clWindowText]');
try
StringToFont(FontString,aFont);
except
boolSelected := false;
while(not boolSelected) do
begin
ShowMessage('请先选择文本显示的缺省字体!');
if(FontDialog1.Execute) then
begin
aFont.Assign(FontDialog1.Font);
boolSelected := true;
end;
end;
end;
BBSSwordIni.Free;
end;
procedure TParameter.WriteParameter;
var
BBSSwordini:TIniFile;
begin
BBSSwordIni := TIniFile.Create(strINIFilePath);
BBSSwordIni.WriteBool('Windows','ShowChildrenList',boolShowChildrenList);
BBSSwordIni.WriteBool('Editor','WordWrap',boolWordWrap);
BBSSwordIni.WriteBool('Format','SkipBBSHead',boolSkipBBSHead);
BBSSwordIni.WriteBool('Format','ReplaceDouble',boolReplaceDouble);
BBSSwordIni.WriteBool('Format','DelTerminalBlank',boolDelTerminalBlank);
BBSSwordIni.WriteBool('Format','DelAllBlank',boolDelAllBlank);
BBSSwordIni.WriteBool('Format','DelDouble',boolDelDouble);
BBSSwordIni.WriteBool('Format','SpliteByexit',boolSpliteByReturn);
BBSSwordIni.WriteBool('Format','SpliteByChar',boolSpliteByChar);
BBSSwordIni.WriteBool('Format','ReplaceMultichar',boolReplaceMultichar);
BBSSwordIni.WriteBool('Format','ReplaceString',boolReplaceString);
BBSSwordIni.WriteBool('Format','ChangeBracket',boolChangeBracket);
BBSSwordIni.WriteBool('Format','FirstMiddle',boolFirstMiddle);
BBSSwordIni.WriteBool('Format','Addexit',boolAddReturn);
BBSSwordIni.WriteInteger('Format','LineLength',intLineLength);
BBSSwordIni.WriteInteger('Format','SkipNumber',intSkipNumber);
BBSSwordIni.WriteInteger('Format','TabNumber',intTabNumber);
BBSSwordIni.WriteString('Format','EndChar',strEndChar);
BBSSwordIni.WriteString('Format','NotFirstChar',strNotFirstChar);
BBSSwordIni.WriteString('Format','NotFirstLineChar',strNotFirstLineChar);
BBSSwordIni.WriteString('Format','NotEndLineChar',strNotEndLineChar);
BBSSwordIni.WriteInteger('Format','SpliteType',intSpliteType);
BBSSwordIni.WriteInteger('Change','EnglishType',intEnglishType);
BBSSwordIni.WriteInteger('Change','DoubleType',intDoubleType);
BBSSwordIni.WriteInteger('Change','AreaType',intAreaType);
BBSSwordIni.WriteInteger('SaveTo','SaveTo',intSaveTo);
BBSSwordIni.WriteString('SaveTo','LastDirectory',strLastDirectory);
BBSSwordIni.WriteBool('SaveTo','bUseDefaultOpenDirectory',boolUseDefaultOpenDirectory);
BBSSwordIni.WriteString('SaveTo','DefaultOpenDirectory',strDefaultOpenDirectory);
BBSSwordIni.WriteBool('SaveTo','bUseDefaultSaveDirectory',boolUseDefaultSaveDirectory);
BBSSwordIni.WriteString('SaveTo','DefaultSaveDirectory',strDefaultSaveDirectory);
BBSSwordIni.WriteBool('SaveTo','bUseDefaultSaveHtmlDirectory',boolUseDefaultSaveHtmlDirectory);
BBSSwordIni.WriteString('SaveTo','DefaultSaveHtmlDirectory',strDefaultSaveHtmlDirectory);
BBSSwordIni.WriteBool('General','AllowOnlyOneApplication',boolAllowOnlyOneApplication);
BBSSwordIni.WriteBool('General','AlwaysOnTop',boolAlwaysOnTop);
BBSSwordIni.WriteString('General','DragDropExt',strDragDropExt);
BBSSwordIni.WriteString('General','Font',FontToString(aFont));
BBSSwordIni.Free;
end;
end.