http://files.cnblogs.com/xe2011/StringToColor.rar
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses IniFiles; procedure TForm1.Button1Click(Sender: TObject); begin Caption := ExtractFilePath(Application.ExeName); end; procedure TForm1.Button2Click(Sender: TObject); begin Color := StringToColor('clRed'); end; procedure SaveConfig(fileName: string; Form: TForm); var f:string; begin f:=ExtractFilePath(Application.ExeName) + fileName; with TIniFile.Create( f ) do begin WriteString('MainForm', 'Color', ColorToString(Form.Color)); end; end; procedure LoadConfig(fileName: string; Form: TForm); var s:string; f:string; begin f:=ExtractFilePath(Application.ExeName) + fileName; with TIniFile.Create(f) do begin s:= ReadString('MainForm', 'Color', 'clBtnFace'); Form.Color := StringToColor(s); end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin SaveConfig('Config.ini',Form1); end; procedure TForm1.FormCreate(Sender: TObject); begin LoadConfig('Config.ini',Form1); end; end.