delphi 中的不安全强制转换有时仅在某些机器上给出 nil?
我们有一些类似这样的代码(Delphi 6 RTL Update Pack 3):
objChild1 := TChild1.create();
... (Some Code)
objProcessor.function1(objChild1);
Tchild1 通过 2 + 层次结构级别从 TGrandPa 继承。
function1 的定义如下,其中 objChildData 是 TProcessor 类的私有变量,类型为 TChild1 :
TProcessor.function1(objTemp : TGrandPa):boolean;
begin
objChildData := TChild1(objTemp);
....
end;
从日志中(因为我们无法在客户计算机上调试),我们已经缩小了 function1 中的第一行使 objChildData nil 的范围有时并且仅在某一特定客户的机器上。部署相同代码的其他地方似乎工作得很好。
谁能解释一下为什么会发生这种情况和/或如何解决这个问题?
We have some code something like this (Delphi 6 RTL Update Pack 3):
objChild1 := TChild1.create();
... (Some Code)
objProcessor.function1(objChild1);
Tchild1 is inherited from TGrandPa through 2 + hierarchy levels.
function1 is defined like this where objChildData is a private variable of TProcessor class and is of type TChild1 :
TProcessor.function1(objTemp : TGrandPa):boolean;
begin
objChildData := TChild1(objTemp);
....
end;
From the logs (since we can't debug on a customer machine), we have narrowed down that the first line in the function1 makes objChildData nil sometimes and only on one particular customer's machines. Rest of the places where same code is deployed seems to be working perfectly fine.
Can anyone throw some light on why this is happening and/or how to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎您正在 ObjChild.Create 上执行某些操作,该操作会抛出异常并由于某种原因被吞没(尝试..除了 except 子句为空) - 当发生这种情况时,Create 无法返回有效实例,返回 NIL 相反。它可以是构造函数内部调用的函数。
如果您将在 TObjChild.Create 上所做的操作带到网站上,也许我们可以发现问题。
Seems you are doing something on the ObjChild.Create that throws an exception and that is swallowed (try..except where the except clause is empty) for some reason - when that happens, Create cannot return a valid instance, returning
NIL
instead. It can be an function called inside the constructor.If you bring what you do on the TObjChild.Create to the site, maybe we can spot the problem.
您可以使用远程调试器(从 Delphi 3 或 4 开始可用)来调试在客户计算机上运行的代码。
不管怎样,通过日志你怎么确定 objTemp 参数不为零?
You are able to debug the code running on a customer machine using Remote Debugger (available since Delphi 3 or 4).
Anyway, by the logs how are you sure objTemp parameter is not nil?