I have a code with overloaded functions, one of them is class method, the other one is object method. Works fine under XE7, tried to implement the same code under D7, getting a compiler error, have no clue why.
[Error] testform.pas(23): Ambiguous overloaded call to 'OpenForm'**
unit testform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Contnrs;
type
TFrmBase = class(TForm)
public
class function Test: TModalResult; overload;
class function OpenForm(AParamNames: array of string; AParamValues: array of Variant): TModalResult; overload;
function OpenForm(AClassName: String; AParamNames: array of string; AParamValues: array of Variant): TModalResult; overload;
end;
implementation
{$R *.dfm}
class function TFrmBase.Test: TModalResult;
begin
// here comes the error, tried without "TFrmBase.", same result
Result := TFrmBase.OpenForm([], []);
end;
class function TFrmBase.OpenForm(AParamNames: array of string; AParamValues: array of Variant): TModalResult;
begin
// do nothing
end;
function TFrmBase.OpenForm(AClassName: String; AParamNames: array of string; AParamValues: array of Variant): TModalResult;
begin
// do nothing
end;
end.
Strangely (for me at least) if I remove the AParamValues: array of Variant
code, it can be compiled just fine.
Why is this one not working under D7? What should I fix here? Probably I am missing something obvious.
CodePudding user response:
I think you need to make your code like the following
class function TFrmBase.Test: TModalResult;
var
StrArr : array of string;
VarArr : array of Variant;
begin
//Fill your arrays here
Result := TFrmBase.OpenForm(StrArr, VarArr);
end;