Defining a custom *constructor* (not initializer!)

Jacob Carlborg doob at me.com
Mon May 14 00:26:25 PDT 2012


On 2012-05-12 20:30, Mehrdad wrote:

> Yes, that's not a WinForms thing -- when you close a window, it's
> trivial to have DestroyWindow() get called too.
>
> The trouble is that you can't rely on this to avoid handle leaks -- for
> example, message-only windows are invisible, so their handles can get
> leaked and they can never be closed.

A DWT Hello World application looks like this:

void main ()
{
     auto display = new Display;
     auto shell = new Shell(display);
     shell.open();

     while (!shell.isDisposed)
         if (!display.readAndDispatch())
             display.sleep();

     display.dispose();
}

You always call "display.dispose" at the end of the main function. Since 
"dispose" will dispose all of the receiver's children and "display" is 
the top level widget, everything will be disposed when the application 
exits.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list