I have a Base Class that needs a Prameter like Filename. This Parameter is needed for the Create Call of the TMemIniFile Class.
Whats the correct Way to call the Class function of the current Classtype inside the Base Class Constructor?
TBaseClassClass = Class of TBaseClass;
TBaseClass = class(TMemIniFile)
protected
class function FileName: string; virtual; abstract;
public
// Current Solution
constructor Create(ClassToCreate: TBaseClassClass); reintroduce;
// wanted Solution
constructor Create; reintroduce;
end;
TImplementation = Class(TBaseClass)
protected
class function FileName: string; override;
end;
// Current Solution
constructor TBaseClass.Create(ClassToCreate: TBaseClassClass);
begin
inherited Create(ClassToCreate.FileName, Encoding.UTF8);
end;
// Wanted Solution
constructor TBaseClass.Create;
begin
inherited Create(FileName, Encoding.UTF8); // This call to FileName has a Abstract Error because its calling Filename from TBaseClass. But how to solve this elegant?
end;
//Trying to Clarify: Usage:
myWorkingIniFile: TImplementation.Create; //Filename is defined in Class and the FileName value is used in the Constructor ...
Can i somehow "dynamically" Typecast inside the Constructor? I have seen the use of RTTI with a call of the function name. But i think there should be another Way. Or am i doing it fundamentally wrong?