0

質問が投稿されるとタイトルが更新される可能性がありますが、整数、文字列、ブール値をこの.iniファイルに保存したい.iniファイルから始めます。私ができること

WriteString
WriteInteger
WriteBool

次に、それをリストに読み込みたいのですが、リストからデータを取得すると、整数、文字列、またはブール値の準備ができていることがわかりますか?

現在、すべてを文字列として書き込む必要があり、次に文字列リストに読み込みます。

4

1 に答える 1

2

前述のように、すべてのデータを文字列として読み取ることができます。また、次の関数を使用してデータ型を判別できます。

type
  TDataType = (dtString, dtBoolean, dtInteger);

function GetDatatype(const AValue: string): TDataType;
var
  temp : Integer;
begin
  if TryStrToInt(AValue, temp) then
    Result := dtInteger   
  else if (Uppercase(AValue) = 'TRUE') or (Uppercase(AValue) = 'FALSE') then
    Result := dtBoolean
  else
    Result := dtString;
end;


You can (ab)use the object property of the stringlist to store the datatype:


procedure TMyObject.AddInteger(const AValue: Integer);
begin
  List.AddObject(IntToStr(AValue), TObject(dtInteger));
end;

procedure TMyObject.AddBoolean(const AValue: Boolean);
begin
  List.AddObject(BoolToStr(AValue), TObject(dtBoolean));
end;

procedure TMyObject.AddString(const AValue: String);
begin
  List.AddObject(AValue, TObject(dtString));

end; 

function TMyObject.GetDataType(const AIndex: Integer): TDataType;
begin
  Result := TDataType(List.Objects[AIndex]);
end;
于 2012-07-21T15:50:42.610 に答える