[plt-scheme] Object Inheritance
At Mon, 26 Nov 2007 05:35:34 -0800 (PST), Laurent wrote:
> Hello,
>
> I try to extend a basic object. Here, an example :
>
> > (define pg-frame%
> > (class frame%
> > (new message% (parent this) (label "Message"))
> > (super-new)))
>
> > (define f (new pg-frame% (label "Frame")))
> > (send f show #t)
>
> But i have this error :
> send: target is not an object: #<undefined> for method: get-container
>
> The message% parent has to be an instance from frame%. So "this" is
> not correct. But it is possible to do what i want ?
Yes, but you need to invoke `super-new' before adding a child to the
frame instance:
(define pg-frame%
(class frame%
(super-new)
(new message% (parent this) (label "Message"))))
(Yes, we should have a better error message...)
Matthew