Программы   Загрузка Партнерство   О компании Контакты  
  Карта Сайта   

Изменить поведение при нажатии для TRadioButton или TComboBox

Автор: http://www.swissdelphicenter.ch

// Q: It appears that programatically setting Item.Index for the Radio Button 
// fires the onClick event.  It also appears  doing the same for the 
// ComboBox does NOT fire the OnClick event. Does another property the two 
// control effect this behavior. 

// A: No, it is caused by the way Windows sends the notifications that fire the 
// event when the control state is changed by a program action. 

// Q: I have an instance where I need each of 
// the control to exhibit the opposite behavior. 

// A: For a TRadiobutton you can disconnect the OnClick handler, change the 
// state, then reconnect the handler. 

procedure ChangeRadiobuttonState(ARadiobutton: TRadiobutton;
   checkit: Boolean);
   oldhandler: TNotifyEvent;
   oldhandler := ARadiobutton.Onclick;
   ARadiobutton.Onclick := nil;
   ARadiobutton.Checked := checkit;
   ARadiobutton.OnClick := oldhandler;

 // To make the combobox "click" after setting the item index simply call its 
// Click method. The control inherits this method from TControl, but it is 
// protected. So you need a bit of hoop-jumping: 

   TComboCracker = class(TCombobox);

 procedure SetComboboxIndex(ACombobox: TCombobox; Index: Integer);
   ACombobox.ItemIndex := Index;

Программы  |  Загрузка  |  Партнерство  |  О компании  |  Контакты

Copyright © LSD Software 2006 - 2011