I have a base class declared as
type TBaseClass=class protected constructor Create(LoadData:boolean;const Param1,Param2:string); overload; public Destructor Destroy; override; end;
Now in another module, the child class TChid_Class , which descends from TBaseClass
TChid_Class=class(TBaseClass) function Create(const Param1, Param2 : String;const Param3 : OleVariant ; var Param4 : LongInt): Integer;overload; constructor Create; overload; constructor Create(LoadData:boolean); overload; end;
there is a function in this class called Create as constructors, the problem is that when I try to create an instance for TChid_Class , I have an access violation.
I wrote this little console application that shows the problem
program TestClass; {$APPTYPE CONSOLE} uses Variants, SysUtils; type TBaseClass=class protected constructor Create(LoadData:boolean;const Param1,Param2:string); overload; public Destructor Destroy; override; end; TChid_Class=class(TBaseClass) function Create(const Param1, Param2 : String;const Param3 : OleVariant ; var Param4 : LongInt): Integer;overload; constructor Create; overload; constructor Create(LoadData:boolean); overload; end; { TBaseClass } constructor TBaseClass.Create(LoadData: boolean; const Param1, Param2: string); begin inherited Create; Writeln('constructor TBaseClass.Create(LoadData: boolean; const Param1, Param2: string);'); end; destructor TBaseClass.Destroy; begin //Code inherited; end; { TChid_Class } function TChid_Class.Create(const Param1, Param2: String; const Param3: OleVariant; var Param4: Integer): Integer; begin Writeln('function create'); Result:=0; end; constructor TChid_Class.Create; begin Writeln('constructor TChid_Class.Create'); Create(True); end; constructor TChid_Class.Create(LoadData: boolean); begin Writeln('constructor TChid_Class.Create(LoadData: boolean)'); //here is the access violation Create(LoadData,'Value 1','Value 2'); end; var Invoker : TChid_Class; Pid : integer; begin try Invoker:=TChid_Class.Create; try Invoker.Create('','',Unassigned,Pid) finally Invoker.Free; end; except on E:Exception do Writeln(E.Classname, ': ', E.Message); end; readln; end.
If I rename the create function, the problem will disappear, but I am looking for a solution without renaming the create function or constructors.
using delphi 2007
Thanks in advance.