[gtkada] Handle signals inside a tagged record
Martin Klaiber
martinkl at zedat.fu-berlin.de
Sun Feb 16 13:36:59 CET 2003
Preben Randhol <randhol at pvv.org> wrote:
> Why can't you simply do:
> Handlers.Connect (Ok_Button, "clicked",
> Handlers.To_Marshaller (Update'Access));
I get the error-message:
[...]: no candidate interpretations match the actuals:
[...]: expected type "Handler" defined at gtk-marshallers.ads:335,
instance at gtk-handlers.ads:524, instance at line 32
[...]: found type access to "Update" defined at line 196
I compile with -gnataEfo. Without, the error-message does not appear.
Handlers is defined as:
package Handlers is
new Gtk.Handlers.Callback (Widget_Type => Gtk_Widget_Record);
I guess my problem is, that I do not really understand the whole
callback-stuff. I suppose, I have to define a new Marshaller, which
knows the new type Example_Record. But I might be wrong.
> procedure Update (Example : access Gtk_Button_Record'Class) is
> begin
> A_Variable_Somewhere := Integer'Value (Get_Text (Entry1));
> Another_Variable := Integer'Value (Get_Text (Entry2));
If I do that, Update is not a procedure of Example_Record and so, the
fields cannot be accessed:
[...]: no selector "Entry1" for type "Gtk_Button_Record'Class"
defined at gtk-button.ads:43
[...]: no selector "Entry2" for type "Gtk_Button_Record'Class"
defined at gtk-button.ads:43
> -- I would add a exception handler here as you cannot know if the
> -- Entries have numbers or tekst.
Yes, of course. Checking the validity of the input will be done. But
for now I have problems to get the content of the Entries at all.
Perhaps a solution would be, to have a 'global' instance (don't know
if this is the right word) of Example_Access within the Package-Spec.
Example : Example_Access;
Then I could define a procedure:
procedure Do_Update (Widget : access Gtk_Widget_Record'Class) is
begin
Update (Example);
end Do_Update;
and could call it with:
Handlers.Connect (Ok_Button, "clicked",
Handlers.To_Marshaller (Do_Update'Access));
I didn't test this, but I want to avoid such a global definition
anyway, if possible.
> -- You could also use Spin_buttons perhaps?
What would be the advantage?
> Can you elaborate a bit more what it is you want the program to do when
> you click on the Button.
This is part of a free tax-programm we just started. Unfortunately it
is only usable for people who pay tax in germany, as it depends on the
german tax-laws. It will be presented at www.opensteuer.de, but there
is no code yet. We hopefully expect a first working alpha-version for
the end of the month. First it was planned to realize it on top of a
Turbo-Vision-like library for Ada, I am currently writing for ncurses.
But then the others wished to have a GUI, so I have to learn GtkAda
really quick ;-)
The program is based on an algorithm published by the german tax
authority. It looks really ugly (COBOL perhaps) and uses only global
variables. Later I will rewrite it, but for now we will use it. All
the GtkAda-stuff is mainly used to get data from the users, pass it
to this algorithm, run it and show the output in a window.
So, what the program needs to do is: ask people for data, like their
income and if they press the accept-button (update-button), update the
global variables which are part of this official algorithm.
When I realize the program with a procedural approach, the handling of
the signals work. But I want to use OOP if possible. There seems to be
an example in the docs (base_widget), which works like that. But it is
too complicated for me to understand. I use GtkAda only for 2 weeks now
;-)
Thanks for your help, Preben.
Martin
More information about the gtkada
mailing list