简体   繁体   English

有时在delphi中进行不安全的转换只会在某些机器上没有显示?

[英]Unsafe cast in delphi sometimes gives a nil only on certain machines?

We have some code something like this (Delphi 6 RTL Update Pack 3): 我们有一些类似以下的代码(Delphi 6 RTL Update Pack 3):

objChild1 := TChild1.create();
... (Some Code)
objProcessor.function1(objChild1);

Tchild1 is inherited from TGrandPa through 2 + hierarchy levels. Tchild1通过2 +层次结构级别从TGrandPa继承。

function1 is defined like this where objChildData is a private variable of TProcessor class and is of type TChild1 : 像这样定义function1,其中objChildData是TProcessor类的私有变量,类型为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. 从日志中(因为我们无法在客户计算机上进行调试),我们缩小了范围,即function1中的第一行有时使objChildData为零,并且仅在一个特定客户的计算机上为零。 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? 任何人都可以对为什么发生这种情况和/或如何解决这一问题有所了解吗?

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. 似乎您在ObjChild.Create上正在执行某些操作,该操作会引发异常并且由于某种原因而被吞下(try..except,其中except子句为空)-发生这种情况时,Create无法返回有效实例,而是返回NIL 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. 如果您将您在TObjChild.Create上所做的工作带到该站点,也许我们可以发现问题。

You are able to debug the code running on a customer machine using Remote Debugger (available since Delphi 3 or 4). 您可以使用远程调试器(自Delphi 3或4开始提供)调试在客户计算机上运行的代码。

Anyway, by the logs how are you sure objTemp parameter is not nil? 无论如何,通过日志如何确定objTemp参数不为nil?

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

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