のを使用しようとすると、常にアクセス違反が発生しDocumentElement
ますXMLDocument
。XMLDocument
なんらかのファイルの存在に基づいて作成します。
エラーメッセージ
プロジェクトproject1.exeは、メッセージ「モジュール'project1.exe'のアドレス0047B152でのアクセス違反」で例外クラスEAccessViolationを発生させました。アドレスB1D59357の読み取り'
私のコード
unit XMLBase;
interface
uses
SysUtils, xmldom, XMLIntf, XMLDoc, Forms;
type
TXMLbase = class
private
{ Private declarations }
public
XMLDocument1: TXMLDocument;
root: IXMLNode;
constructor Create;
end;
var
fn: string;
implementation
constructor TXMLbase.Create;
begin
fn := ChangeFileExt(Application.ExeName, '.xml');
XMLDocument1 := TXMLDocument.Create(nil);
XMLDocument1.Options := [doNodeAutoIndent];
XMLDocument1.Active := False;
//optional, is used to indent the Xml document
if FileExists(fn) then
begin
XMLDocument1.LoadFromFile(fn);
XMLDocument1.Active:= True;
root := XMLDocument1.DocumentElement; //<<--- Access Voilation
end
else
begin
XMLDocument1.Active := False;
XMLDocument1.XML.Text := '';
XMLDocument1.Active := True;
root := XMLDocument1.AddChild('Settings');
end;
XMLDocument1.SaveToFile(fn);
end;
end.
オブジェクトまたはポインタの不適切な初期化が原因でアクセス違反が発生しXMLDocument
ます。これは、が初期化されていないことを意味しますか?