[Gambas-user] A few questions
Benoit Minisini
gambas at ...1...
Thu Sep 25 01:26:20 CEST 2008
On mercredi 24 septembre 2008, Doriano Blengino wrote:
> >
> > The Object.Attach() method does not depend on its context, contrary to
> > the NEW instruction.
>
> I can not catch the point. It seems to me that I can use object.attach()
> everywhere, because in its parameters:
>
> STATIC SUB *Attach* ( _Object_ AS Object, _Parent_ AS Object, _Name_ AS
> String )
>
> ...I specify the object to steal events from (Object), to which
> listener/observer send those events to (Parent), and the name the
> handlers begin with. But I suppose that if Name is "test", the compiler
> looks for "test_xxx()" methods in the class currently being compiled (or
> currently being running), otherwise what the heck could it do?
> So I
> deduce object.attach() depends on its context, in the sense "it depends
> in which class the instruction attach() is compiled".
> Forget the saying "main program"... it was an unhappy way to mean "the
> rest of the program"...
>
No. Object.Attach() will send events raise by 'Object' to 'Parent', by
using 'Name' as event handler prefix. So it does not depend on the context.
The same Attach() call will always do the same thing whereever it is run.
> > * Make frmPreview raise a "GetPage" event.
>
> Already done this way.
>
> > * Add a Register method in your frmPreview that takes an Object as
> > argument.
>
> That was exactly what I wanted to do...
>
> > * In that Register method, creates an observer on the form (ME) and
> > attach it to the form (ME) to the argument. This way, the argument will
> > receive the GetPage event (and other form events if it wants, but don't
> > tell him).
>
> So I should write:
>
> obs = new observer(me) AS parameter_of_sub
>
> This is a little inconsistent with the syntax '...as "whatever"'. I will
> see if it works.
No. My sentence was incorrect! You will write:
PRIVATE $hObs AS Observer
PUBLIC SUB Register(hObject AS Object)
$hObs = NEW Observer(ME)
Object.Attach($hObs, hObject, "whatever")
END
PUBLIC SUB Unregister(hObject AS Object)
Object.Detach($hObs)
$hObs = NULL
END
You can have only one registered object simultaneously, but it should not
matter for your use of that.
>
> Same as before - does the "var = new .... AS xxxx" expect xxxx to be a
> literal string, any string expression, or a class name? Anyway I will
> inspect.
Theoritically, any string expression should be possible. Practically, only use
a string litteral!
Regards,
--
Benoit Minisini
More information about the User
mailing list