> var
>  XL: Variant;         // OLE Excel spreadsheet
>
> {$R *.dfm}
>
> procedure TForm1.FormCreate(Sender: TObject);
> begin
>  XL := CreateOLEObject('Excel.Application');  // Ole object creation
> end;
>
> procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
> begin
>  XL := Unassigned; // release the OLE object
> {  ?  Frankly I'm not 100% sure about this. "Free" is not supported
> apparently.     Anyone got any comments?}
> end;


Yup - this is correct. Deep down in the depths of Delphi's variant
routines, there's a bunch of black magic going on to shield you from
some of the nastiness that is COM coding. At its core, the XL variant
will be holding, in this case, an "interface pointer" to an IDispatch
object.

Delphi reference counts its interface pointers, so setting XL :=
Unassigned (magic variant constant) will end up setting the interface
pointer to nil. When that happens, Delphi will clean up the object.

You can read about alot of the gory details at
http://www.techvanguards.com (if you really want to...).  If you want to
dive into this stuff, a really good book (if you can find a copy) is
"Delphi COM Programming", by Eric Harmon.

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to