2011. március 25., péntek
Make a new DBLookupComboBox-Component with OnChange-Event
Problem/Question/Abstract:
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;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése