unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
type TOptData =
record
OptName:
string;
OptValue:
string;
end;
type TOptDataArray =
array of TOptData;
function GetOptionsFromIni: TOptDataArray;
function GetOptValue(OptData: TOptDataArray; OptName:
string):
string;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetOptionsFromIni: TOptDataArray;
var
MyIni: TIniFile;
i: Integer;
OptionNames: TStringList;
OptionValues:
array of string;
OptionData: TOptDataArray;
begin
MyIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) + '
options.ini');
try
OptionNames := TStringList.Create;
try
MyIni.ReadSection('
option', OptionNames);
SetLength(OptionData, OptionNames.Count);
for i := 0
to OptionNames.Count - 1
do
begin
OptionData[i].OptName := OptionNames[i];
OptionData[i].OptValue := MyIni.ReadString('
option', OptionNames[i], '
');
end;
finally
FreeAndNil(OptionNames);
end;
finally
FreeAndNil(MyIni);
end;
Result := OptionData;
end;
function TForm1.GetOptValue(OptData: TOptDataArray; OptName:
string):
string;
var
i: Integer;
begin
Result := '
';
for i := Low(OptData)
to High(OptData)
do
begin
if OptData[i].OptName = OptName
then
begin
Result := OptData[i].OptValue;
break;
end;
end;
end;
// Beispielaufruf
procedure TForm1.Button1Click(Sender: TObject);
var
OptionValues: TOptDataArray;
begin
OptionValues := GetOptionsFromIni;
ShowMessage(GetOptValue(OptionValues, '
options_1'));
ShowMessage(GetOptValue(OptionValues, '
options_4'));
end;
end.