如何重写TIniFile.Create构造函数?
此代码不起作用,因为Create是静态的:
TMyIniFile = class(TIniFile)
protected
public
constructor Create (CONST AppName: string); override; <------ Error 'Cannot override a non-virtual method'
end;发布于 2012-02-25 04:09:56
不能重写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);https://stackoverflow.com/questions/9437300
复制相似问题