简体   繁体   English

TStringList名称-值对的特殊字符限制?

[英]Special Character restrictions for TStringList Name-Value Pairs?

I have a TStringList that is loaded with a few thousand Name-Value Pairs. 我有一个TStringList,其中装有数千个“名称/值”对。 One of them is 004001000002000=Timbre2 Volume 0~127 4995 其中之一是004001000002000=Timbre2 Volume 0~127 4995

I find a specific index by calling IndexOfName with the string '004001000002000'. 我通过使用字符串'004001000002000'调用IndexOfName查找特定的索引。 I expect ValueFromIndex to return the string 'Timbre2 Volume 0~127 4995' 我希望ValueFromIndex返回字符串'Timbre2 Volume 0〜127 4995'

Instead, when I access this value using the ValueFromIndex, it returns the string: 相反,当我使用ValueFromIndex访问此值时,它将返回字符串:

~127 4995

What causes this? 是什么原因造成的? Is Tilde a special character that causes the string to be truncated? Tilde是否是导致字符串被截断的特殊字符? Can I set it to something else? 我可以将它设置为其他吗?

I can't reproduce the problem using the following code in a TButton.OnClick event (Delphi 2007 and Delphi 7 - screen capture from Delphi 2007 test): 我无法在TButton.OnClick事件中使用以下代码来重现该问题(Delphi 2007和Delphi 7-Delphi 2007测试中的屏幕截图):

procedure TForm2.Button2Click(Sender: TObject);
var
  SL: TStringList;
  i: Integer;
begin
  SL := TStringList.Create;
  try
    SL.Add('004001000002000=Timbre2 Volume 0~127 4995');
    SL.Add('ABCDEF=Testing 1 2 3');
    i := SL.IndexOfName('004001000002000');
    if i > -1 then
      ShowMessage(SL.ValueFromIndex[i])
    else
      ShowMessage('IndexOfName returned -1');
  finally
    SL.Free;
  end;
end;

This correctly shows the expected dialog: 这将正确显示预期的对话框:

ShowMessage结果

I also tested using the simpler method: 我还使用更简单的方法进行了测试:

    ShowMessage(SL.Values['004001000002000']);

This displayed the identical ShowMessage dialog. 这显示了相同的ShowMessage对话框。

Tilde is not a special character to TStringList , unless you explicitally define it as one. Tilde不是TStringList的特殊字符,除非您明确将其定义为一个。

TStringList.IndexOfName() and TStringList.Name[Index] look only at what is in front of the first NameValueSeparator character, and TStringList.ValueFromIndex[Index] returns everything that is after the first NameValueSeparator character, the value is not truncated in any way. TStringList.IndexOfName()TStringList.Name[Index]仅查看第一个NameValueSeparator字符前面的内容, TStringList.ValueFromIndex[Index]返回第一个NameValueSeparator字符之后的所有内容,该值不会以任何方式被截断。 TStringList.NameValueSeparator is set to '=' by default. 默认情况下, TStringList.NameValueSeparator设置为'=' So if you are seeing truncation occuring, then either you are truncating it in your own code, or the TStringList contains a line that actually says '004001000002000=~127 4995' . 因此,如果您看到截断发生,那么您要么在自己的代码中截断它,要么TStringList包含一行实际显示为'004001000002000=~127 4995'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM