Accessing anonymous reference inside with block
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Oct 18 09:19:29 PDT 2010
Oops, the code came out a little fuzzy, here's the fixed one:
http://pastebin.com/kiXPeQLB
On 10/18/10, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> Here's an example from DFL where I'm using an anonymous Scintilla
> object which is a subclass of a text editing widget in DFL (just
> another window subclass), but behind the scenes it actually loads the
> Scintilla DLL and behaves like a normal DFL text editing widget:
>
> http://pastebin.com/YAduPRtF
>
> What really happens in DFL is that assiging the "parent" variable of a
> window class object (lets call it client) to another window class
> object (call it host) means that the host now holds a reference to the
> client. So the client will not be destroyed unless any of it's destroy
> methods are explicitly called, or if the host window is destroyed then
> the client window is destroyed as well (this is how DFL works).
>
> I think that's how it works. If I'm wrong someone can correct me, though.
> :)
>
> On 10/18/10, Stanislav Blinov <blinov at loniir.ru> wrote:
>> 15.10.2010 19:43, Andrej Mitrovic wrote:
>>> Related: A nice alternative for quickly using anonymous objects is
>>> using the with statement, e.g.:
>>>
>>> with (new Foo)
>>> {
>>> foo();
>>> // ... more code
>>> }
>>>
>>> And after the with block the object doesn't exist anymore.
>>> Or you could bind it to some internal reference and keep it there,
>>
>> I must ask, how can this binding be achieved?
>>
>>> which wouldn't destroy it after exiting the with block. Many of the DFL
>>> GUI
>>> library code samples work this way, and it's quite a nice syntax imo.
>>
>>
>
More information about the Digitalmars-d-learn
mailing list