Delphi虚拟构造函数

时间:2017-07-10 11:18:17

标签: delphi delphi-10.2-tokyo

我正在阅读this文章,因为我想了解class of [ClassName]的用处,我看到他们声明了一个虚拟构造函数。所以我做了一个你可以在这里看到的测试:

enter image description here

我理解(从那篇文章中)当我在编译时不知道我想要构建的类并且我可以使用class of时,虚拟构造函数是有用的。在我上面显示的代码中,有什么区别?

如果我将TFirst构造函数声明为虚拟而不覆盖TSecond我会得到警告,当然广告我可以通过重新引入或覆盖来删除它。但是,构造函数是否自动被覆盖(查看左侧的代码)?我认为它们是等价的。

1 个答案:

答案 0 :(得分:4)

使用这两种变体执行此代码,您将看到差异。

public function update($table, $where = array(), $data_arr = array()){

    print_r($data_arr);

    $adapter = $this->tableGateway->getAdapter();

    $projectTable;

    if($table != null){
        $projectTable = new TableGateway($table, $adapter);
    }else{
        $projectTable = new TableGateway('account_master', $adapter);
    }
    echo "158";

    try {
        echo "123";
        $rowset = $projectTable->update(function(Update $update) use ($where, $data_arr) {

                $update->set(array('statement_no' => '01010'));

                $update->where($where);

            echo $update->getSqlString();
        });
    } catch (\Exception $e) {
            print_r($e);
    }

    print_r($rowset);
    die();
}
相关问题