mdbs99 / james

James is a collection of object-oriented Pascal primitives for Lazarus and Delphi
MIT License
53 stars 20 forks source link

Create a secure TXMLComponent without NULL #5

Closed mdbs99 closed 7 years ago

mdbs99 commented 7 years ago

It TXMLComponent class works with default XML libs in FPC/Lazarus. It creates a TXMLDocument. Sometimes (many times) its methods like FindNode, ChildNodes, or Item find nothing and the code receives a NULL. The NULL is a anti-pattern as I already said here.

Is it possible creates decorators for these objects (TDOMNode, for exemple)?

mdbs99 commented 7 years ago

I've renamed some classes and forgot to change these names in template.xml. Because that I got an Access Violation (AV).

Look the code:

Node :=
      Template
        .Document
        .DocumentElement
        .FindNode(Self.ClassName)
        .FindNode('files')
        .ChildNodes
        .Item[0];

If FindNode(Self.ClassName) returns NULL we will get an AV. So, is very important to throw away all NULL from our softwares.

mdbs99 commented 7 years ago

The TXMLComponent class doesn't exist anymore. It was substituted by Xavier.