how to safely bypass Delphi Error: “types of formal and actual parameters must be identical”

后端 未结 4 760
小鲜肉
小鲜肉 2020-12-10 07:02

I need a way to write a generic procedure to act upon an object type or any of its descendants.

My first attempt was to declare

procedure TotalDestro         


        
4条回答
  •  难免孤独
    2020-12-10 08:03

    In addition to what Lasse wrote, which is quite correct, most of the time you don't want to pass an object to a var parameter anyway.

    An object is a reference type. What you see as the object is actually a reference to it. You would only want to pass an object reference to a var parameter if you wanted to change your object out for a new object. If you just want to be able to modify the members of the object, then you can do that by simply passing it to a normal parameter. Make method call take a TMyObject parameter instead of a var TMyObject parameter and it should work.

    Of course, if you really are replacing the object, then feel free to disregard all this, and see Lasse's answer.

提交回复
热议问题