Page 1 of 1

Strange IMA - help appreciated

Posted: Sat Jan 20, 2007 4:32 pm
by WishMaster

Code: Select all

Declare Eins()
Declare Zwei()
Declare Event_Handler()

Procedure Eins()
    OpenWindow(1, 0, 0, 100, 100, "Hallo")
    CreateGadgetList(WindowID(1))
    ButtonGadget(1, 0, 0, 100, 100, "Zwei!")
    
    Repeat
    
    Until Event_Handler() = #PB_Event_CloseWindow
EndProcedure

Procedure Zwei()
    OpenWindow(2, 0, 0, 100, 100, "Hallo 2")
    CreateGadgetList(WindowID(2))
    EditorGadget(2, 0, 0, 100, 100)
    gtk_text_buffer_create_tag_(gtk_text_view_get_buffer_(GadgetID(2)), "bold", "weight", 800)
    
    Repeat
    
    Until Event_Handler() = #PB_Event_CloseWindow
EndProcedure

Procedure Event_Handler()
    Event = WaitWindowEvent(20)
    Select Event
    Case #PB_Event_Gadget
        Select EventGadget()
            Case 1
                Zwei()
        EndSelect
    Default
        ProcedureReturn Event_Handler
    EndSelect
EndProcedure

Eins()
Why does this give an Invalid Memory Access?


//Edit:
This one works fine:

Code: Select all

Declare Eins() 
 Declare Zwei() 
 Declare Drei()
 Declare Event_Handler() 
 
 Procedure Eins() 
     OpenWindow(1, 0, 0, 100, 100, "Hallo") 
     CreateGadgetList(WindowID(1)) 
     ButtonGadget(1, 0, 0, 100, 100, "Zwei!") 
     
     Repeat 
     
     Until Event_Handler() = #PB_Event_CloseWindow 
 EndProcedure 
 
 Procedure Zwei() 
     OpenWindow(2, 0, 0, 100, 100, "Hallo 2") 
     CreateGadgetList(WindowID(2)) 
     EditorGadget(2, 0, 0, 100, 100) 
     Drei()
     
     Repeat 
     
     Until Event_Handler() = #PB_Event_CloseWindow 
 EndProcedure
 
 Procedure Drei()
 gtk_text_buffer_create_tag_(gtk_text_view_get_buffer_(GadgetID(2)), "bold", "weight", 800) 
 EndProcedure
 
 Procedure Event_Handler() 
     Event = WaitWindowEvent(20) 
     Select Event 
     Case #PB_Event_Gadget 
         Select EventGadget() 
             Case 1 
                 Zwei() 
         EndSelect 
     Default 
         ProcedureReturn Event_Handler 
     EndSelect 
 EndProcedure 
 
 Eins()

Posted: Mon Jan 22, 2007 12:13 pm
by WishMaster
You don't like me 'cause I've red hair, do you?

Posted: Mon Jan 22, 2007 5:04 pm
by walker
:D :D do you have?... no, that's not the reason...
I'd changed the code a little to get an output on the console... (switch to console in compiler options)

Code: Select all

Declare Eins()
Declare Zwei()
Declare Event_Handler()

Procedure Eins()
    OpenWindow(1, 0, 0, 100, 100, "Hallo")
    CreateGadgetList(WindowID(1))
    ButtonGadget(1, 0, 0, 100, 100, "Zwei!")
   
;     Repeat
   
;     Until
;      Event_Handler(); = #PB_Event_CloseWindow
EndProcedure

Procedure Zwei()
    OpenWindow(2, 0, 0, 100, 100, "Hallo 2")
    CreateGadgetList(WindowID(2))
    EditorGadget(2, 0, 0, 100, 100)
    
    gtk_text_buffer_create_tag_(gtk_text_view_get_buffer_(GadgetID(2)), "bold", "weight", 800)
   
;     Repeat
   
;     Until 
;     Event_Handler() ;= #PB_Event_CloseWindow
EndProcedure


Eins()
Repeat
    Event = WaitWindowEvent(20)
    Select Event
    Case #PB_Event_Gadget
    If EventType()=#PB_EventType_LeftClick
        Select EventGadget()
            Case 1
                Zwei()
        EndSelect
    EndIf
    Default
;         ProcedureReturn Event_Handler
    EndSelect
 Until Event=#PB_Event_CloseWindow
if you now press the button, the putput on the console is like:

Code: Select all


(purebasic.exe:9355): GLib-GObject-WARNING **: IA__g_object_set_valist: object class `GtkTextTag' has no property named `h%'
I guess there is a bug somewhere around Glib.... may Fred could check this...

But why this leads to an ivalid memory access... :cry:

Posted: Mon Jan 29, 2007 10:29 pm
by freak
gtk_text_buffer_create_tag () is a function with variable arguments.
PB does not support C-style variable arguments.
Basically you are not terminating your property list with a NULL, which leads to the crash.

You will have to call gtk_text_tag_new() to create the tag, then set the properties and add it to the buffer yourself.

Posted: Wed Feb 07, 2007 5:30 pm
by WishMaster
You have to use g_object_set() to change the properties of a tag created by gtk_text_tag_new()....
And g_object_set() also has these veriable arguments...

Posted: Wed Feb 07, 2007 8:29 pm
by freak
Use g_object_set_property then.
gtk has a non C-specific solution for all the features, as it is intended to be used by other languages as well.

Posted: Wed Feb 07, 2007 9:08 pm
by WishMaster
What's wrong here - it gives an IMA:

Code: Select all

OpenWindow(2, 0, 0, 100, 100, "Hallo 2") 
CreateGadgetList(WindowID(2)) 
EditorGadget(2, 0, 0, 100, 100) 

buffer = gtk_text_view_get_buffer_(GadgetID(2))
tag = gtk_text_tag_new_("mytag")
g_object_set_property_(tag, "weight", 800)
gtk_text_tag_table_add_(buffer, tag)

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 

Posted: Sat Feb 10, 2007 12:25 pm
by WishMaster
*bump*

Posted: Sat Feb 10, 2007 3:33 pm
by freak
WishMaster wrote:*bump*
... and your point is ?

I could come up with a working example for you, but i really do not see why
i should do your work, especially if all i get is these annoying bumps.

Your problem is that you do not read the gtk manual carefully. You cannot simply
put up some not working code and expect others to do the work for you.

g_object_set_property() expects a GValue, not an integer as you pass to it. Of course this crashes.

Now, to get a GValue of type int, you need g_value_init() and g_value_set_int()
http://developer.gnome.org/doc/API/2.0/ ... tml#GValue
http://developer.gnome.org/doc/API/2.0/ ... #id2612224

Now i suggest you read that documentation and do some coding yourself.

Alternatively, you could try to load the gtk libs with OpenLibrary and call
the C varargs functions directly.
But if you're not looking at the documentation, your chances with that are low as well...

Posted: Sat Feb 10, 2007 8:53 pm
by WishMaster
Hey, it would have been a single line of code and eventually another line for a small explanation.

Reading the GTK docs - that's what I do all the time.
The GTK terms for variable types always differ from the PB ones - so it's IMO not a crime to take GValue for an ordinary PB long.

Doing coding on my own - that's also something I spend quite much time for but sometimes I have - just like everybody else - a more or less tricky problem to solve - so I post my question in the board.

As you are unfortunately the only one in the PB community with some GTK knowledge it's quite natural to post here.
I excuse if this board isn't meant to ask questions.