gpt4 book ai didi

delphi - 如何覆盖 TIniFile.Create?

转载 作者:行者123 更新时间:2023-12-01 23:56:31 26 4
gpt4 key购买 nike

如何重写 TIniFile.Create 构造函数?

此代码不起作用,因为 Create 是静态的:

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

最佳答案

您无法重写 TIniFile 的构造函数,因为它不是虚拟的。 ini 文件类不使用虚拟构造函数。

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

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);

关于delphi - 如何覆盖 TIniFile.Create?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9437300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com