[gtkada] gtk.text to string
Pedro Díaz Jiménez
pdiaz88 at terra.es
Thu Aug 16 15:23:42 CEST 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thursday 16 August 2001 10:37, you wrote:
> I'm trying to pass gtk.text to a text file, the only way I've founded is
> passing it to string before putting in the text file, so I tried to use the
> get_text function (in gtk-text) and it compiles but I get a constraint
> error when running, this is my procedure:
>
> procedure convertir (b: access gtk.button.gtk_button_record'class) is
> text: string:="";
> begin
> cadena:=gtk.text.get_text(texto);
> put(text); --I did this only to know if it runs
> end convertir;
>
Hiya,
Thats wrong because the string 'text' doesn't have allocated enough space to
hold the text from the widget, hence de constraint error. Solucion: Use
pointers.
Quick and dirt code snippet:
- ---
with Gtk.Window;
with Gtk.GEntry;
with Gtk.Main;
with Ada.Text_IO;
procedure Get_Text is
Type Str_Pointer is Access String;
Window : Gtk.Window.Gtk_Window;
Text : Gtk.GEntry.Gtk_Entry;
strp : Str_Pointer;
begin
Gtk.Main.Init;
Gtk.Window.Gtk_New( Window );
Gtk.Gentry.Gtk_New( Text );
Gtk.Window.Add( Window, Text);
Gtk.GEntry.Set_Text( Text, "Foo! Bar?" );
strp := new String( 1..Gtk.GEntry.Get_Text(Text)'Length );
strp.all := Gtk.GEntry.Get_Text(Text);
Ada.Text_IO.Put_Line( strp.all );
Gtk.Window.Show_All( Window );
Gtk.Main.Main;
end Get_Text;
- ---
Above you can see I declared a String pointer, guessed the size of the text
in the widget (in a pretty unelegant way, but I'm sure there's somewhere a
function to do it more cleanly), allocated memory and copied the text itself
Hope that helps
Pedro
> I don't know what am I doing wrong, as the delcaration of the function is:
> function Get_Text (Text : access Gtk_Text_Record) return String is
>
> and I can't find any info about this in the gtkada_rm.
> please help!
>
> thanks
> Luis.
>
> _____________________________________________
> Free email with personality! Over 200 domains!
> http://www.MyOwnEmail.com
>
>
> _______________________________________________
> gtkada mailing list
> gtkada at lists.act-europe.fr
> http://lists.act-europe.fr/mailman/listinfo/gtkada
- --
/*
* Pedro Diaz Jimenez: pdiaz88 at terra.es, pdiaz at acm.asoc.fi.upm.es
*
* GPG KeyID: E118C651
* Fingerprint: 1FD9 163B 649C DDDC 422D 5E82 9EEE 777D E118 C65
*
* http://planetcluster.org
* Clustering & H.P.C. news and documentation
*
* "Impossible is the adjective of the idiots"
* Napoleon Bonaparte
*/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE7e8llnu53feEYxlERAkS4AKDI89SGkl/Jkgw8TrEZplxjTM9/WwCg4o/a
bw/b6PC6FFjTQX1za9c0b2g=
=qBFX
-----END PGP SIGNATURE-----
More information about the gtkada
mailing list