2012-02-24 74 views
2

如何覆盖TIniFile.Create构造函数?如何覆盖TIniFile.Create?

这个代码不工作,因为创建是静态的:

TMyIniFile = class(TIniFile) 
    protected 
    public 
    constructor Create (CONST AppName: string); override; <------ Error 'Cannot override a non-virtual method' 
    end; 

回答

6

不能覆盖的TIniFile的构造,因为它不是虚拟的。 ini文件类不使用虚拟构造函数。

您只需从代码中删除override即可。

TMyIniFile = class(TIniFile) 
public 
    constructor Create(const AppName: string); 
end; 

这样实现:

constructor TMyIniFile.Create(const AppName: string); 
begin 
    inherited Create(FileName);//I can't tell what you need as FileName 
    FAppName := AppName; 
end; 

当你需要创建一个你这样做是这样的:

MyIniFile := TMyIniFile.Create(MyAppName); 
+2

这正是'TMemIniFile'一样。 – 2012-02-24 20:13:18