如何在 Delphi 中将MDB内容写入INI文件?

ttvkxqim  于 2023-03-01  发布在  其他
关注(0)|答案(1)|浏览(166)

mdb有一个表项,表有18列10行,我想把表的内容写在ini文件里,有办法吗?

procedure TForm1.Button4Click(Sender: TObject);
var
  ini : TIniFile;
  i : Integer;
  sTableInfo : String;

begin

  Adotable1.First;
  ini := TIniFile.Create('C:\Users\win10_pro\Desktop\test.ini');
  sTableInfo := Adotable1['name'] + '  '  +Adotable1['capital']+ '  ' +   Adotable1['continent'];
  
  try
  for i := 0 to adotable1.RecordCount - 1 do
     begin
        ini.WriteString('Name', 'test1', sTableInfo );
      end;
        ShowMessage('INI file create');
      end;
  finally
    ini.Free;
  end;

这样,只放入一个项目,而我希望放入所有项目。这样,只放入一个项目,而我希望放入所有项目。

46scxncf

46scxncf1#

我不知道你为什么要这样做,因为你有一个完美的数据库,已经存储了数据。但是,这应该做你想要的(未经测试)。注意,我还必须改变写入INI文件的代码,使键随着每一次传递而改变,或者只写入一个值。

procedure TForm1.Button4Click(Sender: TObject);
var
  ini : TIniFile;
  keyNo: Integer;
  sTableInfo : String;
begin
  Adotable1.First;
  ini := TIniFile.Create('C:\Users\win10_pro\Desktop\test.ini');
  keyNo := 1;
  try
     while not adotable1.Eof do
     begin
       sTableInfo := Adotable1['name'] + '  '  +Adotable1['capital']+ '  ' +   Adotable1['continent'];

       ini.WriteString('Name', 'test' + IntToStr(keyNo), sTableInfo );
       Inc(keyNo);
       adoTable1.Next;
     end;
     ShowMessage('INI file created');
  finally
    ini.Free;
  end;
end;

相关问题