Delphi 自定义TXmlIniFile方法创建错误

Delphi 自定义TXmlIniFile方法创建错误,delphi,delphi-xe7,Delphi,Delphi Xe7,我创建了这个单元,其中包含一个从TXmlIniFile派生的类: unit PAXMLIniFile; interface uses System.SysUtils, System.IniFiles, Xml.XmlDoc, Xml.XMLIntf, Xml.XMLIniFile; type TMyStandaloneXmlIniFile = class(TXmlIniFile) strict private FDocument: IXMLDocumen

我创建了这个单元,其中包含一个从TXmlIniFile派生的类:

unit PAXMLIniFile;

interface

uses
  System.SysUtils,
  System.IniFiles,
  Xml.XmlDoc,
  Xml.XMLIntf,
  Xml.XMLIniFile;

type
  TMyStandaloneXmlIniFile = class(TXmlIniFile)
  strict private
    FDocument: IXMLDocument;
    FFileName: string;
  public
    constructor Create(const AFileName: string);
    procedure UpdateFile; override;
  end;

implementation

constructor TMyStandaloneXmlIniFile.Create(const AFileName: string);
begin
  if FileExists(AFileName) then
    FDocument := LoadXMLDocument(AFileName)
  else
  begin
    FDocument := NewXMLDocument;
    FDocument.Options := FDocument.Options + [doNodeAutoIndent];
  end;
  if FDocument.DocumentElement = nil then
    FDocument.DocumentElement := FDocument.CreateNode('Sections');
  TCustomIniFile(Self).Create(AFileName); 
  FFileName := AFileName;
  inherited Create(FDocument.DocumentElement);
end;

procedure TMyStandaloneXmlIniFile.UpdateFile;
begin
  FDocument.SaveToFile(FFileName);
end;

end.
现在,每当我调用UpdateFile方法时,我都会收到一条错误消息“错误的参数”。这里怎么了

以下是测试程序:

program BonkersTest;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, PAXMLIniFile, Winapi.ActiveX;

var
  MyStandaloneXmlIniFile: TMyStandaloneXmlIniFile;
  MyXmlFile: string;

begin
  try
    CoInitialize(nil);
    MyXmlFile := ChangeFileExt(ParamStr(0), '.xml');
    MyStandaloneXmlIniFile := TMyStandaloneXmlIniFile.Create(MyXmlFile);
    try
      MyStandaloneXmlIniFile.WriteString('Section1', 'Ident1', 'Value1');
      MyStandaloneXmlIniFile.UpdateFile;
    finally
      MyStandaloneXmlIniFile.Free;
    end;
    CoUninitialize;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

TCustomIniFile(Self)。创建(AFileName)
Er,什么?!!接着是继承的创建?!我完全不知道它试图实现什么,它应该使用常见的TCustomInifile方法来创建和读取XML文件。试试看。它来自《Delphi XE2基础》一书中的一个想法。创建(AFileName)肯定是胡说八道。这是你的主意,还是克里斯的?不管怎样,我不打算深入挖掘,因为这里没有一个完整的程序。你很容易加上这个,但我不得不猜测。我们以前一定做过,这是克里斯的主意。你试过了吗?我看它简直疯了。当然容易受到实施变化的影响。我没有试过,因为我没有一个程序可以运行。你没有提供。