我有一个函数,在其中存储了一些键值对,当我迭代它们时,我会两次收到这个错误:[dcc32 错误] App.pas(137): E2149 类没有默认属性。 以下是我的代码的一部分:
function BuildString: string;
var
i: Integer;
requestContent: TDictionary<string, string>;
request: TStringBuilder;
begin
requestContent := TDictionary<string, string>.Create();
try
// add some key-value pairs
request := TStringBuilder.Create;
try
for i := 0 to requestContent.Count - 1 do
begin
// here I get the errors
request.Append(requestContent.Keys[i] + '=' +
TIdURI.URLEncode(requestContent.Values[i]) + '&');
end;
Result := request.ToString;
Result := Result.Substring(0, Result.Length - 1); //remove the last '&'
finally
request.Free;
end;
finally
requestContent.Free;
end;
end;
我需要从字典中的每个项目收集信息。 我该怎么办?
for AKey in requestContent.Keys do begin request.Append(AKey + '=' + TIdURI.Encode(requestContent[AKey]) + '&'); ... etc.
。当然,你必须将AKey
声明为字符串。 - Rudy Velthuis