[Gambas-user] A few questions

Doriano Blengino doriano.blengino at ...1909...
Wed Sep 24 11:12:57 CEST 2008


Benoit Minisini ha scritto:
> On mardi 23 septembre 2008, Doriano Blengino wrote:
>   
>> Hi,
>>
>> I am facing a series of little problems (gambas v. 2.0.0).
>>
>>     
>
> You should use a more recent version of Gambas, otherwise what I will say may 
> not work.
>   
Yes, this is true. But I installed the v2.7.xxx (debian repository) on 
another machine to see if it had many improvements and, as far I could 
see from a quick tour, there was nothing exiciting. I have to say that 
my 2.0.0 is very stable... and I am happy with this unless I found a 
bug. I prefer stability over everything else... ;-)

>>   object.Detach(obs)
>>   obs = NULL
>>
>> 1) Is this the correct way to destroy an observer? I did not find
>> another way - both instructions are needed, it seems. I hoped an
>> "Object.destroy(...)" was present...
>>     
>
> You don't decide. Gambas decides.
>
> More precisely, an object is destroyed when nothing references it. The only 
> thing you can do in your program is not holding a reference on it, by setting 
> NULL to your 'obs' variable for example. 
>
> But it does not mean that a reference is not internally store somewhere else. 
> For example, if you do not do the Object.Detach(obs), fmPreview will hold a 
> reference on it (any object hold a reference on its observers).
>   
So it seems that the two instructions are correct, provided that nothing 
else increments the reference count.

>> 2) I tried to not to use an observer, but attach/detach seem to catch
>> all events involved in fmPreview - both the ones generated by fmpreview
>> and the ones generated by fmPreview child controls.
>>     
>
> No. An observer catches the events sent by one object only.
>   
Sorry... I was talking about *not* to use an observer. I tried to 
"object.attach()" fmPreview, and the result was that 
fmPreview.form_open() didn't execute anymore. I understand this was 
because I deviated, by mean of attach(), the events from fmPreview to 
another place. But I was thinking that events directed *to* fmPreview 
(such form_keypress, form_open and so on) took a different path than 
those generated *from* fmPreview.

>> 3) I tried to instantiate an observer directly from fmPreview, instead
>> of the main program, and then object.attach() it to the main program,
>> but it didn't work.
>>     
>
> You cannot "Object.Attach() to the main program". A default observer (badly 
> named Parent in Gambas) is not a program, but another object.
>
> In the case of a static class (a module), the observer is the class object.
>   
Yes, but... the instruction object.attach() was written inside the code 
of a form, so it was belonging to a class.
I know my english is poor, I say "main program" as a short way to say 
"another class/form which is executing at the time I call fmPreview"...

>> 4) Probably, using "hPreview = NEW fmPreview(...) as "preview" would
>> solve, but I would try to understand better how to use an observer,
>> attach/detach and so on. My goal would be to instantiate fmPreview with
>> only two lines of code (ok, not a so great deal...), or just one line:
>> the event name to be raised could be the same as the title of the print.
>>     
>
> A form is its own event observer. If you want a form to raise other events to 
> other observer, I suggest you think again on how things are encapsulated in 
> your application.
>   
My application is encapsulated pretty well, and it works smoothly.
It is encapsulated well because fmPreview does a lot of things, and the 
only callback is the getpage event.
On the other side, the main program (ie, the form which needs to print) 
only setups() fmPreview to pass the template name of the print, and 
through "reply = fmPreview.ShowModal()" knows if the user aborted, 
printed none, some, or all the pages. I cannot see a simpler way to do 
this, but if someone knows, ...welcome!

>> 5) Does TableView raise keypress events when in edit mode? I see
>> nothing, but I would need it to do certain things. Is there another way
>> to do a controlled editing in a tableview?
>>     
>
> TableView is made in Gambas, so you just have to look at the sources in 
> gb.form to understand how it works. It mainly inherits GridView and uses 
> Observers (and the Watcher class) to do its job. 
>
> And, no, you won't see the keyboard events while editing, as they are caught 
> by the internal editor widget. In that specific case, we could imagine adding 
> a property to get a reference on the editor widget so that you can put your 
> own event observer on it to catch the keyboard events.
>   
In the meantime I realized that. But I didn't want to replicate all the 
code to position a textbox in the right place, set the focus on it, 
implement xxx_data() and friends. But I could reimplement TableView in 
my application, inherit all, and only add a property which contains the 
editor widget reference needed to catch its keypress event... could be...

Many thanks. In my experiments I tried a code snippet like this:

    DIM sName as string

    sName = "test"
    ...
    hSomething = new SomethingElse(ME) as sName


but the compiler complains about sName being an "unknown identifier". Is 
this the intended behaviour, ie the AS clause wants a literal, or 
something else?

Regards,
Doriano Blengino




More information about the User mailing list