//列表框
//文本框
//编辑框
//组合框
//单选框
//检查框
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Button1: TButton; Button2: TButton; Memo1: TMemo; Button3: TButton; Button4: TButton; ComboBox1: TComboBox; Edit1: TEdit; CheckBox1: TCheckBox; CheckBox2: TCheckBox; RadioGroup1: TRadioGroup; ComboBox2: TComboBox; Button5: TButton; Button6: TButton; Button7: TButton; procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure ComboBox1Change(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses IniFiles; {$R *.dfm} var iniPath: string; //ini路径 fName: string; //ini的文件名 procedure ListBoxToINI( const AINIFile, ASection: string; ListBox: TListBox); var INI: TINIFile; I: Integer; begin INI := TINIFile.Create(AINIFile); try INI.EraseSection(ASection); INI.WriteInteger(ASection, 'Count', ListBox.Items.Count); for I := 0 to ListBox.Items.Count - 1 do begin INI.WriteString(ASection, 'Item' + IntToStr(I), ListBox.Items[I]); end; finally INI.Free; end; end; procedure INIToListBox( const AINIFile, ASection: string; ListBox: TListBox); var INI: TINIFile; I, Count: Integer; begin INI := TINIFile.Create(AINIFile); try Count := INI.ReadInteger(ASection, 'Count', 0); for I := 0 to Count - 1 do begin ListBox.Items.Add(INI.ReadString(ASection, 'Item' + IntToStr(I), '0')); end; finally INI.Free; end; end; procedure MemoToINI( const AINIFile, ASection: string; Memo: TMemo); var INI: TINIFile; I: Integer; begin INI := TINIFile.Create(AINIFile); try INI.EraseSection(ASection); INI.WriteInteger(ASection, 'Count', Memo.Lines.Count); for I := 0 to Memo.Lines.Count - 1 do begin INI.WriteString(ASection, 'Item' + IntToStr(I), Memo.Lines[I]); end; finally INI.Free; end; end; procedure INIToMemo( const AINIFile, ASection: string; Memo: TMemo); var INI: TINIFile; I, Count: Integer; begin INI := TINIFile.Create(AINIFile); try Count := INI.ReadInteger(ASection, 'Count', 0); for I := 0 to Count - 1 do begin Memo.Lines.Add(INI.ReadString(ASection, 'Item' + IntToStr(I), '0')); end; finally INI.Free; end; end; {write ini} procedure TForm1.Button1Click(Sender: TObject); begin fName :=ComboBox1.Text; iniPath :=GetCurrentDir() +format( '\%s.ini',[fName]); ListBoxToINI(iniPath, '列表框1',ListBox1); end; {read ini} procedure TForm1.Button2Click(Sender: TObject); begin fName :=ComboBox1.Text; iniPath :=GetCurrentDir() +format( '\%s.ini',[fName]); ListBox1.Clear; INIToListBox(iniPath, '列表框1',ListBox1); memo1.Text :=iniPath; end; procedure TForm1.Button3Click(Sender: TObject); begin ListBox1.Items :=memo1.Lines; end; procedure TForm1.Button4Click(Sender: TObject); begin listbox1.Clear; end; procedure TForm1.FormCreate(Sender: TObject); begin Button6.Click; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin ///角色名<>空 Button5.Click; end; procedure TForm1.Button5Click(Sender: TObject); var MyIniFile: TIniFile; begin INI// fName :=ComboBox1.Text; iniPath :=GetCurrentDir() +format( '\%s.ini',[fName]); MyIniFile := TIniFile.Create (iniPath); try MyIniFile.WriteInteger ( 'Settings', 'Top', form1.Top); MyIniFile.WriteInteger ( 'Settings', 'Left', form1.Left); MyIniFile.WriteString( 'Settings', 'Edit1', Edit1.text); MyIniFile.WriteString( 'Settings', 'ComboBox2', ComboBox2.text); MyIniFile.WriteBool( 'Settings', 'CheckBox1', CheckBox1.Checked); MyIniFile.WriteBool( 'Settings', 'CheckBox2', CheckBox2.Checked); MyIniFile.WriteInteger( 'Settings', 'RadioGroup1', RadioGroup1.ItemIndex); /ThisIsListBox ListBoxToINI(iniPath, '列表框1',ListBox1); MemoToINI(iniPath, '文本框',Memo1); /ThisIsListBox Finally MyIniFile.Free; end; INI// end; procedure TForm1.Button6Click(Sender: TObject); var MyIniFile: TIniFile; begin INI// fName :=ComboBox1.Text; iniPath :=GetCurrentDir() +format( '\%s.ini',[fName]); MyIniFile := TIniFile.Create(iniPath); try form1.Top := MyIniFile.ReadInteger( 'Settings', 'Top',form1.Top); form1.Left := MyIniFile.ReadInteger( 'Settings', 'Left',form1.Left); Edit1.text :=MyIniFile.ReadString( 'Settings', 'Edit1', Edit1.text); ComboBox2.text :=MyIniFile.ReadString( 'Settings', 'ComboBox2', ComboBox2.text); CheckBox1.Checked :=MyIniFile.ReadBool( 'Settings', 'CheckBox1', CheckBox1.Checked); CheckBox2.Checked :=MyIniFile.ReadBool( 'Settings', 'CheckBox2', CheckBox2.Checked); RadioGroup1.ItemIndex :=MyIniFile.ReadInteger( 'Settings', 'RadioGroup1', RadioGroup1.ItemIndex); /ThisIsListBox// ListBox1.Clear; INIToListBox(iniPath, '列表框1',ListBox1); Memo1.Clear; INIToMemo(iniPath, '文本框',Memo1); /ThisIsListBox// Finally MyIniFile.Free; end; INI// end; procedure TForm1.ComboBox1Change(Sender: TObject); begin //角色名改变后才读取 //角色名<>空 //角色的Hpmin<>0 if ComboBox1.Text <> '' then Button6.Click; end; end.
附件列表