[Gtk2forpascal-devel] Why my program crash?
Brought to you by:
mgaertner
From: mili <mil...@16...> - 2002-10-22 12:38:24
|
Hello, Every one My program appears weild. Can anybody find the solutions for them? (1)First problem: Compile and run the test program, and try to enter some chars into th= e=20 textviewer, then you will find that the codes under "//---1" can correctl= y=20 output chars you entered, but the codes under "//---2" can't give correct= =20 results, and sometimes cause the program to crash. I suspect that the sys= tem=20 has not regard "texts: String" as a String but a PChar. (2)Second problem: Now comment the codes under "//---2" so that we can test the program. Then try to enter some chars, almost all chars will not cause problem= s,=20 but as soon as you press the key of "enter", the program crashes!!! So perhaps it's the signal & it's handler of "insert_text" that shoul= d be=20 responsible for these problems. It's very possible that there's a bug in=20 Gtk2forpascal. Thanks, Yours, mili >>>>>>>> program test; {$mode objfpc} {$H+} uses glib2, gtk2, gdk2; var window : PGtkWidget; sw : PGtkWidget; tv : PGtkWidget; buffer : PGtkTextBuffer; procedure destroy (window: PGtkWidget; data: gpointer); cdecl; begin gtk_main_quit(); end;//destroy procedure InsertTextHandler(buffer: PGtkTextBuffer; pos: PGtkTextIter; texts: String; len: gint; um: gpointer); cdecl; var str:String; i :Integer; begin //Actually, I did nothing in this handler writeln('@ InsertTextHandler'); //---1 setlength(str,len); for i:=3D1 to len do str[i]:=3Dtexts[i]; writeln('String: ', str); //---2 writeln('String: ', texts); end;//InsertTextHandler begin gtk_init(@argc,@argv); window:=3Dgtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(window,500,400); gtk_window_set_position(PGtkWindow(window),GTK_WIN_POS_CENTER_ALWAYS); gtk_window_set_title(PGtkWindow(window),'Test'); g_signal_connect(window,'destroy',TGCallback(@destroy),NULL); sw:=3Dgtk_scrolled_window_new(NULL,NULL); tv:=3Dgtk_text_view_new(); buffer:=3Dgtk_text_view_get_buffer(PGtkTextView(tv)); g_signal_connect(PGOBJECT(buffer), 'insert_text', TGCallback(@InsertTextHandler), nil); gtk_container_add(PGtkContainer(sw),tv); gtk_widget_show(tv); gtk_widget_show(sw); gtk_container_add(PGtkContainer(window),sw); gtk_widget_show(window); gtk_main(); end.//test <<<<<<<< |