Re: [Gtk2forpascal-devel] Why my program crash?
Brought to you by:
mgaertner
From: Mattias G. <nc-...@ne...> - 2002-10-22 13:08:03
|
On Tue, 22 Oct 2002 17:24:50 +0800 mili <mil...@16...> wrote: > 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 > the > textviewer, then you will find that the codes under "//---1" can > correctly output chars you entered, but the codes under "//---2" can't > give correct results, and sometimes cause the program to crash. I > suspect that the system has not regard "texts: String" as a String but > a PChar. gtk does not know strings. 'texts' must be a PChar. And PChar begins at 0 not at 1 like strings. hope this helps, Mattias > > (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 problems, > 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 > should be > responsible for these problems. It's very possible that there's a bug > in 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:=1 to len do str[i]:=texts[i]; > writeln('String: ', str); > //---2 > writeln('String: ', texts); > end;//InsertTextHandler > > begin > gtk_init(@argc,@argv); > > window:=gtk_window_new(GTK_WINDOW_TOPLEVEL); > gtk_widget_set_size_request(window,500,400); > gtk_window_set_position(PGtkWindow(window),GTK_WIN_POS_CENTER_ALWAY > S); gtk_window_set_title(PGtkWindow(window),'Test'); > g_signal_connect(window,'destroy',TGCallback(@destroy),NULL); > > sw:=gtk_scrolled_window_new(NULL,NULL); > tv:=gtk_text_view_new(); > buffer:=gtk_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 > > <<<<<<<< > > > > ------------------------------------------------------- > This sf.net emial is sponsored by: Influence the future of > Java(TM) technology. Join the Java Community Process(SM) (JCP(SM)) > program now. http://ad.doubleclick.net/clk;4699841;7576301;v? > http://www.sun.com/javavote > _______________________________________________ > Gtk2forpascal-devel mailing list > Gtk...@li... > https://lists.sourceforge.net/lists/listinfo/gtk2forpascal-devel |