首先把IniFiles加入到interface的uses里,这样才能使用Tinifile类,其他代码如下
implementation {$R *.dfm} var inifile: Tinifile; filepath: string; procedure TForm1.Button1Click(Sender: TObject); begin inifile.WriteString(‘Common‘, ‘PortNumber‘, Edit1.Text); inifile.WriteString(‘Common‘, ‘Brand‘, Edit2.Text); end; procedure TForm1.FormCreate(Sender: TObject); begin filepath := ExtractFilePath(Application.Exename) + ‘reg.ini‘;//取得ini文件的路径 inifile := Tinifile.Create(filepath); Edit1.Text := inifile.ReadString(‘Common‘, ‘PortNumber‘, ‘‘); Edit2.Text := inifile.ReadString(‘Common‘, ‘Brand‘, ‘‘); end;
时间: 2024-10-08 17:20:35