What is internal error E5912
I ask a question here How to create simple XML in OmniXML and I get an answer from Gavin Watkinson.
I create the unit:
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 GetXMLAtt开发者_JS百科rPropWide 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;
When I try to TRootsXml.ver = 'sat123';
and try to compile I get this error. 'Internal error E5912' and not compiling...
But I can build without problem and run it.
So what is wrong and what is internal error E5912?
Internal errors are, well, internal errors in the compiler or linker. This time, it looks like the compiler. The number is merely an indication to the people who actually wrote the compiler. What it means is not documented and it is something that should actually never happen, in other words, it is a bug in the compiler. If it happens, you can only guess where or why it happens and try to modify your code until it disappears. That is not easy, and can be frustrating, but it is the only thing you can do.
I assume it is related to the fact that the code uses indexed properties with getters and setters defined in an ancestor class. I guess you could write your own getters and setters and call the inherited getters with the given index. Try this:
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.
Not sure if that works, as I don't have Delphi 7 installed anymore, but please try it and report what happened.
I guess the original code was meant to be used in a higher version. That does not explain the internal error (as I said, these are bugs in the compiler), but it explains why it doesn't compile as expected, since I assume the code was tested, but apparently not in Delphi 7.
精彩评论