相关疑难解决方法(0)

编译器在将对象实例直接作为const接口参数传递时是否应该提示/警告?

在将对象的新实例传递给具有对象类实现的接口的const接口参数的方法时,编译器是否应该提示/警告?

编辑:当然样本很容易说明问题.但在现实生活中,它变得更加复杂:如果创建和使用在相隔很远的代码(不同的单元,不同的类,不同的项目)中会怎么样?如果由不同的人维护怎么办?如果非const参数变为常量参数,并且不能检查所有调用代码(因为更改代码的人无法访问所有调用代码),该怎么办?

下面的代码崩溃了,很难找到原因.

首先是日志:

1.Run begin

1.RunLeakCrash
 2.RunLeakCrash begin
     NewInstance 1
     AfterConstruction 0
   3.LeakCrash begin
     _AddRef 1
    4.Dump begin
    4.Dump Reference=10394576
    4.Dump end
     _Release 0
     _Release Destroy
     BeforeDestruction 0
   3.LeakCrash Reference got destroyed if it had a RefCount of 1 upon entry, so now it can be unsafe to access it
     _AddRef 1
    4.Dump begin
    4.Dump Reference=10394576
    4.Dump end
     _Release 0
     _Release Destroy
     BeforeDestruction 0
   3.LeakCrash end with exception

1.Run end
EInvalidPointer: Invalid pointer operation
Run Code Online (Sandbox Code Playgroud)

然后过早释放实现接口的对象实例的代码:

//{$define all} …
Run Code Online (Sandbox Code Playgroud)

delphi parameters const interface

17
推荐指数
2
解决办法
1134
查看次数

标签 统计

const ×1

delphi ×1

interface ×1

parameters ×1