how to get the gtkentry text?

I would like to know how you get the text of a gtkentry when you click on a button???because when i trying to get the text of the entry with a button it not work. here my code. I use Ada

file.ads

--  specification

package file is

type my_window_record is private;
type my_Window is access my_window_record'class;

procedure create_window (F : my_window);

procedure open_window (F : my_window);

private

type my_window_record is record

win : Gtk_Window;
container : Gtk_Table;
Button : Gtk_Button;
E : Gtk_Entry;

end record;

procedure initialize_container (F : my_window);

procedure create_button (F : my_window);
procedure callback_button (widget : access Gtk_Widget_Record'Class);
procedure create_entry (F : my_window);
end file;

file.adb

-- body

package body file is

----------------------------
--  Initialize container  --
----------------------------

procedure Initialize_container (F : my_window) is
begin

Gtk_New (F.container, 0, 0, true);
--  ^ create a new container.

F.Container.Set_Row_Spacing (3);
F.Container.set_Column_Spacing (3);

end initialize_container;

--------------------
--  create button --
--------------------

procedure create_button (F : my_window) is
begin

Gtk_New (F.button, "Connected");

Connect (F.button, signal_clicked, callback_button'access);
--  ^ connecting to callback

end create_button;

function button_created (F : my_window) return Gtk_button is
begin

create_button (F);
return F.button;
end button_created;

--------------------
--   create entry --
--------------------

procedure create_entry (F : my_window) is
begin

Gtk_New (F.E);

end create_entry;

function entry_created (F : my_window) return Gtk_Entry is
begin

create_entry (F);
return F.E;
end entry_created;

---------------------
--  create window  --
---------------------

procedure create_window (F : my_window) is
begin

Gtk_New (F.win);
F.win.Fullscreen;
--  ^ create a new window

Initialize_container (F);
F.win.Add (F.container);
--  ^ add the container to the window

F.container.Attach (entry_created (F), 0, 0);
-- ^ add the entry to the container

F.container.Attach (button_created (F), 0, 20);
-- ^ add the button to the container

end create_window;

------------------
--  open window --
------------------

procedure open_window (F : my_window) is
begin

F.win.Show_All;

end open_window;

----------------------
--  callback button --
----------------------

procedure callback_button (widget : access Gtk_Widget_Record'class) is

type Pointeur is access String;

F : my_window;
P : Pointeur;

begin
F := new my_window_record;
P := new String'(Get_Text (entry_created (F)));

Put_line (P.all);

free (F);
free (P);

end callback_button;
end file;

main.adb

with file;      use file;
with Gtk.main;  use Gtk.main;

procedure main is

F : my_window;
begin

Gtk.main.Init;

F := new my_window_record;

create_window (F);
open_window (F);

Gtk.main.main;
end main;

here is all my code to get the text of the entry when clicking on the button. but it doesn't work I can't get the text.

Upvotes: 0

Views: 53

Answers (0)

Related Questions