【发布时间】:2016-04-19 14:22:52
【问题描述】:
我使用 Delphi XE7。有没有办法将 .ini 文件中的所有值加载到不同列的字符串网格中?
我的 .ini 文件看起来像
[1038] 值 = a1 B值 = b1 C值 = c1 D值 = d1 [1031] A值 = a2 B值 = b2 C值 = c2 D值 = d2我使用这个程序来填充网格:
procedure TForm1.ReadIntoGrid(const aIniFileName, aSection: string;
const aGrid: TStringGrid);
var
Ini: TIniFile;
SL: TStringList;
i: Integer;
begin
SL := TStringList.Create;
try
Ini := TIniFile.Create(aIniFileName);
try
aGrid.ColCount := 2;
Ini.ReadSectionValues(aSection, SL);
aGrid.RowCount := SL.Count;
for i := 0 to SL.Count - 1 do
begin
aGrid.Cells[0,i] := SL.Names[i];
aGrid.Cells[1,i] := SL.ValueFromIndex[i];
end;
finally
Ini.Free;
end;
finally
SL.Free;
end;
end;
效果很好,我明白了:
我的问题是……
如何将所有部分值(1038 和 1031)读入 1038 值旁边的网格中?值将始终固定。
【问题讨论】:
-
这个任务的哪一部分你觉得困难。从表面上看,您似乎知道如何读取 INI 文件,以及如何使用字符串网格。看来您拥有所需的一切。
-
我必须同意大卫的观点。唯一棘手的部分似乎是将不同部分的项目名称同步到字符串网格中。
标签: delphi delphi-xe delphi-xe7