--- ibx/trunk/ibcontrols/IBLookupComboEditBox.pas 2018/04/03 09:09:05 225 +++ ibx/trunk/ibcontrols/IBLookupComboEditBox.pas 2018/12/06 15:55:01 263 @@ -30,8 +30,8 @@ unit IBLookupComboEditBox; interface uses - Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DbCtrls, - ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet; + Classes, SysUtils, LCLType, LResources, Forms, Controls, Graphics, Dialogs, DbCtrls, + ExtCtrls, IBSQLParser, DB, StdCtrls, IBCustomDataSet, LCLVersion; type @@ -117,6 +117,15 @@ type procedure CheckAndInsert; procedure DoEnter; override; procedure DoExit; override; + {$if lcl_fullversion >= 2000000} + {Deferred update changes in Lazarus 2.0 stop the combo box working when + the datasource is nil. We thus have to reverse out the changes :(} + function DoEdit: boolean; override; + procedure Change; override; + procedure CloseUp; override; + procedure Select; override; + procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override; + {$ifend} procedure KeyUp(var Key: Word; Shift: TShiftState); override; procedure Loaded; override; procedure Notification(AComponent: TComponent; Operation: TOperation); override; @@ -147,7 +156,7 @@ type implementation -uses LCLType, Variants, LCLProc, LazUTF8; +uses Variants, LCLProc, LazUTF8; { TIBLookupControlLink } @@ -501,9 +510,6 @@ end; procedure TIBLookupComboEditBox.KeyUp(var Key: Word; Shift: TShiftState); begin inherited KeyUp(Key, Shift); - if Key = VK_RETURN then - EditingDone - else if Key = VK_ESCAPE then begin SelStart := UTF8Length(Text); {Ensure end of line selection} @@ -581,6 +587,67 @@ begin FModified := false; end; +{$if lcl_fullversion >= 2000000} +type + + { THackedCustomComboBox } + + THackedCustomComboBox = class(TCustomComboBox) + private + procedure CallUTF8KeyPress(var UTF8Key: TUTF8Char); + procedure CallChange; + end; + +{ THackedCustomComboBox } + +procedure THackedCustomComboBox.CallUTF8KeyPress(var UTF8Key: TUTF8Char); +begin + inherited UTF8KeyPress(UTF8Key); +end; + +procedure THackedCustomComboBox.CallChange; +begin + inherited Change; +end; + +procedure TIBLookupComboEditBox.UTF8KeyPress(var UTF8Key: TUTF8Char); +begin + {TDBLookupComboBox.UTF8KeyPress will swallow the character if + the datalink is not editable. hence to enable writing we must override it} + if ((DataSource = nil) or (Field = nil)) and not ReadOnly then + THackedCustomComboBox(self).CallUTF8KeyPress(UTF8Key) + else + inherited; +end; + +procedure TIBLookupComboEditBox.Change; +begin + THackedCustomComboBox(self).CallChange; +end; + +procedure TIBLookupComboEditBox.CloseUp; +begin + inherited CloseUp; + inherited DoEdit; +end; + +procedure TIBLookupComboEditBox.Select; +begin + inherited Select; + inherited DoEdit; +end; + +function TIBLookupComboEditBox.DoEdit: boolean; +begin + {DoEdit will swallow characters if no editable Field. Hence, to enabled + writing we must avoid calling the inherited method.} + if ((DataSource = nil) or (Field = nil)) and not ReadOnly then + Result := true + else + Result := inherited DoEdit; +end; +{$ifend} + constructor TIBLookupComboEditBox.Create(TheComponent: TComponent); begin inherited Create(TheComponent);