[DUG] Usage - initialization and finalization

Paul A Norman paul.a.norman at gmail.com
Fri May 19 12:59:08 NZST 2006


Point of interest - something basic for me and possibly others to learn.

I've only ever used unit 'initialization and finalization' "blindly" since
Delphi 3 days for Activex / OLE type stuff, as just someting that you have
to do - without understanding.

initialization
  OleInitialize(nil);

finalization
  OleUninitialize;

Otherwise I've used the *onFormComplete* and *onDestroy* to set intial stuff
up and then release stuff.

But I am guessing that *Finailization* is a better place to release
stuff (*help
avoid memoery leakage under certain circumstances*?), but
*Initialization*would have to be used for
*Finalization* to be acceptable..

I've read the Delphi 2005 help and googled a bit, but am not yet sure just
what sorts of code can be put in the Initialization and Finalization.

   1. Can anything declared as a unit *VAR* or *CONST* be dealt with or
   used in Initialization ? it appears so to me from what I see (below).
   2. Could I safely .*create* and .*free* objects respectively?

 I  was reading through a *Unit* the other day and saw all sorts of things
in *Initialization*  there that surprised me.

Can any one please point me to a good reference on this, or in our new
learning sharing attitude, explain it for every ones benefit here?

initialization
  FillChar(BrowserData,SizeOf(BrowserData),#0);
  OleInitialize(nil);
  New(PtrWGUID);
  New(PtrMGUID);
  New(PtrDGUID);
  PtrWGUID^:=CGID_WebBrowser;
  PtrMGUID^:=CGID_MSHTML;
  PtrDGuid:=PGUID(nil);
  GetBrowserData(BrowserData);
  IEStr:=IEVerStr;
  OnMessageCompNo:=0;

finalization
  Dispose(PtrWGUID);
  Dispose(PtrMGUID);
  Dispose(PtrDGUID);
  OleUninitialize;

end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20060519/31b939c7/attachment.html


More information about the Delphi mailing list