什么是内部错误E5912

azr*_*l11 1 delphi delphi-7

我在这里问一个问题如何在OmniXML中创建简单的XML,我得到了Gavin Watkinson的答案.

我创建单位:

interface

uses
 OmniXML, OmniXMLProperties;

type
 TRow = class(TGpXMLData)
 public
  constructor Create(Node: IXMLNode); override;

  property Id: integer index 0 read GetXMLPropInt write SetXMLPropInt;
  property Name: WideString index 1 read GetXMLPropWide write SetXMLPropWide;
  property Surname: WideString index 2 read GetXMLPropWide write SetXMLPropWide;
  property Time: WideString index 3 read GetXMLPropWide write SetXMLPropWide;
  property Old: WideString index 4 read GetXMLPropWide write SetXMLPropWide;
  property Subject: WideString index 5 read GetXMLPropWide write SetXMLPropWide;
end;

TRows = class(TGpXMLList)
protected
  function GetRow(Value: integer): TRow;
public
  constructor Create(ParentNode: IXMLNode); reintroduce;

  function Add: TRow; reintroduce;

  property Rows[Value: integer]: TRow read GetRow; default;
end;

TRootsXml = class(TGpXmlDocList)
private
  fRows: TRows;
public
  constructor Create; reintroduce;
  destructor Destroy; override;

  property Ver: WideString index 0 read GetXMLAttrPropWide write SetXMLAttrPropWide;
  property RootFile: WideString index 1 read GetXMLAttrPropWide write SetXMLAttrPropWide;

  property Rows: TRows read fRows;
end;

implementation

constructor TRow.Create(Node: IXMLNode);
begin
  inherited;

  InitChildNodes(['id', 'name', 'surname', 'time', 'old', 'subjects'], 
                 ['', '', '', '', '', '']);
end;

constructor TRows.Create(parentNode: IXMLNode);
begin
  inherited Create(parentNode, '', 'row', TRow);
end;

function TRows.Add: TRow;
begin
  Result := TRow(inherited Add);
end;

function TRows.GetRow(Value: Integer): TRow;
begin
  Result := TRow(inherited Items[Value]);
end;

constructor TRootsXml.Create;
var
  xmlPI: IXMLProcessingInstruction;
begin
  inherited Create('Root', '', '', nil);

  xmlPI := XMLDoc.CreateProcessingInstruction('xml', 'version="1.0" encoding="utf-8"');
  XMLDoc.InsertBefore(xmlPI, node);

  InitChildNodes(['ver', 'file'], ['', '']);

  fRows := TRows.Create(node);
end; 

destructor TRootsXml.Destroy;
begin
  fRows.free;

  inherited;
end;
Run Code Online (Sandbox Code Playgroud)

当我尝试TRootsXml.ver = 'sat123';编译时,我得到了这个错误.'内部错误E5912'而不是编译......但我可以毫无问题地构建并运行它.

那么什么是错的,什么是内部错误E5912?

Rud*_*uis 6

内部错误是编译器或链接器中的内部错误.这一次,它看起来像编译器.该数字仅仅是实际编写编译器的人的指示.它的意思是没有记录,它实际上永远不会发生,换句话说,它是编译器中的一个错误.如果它发生了,你只能猜测它发生的地点或原因,并尝试修改你的代码直到它消失.这并不容易,而且令人沮丧,但这是你唯一能做的事情.

我假设这与代码使用索引属性与祖先类中定义的getter和setter这一事实有关.我猜你可以编写自己的getter和setter,并用给定的索引调用继承的getter.试试这个:

  TRootsXml = class(TGpXmlDocList)
  private
    fRows: TRows;
    function GetVer: WideString;
    procedure SetVer(const Value: WideString);
    function GetRootFile ... etc.. 
  public
    constructor Create; reintroduce;
    destructor Destroy; override;

    property Ver: WideString read GetVer write SetVer;
    property RootFile: WideString read GetRootFile write SetRootFile;
    property Rows: TRows read fRows;
  end;

function TRootsXml.GetVer: WideString;
begin
  Result := GetXMLAttrPropWide(0);
end;

procedure TRootsXml.SetVer(const Value: WideString);
begin
  SetXMLAttrPropWide(0, Value);
end;

// etc... similar code for GetRootFile and SetRootFile, but with index 1.
Run Code Online (Sandbox Code Playgroud)

不确定是否有效,因为我没有安装Delphi 7,但请尝试并报告发生的事情.

我想原始代码是用于更高版本的.这并没有解释内部错误(正如我所说,这些是编译器中的错误),但它解释了为什么它不能按预期编译,因为我假设代码已经过测试,但显然不是在Delphi 7中.