Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 将多个数据类型读入列表_Delphi_Delphi Xe2_Ini - Fatal编程技术网

Delphi 将多个数据类型读入列表

Delphi 将多个数据类型读入列表,delphi,delphi-xe2,ini,Delphi,Delphi Xe2,Ini,标题可能会在问题发布后更新,但我从一个.ini文件开始,我想将整数、字符串、Bool保存到这个.ini文件中。我可以用它 WriteString WriteInteger WriteBool 然后我想把它读入一个列表,当我从列表中提取数据时,它会知道它已经准备好了,是整数、字符串还是布尔 目前,我必须将所有内容写入字符串,然后将其读入字符串列表 如前所述,您可以将所有数据读取为字符串。您可以使用以下函数来确定数据类型: type TDataType = (dtString, dtBoole

标题可能会在问题发布后更新,但我从一个.ini文件开始,我想将整数、字符串、Bool保存到这个.ini文件中。我可以用它

WriteString
WriteInteger
WriteBool
然后我想把它读入一个列表,当我从列表中提取数据时,它会知道它已经准备好了,是整数、字符串还是布尔


目前,我必须将所有内容写入字符串,然后将其读入字符串列表

如前所述,您可以将所有数据读取为字符串。您可以使用以下函数来确定数据类型:

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;

将所有设置读取为ReadString:)目前,我已经准备好知道从stringlist中提取的数据值是int、string还是bool。我只想停止执行strotint(stringlist中的值)和StrToBool(stringlist中的值),那么我可以在stringlist中分配数据类型吗?或任何列表类型。很抱歉,如果我没有正确解释第一次更新的答案以包含数据类型。请阅读关于Variant和TValue等类型的隐式自动转换