Re: Attn: Thomas Reg. Temp Conversion Combobox example code.....



On Tue, 2001-09-04 at 22:17, manchalapraveenk reddy wrote:
hi Thomoas,
10q for responding i got confused in passing the
parameter to the switch() to
what to pass and the parameters of the eventhandler i
will he thak ful to u if
u can provide the required. plz find my coding for the
same.

Ah, yes.

          switch ( GTK_COMBO(combo->entry))

First of all, this             ^^^^^^^^^^^^ gives you the entry widget,
so casting it to a combo is not going to work. Try
GTK_COMBO(combo)->entry. Secondly, *this* is going to give you the entry
widget, *not* the data the widget contains. For that you need to call
gtk_entry_get_text (just as you do just before the switch statement in
your code). This will give you the text the entry contains. Now comes
the unpleasant supprise: you cannot switch over a text. (Well, you *can*
switch over char*, but you will be comparing pointers, not doing string
comparison, which is usually what you want).

In any case...

            {
             case 1:
                    ^^ here you are comparing a pointer with the integer
1. You probably don't have pointers to anything in that area of the
address-space, and it is not what you want anyway.


                [snip]

             break;
   
             case  Kelvin:

                and  ^^^^^^^ here you are comparing the pointer with a
constant (only constants can be used after 'case'), but a constant that
you haven't declared.

                [snip]

What you want is probably an if-else-if-else-if-else where you call
strcmp to compare the entry string with the possible temparature scales
(represented as strings). That would look something like

const char *str = gtk_entry_get_text (GTK_COMBO (combo)->entry);
if (strcmp (str,"Celcius") == 0)
  {
     // do stuff
  }
else if (strcmp (str,"Kelvin") == 0)
  {
     // do other stuff
  }
else if ...
else
  {
     // not a recognized value, do exception handling
  }

Try this out and see if you can get through with this solution.

        /mailund


-- 
GPG signature disabled due to popular demands.





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