Dear Valeriy Thank you for this information. Menawhile I have found a workaround in the tutorial guitest.C: TGFrame *frm = (TGFrame *) gTQSender; if (frm->IsA()->InheritsFrom(TGSlider::Class())) { TGSlider *sl = (TGSlider*) frm; id = sl->WidgetId(); } else { TGDoubleSlider *sd = (TGDoubleSlider *) frm; id = sd->WidgetId(); } I have thought that it would be much easier if I could simply call: if (id == -1) { TGWidget *wdg = (TGWidget*)gTQSender; id = wdg->WidgetId(); } But I see, in that case gTQSender would also need to inherit from TGWidget. Best regards Christian Valeriy Onuchin wrote: > Hi Christian, > > > >>Dear Rooters >> >>To get the id of TGButtons, I have always used: >> if (id == -1) { >> TGButton *btn = (TGButton*)gTQSender; >> id = btn->WidgetId(); >> } >> > > > TGButton is derived from TQObject and TGWidget, > so the cast is correct and calling btn->WidgetId() is correct. > > > >>This has always worked, but I can only find TGButton Ids. >>Now I would like to find the Ids of either TGButton or >>TGListBox. Since both inherit from TGWidget I wanted to do: >> if (id == -1) { >> TGWidget *wdg = (TGWidget*)gTQSender; >> id = wdg->WidgetId(); >> } >> > > > You can only do: TGListBox *wdg = (TGListBox*)gTQSender > gTQSender is inherited from TQObject, not from TGWidget. > So, casting TGWidget *wdg = (TGWidget*)gTQSender is not possible. > Even if you get non-zero wdg pointer, it can not be used and should > cause segementation violation when calling TGWidget methods. > > >>Sorrowly, this is not possible, since the return id is >>always zero. >> >>Do you know how I can get the WidgetId from different >>widgets such as TGButton, TGListBox, etc? > > > gTQSender is inherited from TQObject, not from TGWidget. > What is a purpose of getting WidgetId? > > Regards. Valeriy > > >
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET