mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:5k
- unit mainunit;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls,IniFiles;
- type
- TForm1 = class(TForm)
- ComboBox1: TComboBox;
- Label1: TLabel;
- Memo1: TMemo;
- Button1: TButton;
- FontDialog1: TFontDialog;
- ColorDialog1: TColorDialog;
- Button2: TButton;
- Button3: TButton;
- Button4: TButton;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- private
- { Private declarations }
- public
- procedure RestoreLastSettings(FileName:String);
- procedure SaveFirstSettings(FileName:String);
- procedure SaveCurrentSettings;
- procedure LoadOtherSettings;
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- with FontDialog1 do
- begin
- if execute then
- begin
- Memo1.Font:=FontDialog1.Font;
- end;
- end;
- end;
- procedure TForm1.SaveCurrentSettings;
- var
- IniFile:TIniFile;
- FileName:String;
- SettingStr:String;
- Number:Integer;
- begin
- FileName:=ExtractFilePath(Application.ExeName)+'IniHandle.ini';
- IniFile:=TInifile.Create(FileName);
- if ComboBox1.ItemIndex=1 then
- begin
- SettingStr:='Settings1';
- Number:=2;
- end
- else
- begin
- SettingStr:='Settings2';
- Number:=1;
- end;
- try
- With IniFile do
- begin
- WriteInteger('ThemeNumber','Number',Number);
- WriteString(SettingStr,'FormColor',ColorToString(Form1.Color));
- WriteString(SettingStr,'Memo.Font.Color',ColorToString(Memo1.Font.Color));
- WriteInteger(SettingStr,'Memo.Font.Size',Memo1.Font.Size);
- WriteString(SettingStr,'Memo.Color',ColorToString(Memo1.Color));
- WriteString(SettingStr,'Memo.Font.Name',Memo1.Font.Name);
- end;
- finally
- IniFile.Free;
- end;
- end;
- procedure TForm1.LoadOtherSettings;
- var
- IniFile:TIniFile;
- Number:Integer;
- SettingStr:String;
- FileName:String;
- begin
- FileName:=ExtractFilePath(Application.ExeName)+'IniHandle.ini';
- IniFile:=TInifile.Create(FileName);
- try
- With IniFile do
- begin
- Number:=ComboBox1.ItemIndex+1;
- SettingStr:='Settings'+IntToStr(Number);
- Form1.Color:=StringToColor(ReadString(SettingStr,'FormColor','ClBtnFace'));
- Memo1.Color:=StringToColor(ReadString(SettingStr,'Memo.Color','ClBtnFace'));
- Memo1.Font.Color:=StringToColor(ReadString(SettingStr,'Memo.Font.Color','ClBtnFace'));
- Memo1.Font.Size:=ReadInteger(SettingStr,'Memo.Font.Size',0);
- Memo1.Font.Name:=ReadString(SettingStr,'Memo.Font.Name','System');
- end;
- finally
- IniFile.Free;
- end;
- end;
- procedure TForm1.RestoreLastSettings(FileName:String);
- var
- IniFile:TIniFile;
- Number:Integer;
- SettingStr:String;
- begin
- IniFile:=TInifile.Create(FileName);
- try
- With IniFile do
- begin
- Number:=ReadInteger('ThemeNumber','Number',1);
- ComboBox1.ItemIndex:=Number-1;
- SettingStr:='Settings'+IntToStr(Number);
- Form1.Color:=StringToColor(ReadString(SettingStr,'FormColor','ClBtnFace'));
- Memo1.Color:=StringToColor(ReadString(SettingStr,'Memo.Color','ClBtnFace'));
- Memo1.Font.Color:=StringToColor(ReadString(SettingStr,'Memo.Font.Color','ClBtnFace'));
- Memo1.Font.Size:=ReadInteger(SettingStr,'Memo.Font.Size',0);
- Memo1.Font.Name:=ReadString(SettingStr,'Memo.Font.Name','System');
- end;
- finally
- IniFile.Free;
- end;
- end;
- procedure TForm1.SaveFirstSettings(FileName:String);
- var
- IniFile:TIniFile;
- begin
- IniFile:=TInifile.Create(FileName);
- try
- With IniFile do
- begin
- WriteInteger('ThemeNumber','Number',1);
- WriteString('Settings1','FormColor',ColorToString(Form1.Color));
- WriteString('Settings1','Memo.Color',ColorToString(Memo1.Color));
- WriteString('Settings1','Memo.Font.Color',ColorToString(Memo1.Font.Color));
- WriteInteger('Settings1','Memo.Font.Size',Memo1.Font.Size);
- WriteString('Settings1','Memo.Font.Name',Memo1.Font.Name);
- WriteString('Settings2','FormColor',ColorToString(Form1.Color));
- WriteString('Settings2','Memo.Color',ColorToString(Memo1.Color));
- WriteString('Settings2','Memo.Font.Color',ColorToString(Memo1.Font.Color));
- WriteInteger('Settings2','Memo.Font.Size',Memo1.Font.Size);
- WriteString('Settings2','Memo.Font.Name',Memo1.Font.Name);
- end;
- finally
- IniFile.Free;
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- var
- FileName:String;
- begin
- FileName:=ExtractFilePath(Application.ExeName)+'IniHandle.ini';
- if FileExists(FileName) then
- begin
- RestoreLastSettings(FileName);
- end
- else
- begin
- SaveFirstSettings(FileName);
- end;
- end;
- procedure TForm1.ComboBox1Change(Sender: TObject);
- begin
- SaveCurrentSettings;
- LoadOtherSettings;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- with ColorDialog1 do
- begin
- if execute then
- begin
- Memo1.Color:=ColorDialog1.Color;
- end;
- end;
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- with ColorDialog1 do
- begin
- if execute then
- begin
- Form1.Color:=ColorDialog1.Color;
- end;
- end;
- end;
- end.