链接程序消除了TDictionary上的GetItem [英] GetItem on TDictionary eleminated by linker

查看:89
本文介绍了链接程序消除了TDictionary上的GetItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用<string, string>TDictionary.但是由于某种原因,链接器决定我不想从中取出项目.

I am using a TDictionary of <string, string>. But for some reason, the linker decides that I do not want to get items out of it.

我有以下代码:

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

FFieldNamesTDictionary<string, string>.在第2行(if FFieldNames[Field] = '' then)上,它引发找不到文件"异常.在手表中添加FFieldNames[Field]告诉我,链接器消除了要调用的函数{System.Generics.Collections} TDictionary.GetItem .

FFieldNames is a TDictionary<string, string>. On line 2 (if FFieldNames[Field] = '' then), it throws a 'File not found' exception. Adding FFieldNames[Field] to my watch tells me that Function to be called, {System.Generics.Collections}TDictionary.GetItem, was eliminated by linker.

某人在这里问了类似的问题,该问题是如何避免链接器在调试期间消除功能的.从此我收集到,编译器/链接器假定我没有使用它.有人建议-在对话期间-我应该尝试使用它更多.

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];

其中SNameV是字符串.这是从FFieldNames充满数据的代码中得出的. V的唯一目的是获取刚刚插入的S;它什么也没做.

Where S, Name and V are strings. This is from the code where FFieldNames is filled with data. V's only purpose is to obtain the just inserted S; it does nothing else.

奇怪的是,尽管调试器告诉我同样的事情(即,取消了GetItem),但V确实设置为期望值.但是它不在我的TSheet.GetFieldName函数中. :|

Strangely, while the debugger tells me the same thing (i.e. GetItem being eliminated), V does get set to the expected value. But it does not in my TSheet.GetFieldName function. :|

我想念什么?

推荐答案

相同的问题适用于TList<>.即使代码在类中使用方法,也无法从调试器访问它(链接器消除了TList上的xxx").我想这通常是泛型的问题.

The same problem applies to 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"). 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;

这篇关于链接程序消除了TDictionary上的GetItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆