2012-02-24 75 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