> I'm new to FLTK and I just want to change the label of Fl_Input when I
> press the button. However the label changed to a strange string instead of
> what I want.
> Any idea?


Yes - FWIW, this is a FAQ, and is described in the docs too...



> The code :

> void changelabel(Fl_Widget*ptr)
> {
>       char l[15];
>       Fl_Window *win = (Fl_Window *)((Fl_Button*)ptr->parent());
>       Fl_Input *input = (Fl_Input*)win->child(i);
> 
>       sprintf_s(l,"p :=:  ");
>       input->label(l);

NAK: You want;

     input->copy_label(l);

at this point. Check the docs:

if you simply use label(), then fltk assumes the string you are passing is 
static and will refer to it directly. 

However, here the string you are passing, "l", is stack-automatic and will go 
out of scope as soon as your changelabel() function returns.

So, if that's what you want to do, you need to use copy_label() instead so that 
fltk knows it needs to make an internal copy of the label. 
You have a choice, you can either make your labels in static scope (useful if 
you want to share strings between widgets, for example) or you can use 
copy_label() if the strings are created in dynamic scope.
The static approach may be slightly faster, but the static memory footprint may 
be higher - take your pick!





SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to