Mega Code Archive

 
Categories / Delphi / VCL
 

OnChange Event for TDBLookupComboBox

Title: OnChange Event for TDBLookupComboBox Question: DB-Aware Components like TDBEdit have an Event "OnChange". This Event is established in TCustomEdit. Unfortunately in TDBLookupComboBox there is no OnChange-Event, because this component is not based on TCustomEdit but on TWinControl. What to do if you want to have an OnChange event in a DBLookupComboBox? Answer: DB-Aware Components like TDBEdit have an Event "OnChange". This Event is established in TCustomEdit. Unfortunately in TDBLookupComboBox there is no OnChange-Event, because this component is not based on TCustomEdit but on TWinControl. What to do if you want to have an OnChange event in a DBLookupComboBox? Well, let's build our own component with this event! It's easy because TDBLookupControl established an protected Procedure "KeyValueChanged". It will fired when the property "KeyValue" ist changed. So we can overwrite this Event in our own Componentent and call a new Event "OnChang". That's all :-) Type TMyDBLookupComboBox = class ( TDBLookupComboBox) private FOnChange: TNotifyEvent; protected procedure KeyValueChanged; override; published property OnChange : TNotifyEvent read FOnChange write FOnChange; end; implementation procedure TMyDBLookupComboBox.KeyValueChanged; begin inherited; if Assigned(FOnChange) then FOnChange(Self); end;