Ver Mensaje Individual
  #4  
Antiguo 09-11-2005
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Normalmente yo estaría de acuerdo con Neftali cuando dice

Cita:
Empezado por Neftali
Si tú vas a realizar el FreeAndNil, deberías crearlo con el parámetro nil, para indicar que tú mismo lo vas a liberar.
y es, de hecho, lo que yo hubiera contestado. Pero al ver que falla de esta manera me puse a buscar en la ayuda de Delphi y dice esto:

Cita:
TXMLDocument implements the IXMLDocument interface. Applications obtain this interface from TXMLDocument or from the nodes in the document.

When TXMLDocument is created without an Owner, it behaves like an interfaced object. That is, when all references to its interface are released, the TXMLDocument instance is automatically freed. When TXMLDocument is created with an Owner, however, it behaves like any other component, and is freed by its Owner. When you add a TXMLDocument component from the component palette to a form or data module, it is automatically created with an Owner.
Luego entonces, suponiendo que TXMLDocument se comporta como otras interfaces, lo adecuado sería:

1. Usar una variable de tipo IXMLDocument en lugar de TXMLDocument
2. No intentar liberar dicha variable.

Código Delphi [-]
var
  XMLDocument: IXMLDocument;

begin
  XMLDocument := TXMLDocument.Create(nil);
end;

La instancia se destruirá automáticamente en cuanto se pierda la última referencia a ella. En el ejemplo, cuando la variable XMLDocument salga de alcance.

// Saludos

Última edición por roman fecha: 09-11-2005 a las 05:55:36.
Responder Con Cita