Re: name -> widget func? (fwd)




What if you wanted to use in integer instead of "my_button" in each case?
like:
for(i=0;i<count;i++)
button[i] = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (window), i );

That's fine, I use it myself, others in this list use this method as well.
You just have to fully understand the implications. Imagine that i
is equal to 5. Then you are passing an address as, say 0000000005,
then when you get it back you convert this address back to a number
so 0000000005  becomes 5 again (Of course if you try to access
this 0000000005 memory position you will have a crash...). The only
limitation of this method is, if your machine uses 32 bits to
describe a memory address then you cannot pass numbers bigger
than that... which means 2**32-1 (unsigned integer), a fairly large integer! 

This method is also often used to pass numbers 
as data parameters in gtk_signal_connect commands.

This is from my own code (APP_LAYER is an integer in an enumeration):

gtk_object_set_data (GTK_OBJECT (menu), "select", (gpointer) APP_LAYER);

Carlos

Thanks Carlos,

I was worried about using an integer where a const char * was
called for. I thought that giving an address of a register variable 
might be a problem if the contents of the address were changed before
a call to gtk_object_get_data.

Havoc gave the function definitions for gtk_object_set_data and get_data
in another reply to a previous question I asked. Thanks Havoc for the
reply, sorry for the lateness.

George




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]