Search code examples
classdelphiparametersdelphi-xe6

Parameter name conflict with class member


I have a parameter that its name is the same as a procedure within with/do scope. I realised it after hours of investigating, but now I'm looking for a solution better than just renaming my parameter.

Procedure Test(Param:TMyTape);
begin
    with TSomeClass.Create do
    try
        AClassFunc(Param);   // << There is a Param method inside TSomeClass
    finally
        free;
    end;
end;

There is Param method inside TSomeClass that makes the Param parameter useless. If the result type of that Param method is the same as Param parameter, then compiler don't even notice.

Q: Is it possible to refer to Param parameter to resolve this issue and don't needs to rename the Param

Another solution maybe declaring a variable for TSomeClass and don't using with/do clause. I' not looking for this too.


Solution

  • Is it possible to refer to Param parameter to resolve this issue and don't needs to rename the Param?

    Not if you are going to use with.

    Another solution maybe declaring a variable for TSomeClass and don't using with/do clause.

    This approach will work and is how I would write the code. There are only a very narrow set of scenarios where with is appropriate. This is not one of them.