1. Home
  2. Computing & Technology
  3. Delphi Programming

Using an object with no reference variable

By , About.com Guide

The idea is to construct the object, then enter its scope rather than assign its address to an object reference variable. Whilst in its scope, you can access all its properties and methods directly.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.FormCreate(Sender: TObject) ;
var RegPath : string;
begin
   with TRegistry.Create do
     try
       RegPath:='MyApp';
       RootKey := HKEY_CURRENT_USER;
       If OpenKey(RegPath, False) then
         // do stuff here
     finally
       Free
     end
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Delphi Enum to String
« Get Associated application by Extension

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2003 Delphi Tips
  7. Using an object with no reference variable

©2009 About.com, a part of The New York Times Company.

All rights reserved.