Hej
Robie klase ktora dziedziczy po TXmlDocument - ma za zadanie dodanie kilku dodatkowych funkcjonalnosci ktorych brakuje temu komponentowi.
Jedna z metod jest weryfikacja podanego przez uzytkownika XML - czy jest poprawny. I tu pojawia sie problem.
Kiedy robie self.ChildNodes.Count (w klasie wydziedziczonej z TXmlDocument) delphi zglasza mi EAbstractError :(
Klasa wyglada mniej wiecej tak
unit CustomXmlDocumentSrc;
interface
uses SysUtils, xmldom, XMLIntf, msxmldom, XMLDoc;
type
TCustomXmlDocument = class( TXmlDocument )
private
function WeryfikujXml(): boolean;
public
constructor Create();
procedure AfterConstruction; override;
procedure SetXml( const AXml: WideString );
end;
implementation
procedure TCustomXmlDocument.SetXml( const AXml: WideString );
begin
// jesli XML jest pusty to blad
if( Length( AXml ) = 0 ) then
begin
raise EDOMParseError.Create( self.DOMDocument as IDOMParseError,
'Niepoprawny XML' );
Exit;
end;
// jesli nowa wartosc jest rozna od starej
if( self.XML.Text = AXml ) then
begin
Exit;
end;
// to zachowujemy nowa wartosc
self.XML.Text := AXml;
self.Active := true;
if( not WeryfikujXml() ) then
begin
raise EDOMParseError.Create( self.DOMDocument as IDOMParseError,
'Niepoprawny XML' );
Exit;
end;
end;
// Metoda weryfikuje poprawnosc XMLa
function TCustomXmlDocument.WeryfikujXml: boolean;
begin
// domyslnie XML OK
Result := true;
// jesli XML nie ma zadnych wezlow to koniec
if( self.ChildNodes.Count = 0 ) then
begin
Result := false;
Exit;
end;
// jesli glowny wezel dokumentu nie ma dzieci to koniec
if( not self.DocumentElement.HasChildNodes ) then
// ^ w tej lini jest zglaszany wyjatek ^
begin
Result := false;
Exit;
end;
end;
// Konstruktor klasy
constructor TCustomXmlDocument.Create();
begin
inherited Create( nil );
end;
procedure TCustomXmlDocument.AfterConstruction;
begin
inherited;
self.Options := self.Options + [ doNodeAutoIndent ];
end;
end.
Co dziwne gdy w debugerze patrze sobie krok po kroku co sie dzieje i najade pierwszy raz myszka na self.ChildNodes.Count pokazuje mi ilosc wezlow - gdy najade drugi raz juz mi wyskakuje EAbstractError
Moze ktos z Was wpadnie na to co jest zle.
pozdrawiam
Mateusz [PEYN] Adamus
http://adamus.home.pl