简体   繁体   English

链接程序消除了TDictionary上的GetItem

[英]GetItem on TDictionary eleminated by linker

I am using a TDictionary of <string, string> . 我正在使用<string, string>TDictionary But for some reason, the linker decides that I do not want to get items out of it. 但是由于某种原因,链接器决定我不想从中取出项目。

I have the following code: 我有以下代码:

function TSheet.GetFieldName(Field: string; Default: string): string;
begin
  Result := Default;
  if FFieldNames[Field] = '' then
    Result := Field
  else
    Result := FFieldNames[Field];
end;

FFieldNames is a TDictionary<string, string> . FFieldNamesTDictionary<string, string> On line 2 ( if FFieldNames[Field] = '' then ), it throws a 'File not found' exception. 在第2行( if FFieldNames[Field] = '' then ),它将引发“找不到文件”异常。 Adding FFieldNames[Field] to my watch tells me that Function to be called, {System.Generics.Collections}TDictionary.GetItem, was eliminated by linker . 在我的手表中添加FFieldNames[Field]告诉我, 链接器消除了要调用的函数{System.Generics.Collections} TDictionary.GetItem

Someone asked here on a similar issue on how to avoid the linker eliminating functions during debugging. 这里有人问过类似的问题 ,即如何避免链接器在调试期间消除功能。 From this I gathered, that the compiler/linker assumes that I am not using it. 从此我收集到,编译器/链接器假定我没有使用它。 Someone suggested - during conversation - that I should try using it more . 在谈话中有人建议我应该尝试更多使用它。

So I created the following code: 因此,我创建了以下代码:

FFieldNames.Add(Name, S);
V := FFieldNames.Items[Name];

Where S , Name and V are strings. 其中SNameV是字符串。 This is from the code where FFieldNames is filled with data. 这是从FFieldNames填充数据的代码中FFieldNames V 's only purpose is to obtain the just inserted S ; V的唯一目的是获得刚刚插入的S it does nothing else. 它什么也没做。

Strangely, while the debugger tells me the same thing (ie GetItem being eliminated), V does get set to the expected value. 奇怪的是,尽管调试器告诉我同样的事情(即,删除了GetItem ),但V确实设置为期望值。 But it does not in my TSheet.GetFieldName function. 但是它不在我的TSheet.GetFieldName函数中。 :| :|

What am I missing? 我想念什么?

The same problem applies to TList<> . 相同的问题适用于TList<> Even if the code is using a method in the class it is not accessible from the debugger ("xxx on TList eliminated by linker"). 即使代码在类中使用方法,也无法从调试器访问它(“链接器消除了TList上的xxx”)。 I guess this is a problem with generics in general. 我想这通常是泛型的问题。

If you make a descendent class it will not have this problem 如果您进行后代课程,则不会有此问题

type
  TMyList = class(TList<TMyObject>)

  end;

var
  List : TMyList;
begin
  ...

end;

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

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