mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 00:56:35 +02:00
LCL: "EmptyValue" and "DisplayEmpty" properties for TBLookupCombobox and TDBLookupListBox components. Issue #36035, patch from Zdravko Gabrovski.
git-svn-id: trunk@62884 -
This commit is contained in:
parent
2675c98695
commit
a43056f291
@ -123,6 +123,8 @@ Type
|
||||
FDataFieldNames: string;
|
||||
FKeyFieldNames: string;
|
||||
FListFieldName: string;
|
||||
FEmptyValue: string;
|
||||
FDisplayEmpty: string;
|
||||
FListFieldIndex: Integer;
|
||||
FDataFields: TList; // Data Fields to lookup/edit
|
||||
FKeyFields: TList; // Keyfields in lookup dataset
|
||||
@ -169,6 +171,8 @@ Type
|
||||
property ListSource: TDataSource read GetListSource write SetListSource;
|
||||
property NullValueKey: TShortcut read FNullValueKey write FNullValueKey;
|
||||
property ScrollListDataset: Boolean read FScrollListDataset write FScrollListDataset;
|
||||
property EmptyValue : String read FEmptyValue write FEmptyVAlue;
|
||||
property DisplayEmpty : String read FDisplayEmpty write FDisplayEmpty;
|
||||
end;
|
||||
|
||||
{ TDBEdit }
|
||||
@ -451,6 +455,8 @@ Type
|
||||
private
|
||||
FLookup: TDBLookup;
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
function GetDisplayEmpty: String;
|
||||
function GetEmptyValue: String;
|
||||
function GetKeyField: string;
|
||||
function GetKeyValue: Variant;
|
||||
function GetListField: string;
|
||||
@ -459,6 +465,8 @@ Type
|
||||
function GetLookupCache: boolean;
|
||||
function GetNullValueKey: TShortCut;
|
||||
function GetScrollListDataset: Boolean;
|
||||
procedure SetDisplayEmpty(AValue: String);
|
||||
procedure SetEmptyValue(AValue: String);
|
||||
procedure SetKeyField(const Value: string);
|
||||
procedure SetKeyValue(const AValue: Variant);
|
||||
procedure SetListField(const Value: string);
|
||||
@ -504,6 +512,8 @@ Type
|
||||
property ListSource: TDataSource read GetListSource write SetListSource;
|
||||
property LookupCache: boolean read GetLookupCache write SetLookupCache;
|
||||
property NullValueKey: TShortCut read GetNullValueKey write SetNullValueKey default 0;
|
||||
property EmptyValue: String read GetEmptyValue write SetEmptyValue;
|
||||
property DisplayEmpty: String read GetDisplayEmpty write SetDisplayEmpty;
|
||||
// property MultiSelect;
|
||||
property OnClick;
|
||||
property OnDblClick;
|
||||
@ -852,6 +862,8 @@ Type
|
||||
private
|
||||
FLookup: TDBLookup;
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
function GetDisplayEmpty: String;
|
||||
function GetEmptyValue: String;
|
||||
function GetKeyField: string;
|
||||
function GetKeyValue: variant;
|
||||
function GetListField: string;
|
||||
@ -860,6 +872,8 @@ Type
|
||||
function GetLookupCache: boolean;
|
||||
function GetNullValueKey: TShortCut;
|
||||
function GetScrollListDataset: Boolean;
|
||||
procedure SetDisplayEmpty(AValue: String);
|
||||
procedure SetEmptyValue(AValue: String);
|
||||
procedure SetKeyField(const Value: string);
|
||||
procedure SetKeyValue(const AValue: variant);
|
||||
procedure SetListField(const Value: string);
|
||||
@ -915,6 +929,8 @@ Type
|
||||
property LookupCache: boolean read GetLookupCache write SetLookupCache;
|
||||
// property MaxLength default -1;
|
||||
property NullValueKey: TShortCut read GetNullValueKey write SetNullValueKey default 0;
|
||||
property EmptyValue: String read GetEmptyValue write SetEmptyValue;
|
||||
property DisplayEmpty: String read GetDisplayEmpty write SetDisplayEmpty;
|
||||
property OnChange;
|
||||
property OnChangeBounds;
|
||||
property OnClick;
|
||||
|
@ -106,6 +106,8 @@ begin
|
||||
FDataFields := TList.Create;
|
||||
FKeyFields := TList.Create;
|
||||
FListLink := TDBLookupDataLink.Create(Self);
|
||||
FDisplayEmpty := '';
|
||||
FEmptyValue := '';
|
||||
//FHasLookUpField := False;
|
||||
//FLookupCache := False;
|
||||
end;
|
||||
@ -281,8 +283,22 @@ begin
|
||||
ListLinkDataSet := FListLink.DataSet;
|
||||
if not (Assigned(ListLinkDataSet) and Assigned(FListField)) then
|
||||
Exit;
|
||||
if ListLinkDataSet.IsEmpty then
|
||||
|
||||
if ListLinkDataSet.IsEmpty then begin
|
||||
// Add Empty value if no recs into dataset
|
||||
if FEmptyValue<>'' then begin
|
||||
FControlItems.BeginUpdate;
|
||||
try
|
||||
KeyIndex := FControlItems.Add(FDisplayEmpty);
|
||||
SetLength(FListKeys, 1);
|
||||
FListKeys[KeyIndex] := FEmptyValue;
|
||||
KeyListCount := 1;
|
||||
finally
|
||||
FControlItems.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
Exit;
|
||||
end;
|
||||
Bookmark := ListLinkDataSet.GetBookmark;
|
||||
//in fpc 2.6.4, TMemDataset does not supports BlockRead. Issues 26356, 27959
|
||||
{$IF FPC_FULLVERSION < 30000}
|
||||
@ -302,8 +318,18 @@ begin
|
||||
//needed to handle sqldb.TSQLQuery that does not has a reliable recordcount after Open
|
||||
ListLinkDataSet.Last;
|
||||
ListLinkDataSet.First;
|
||||
SetLength(FListKeys, ListLinkDataSet.RecordCount);
|
||||
KeyListCount := 0;
|
||||
SetLength(FListKeys, ListLinkDataSet.RecordCount);
|
||||
// Handle Empty Value and Empty Display
|
||||
if FEmptyValue<>'' then begin
|
||||
KeyIndex := FControlItems.Add(FDisplayEmpty);
|
||||
if KeyIndex<>length(FListKeys) then // sanity check
|
||||
raise Exception.Create('TDBLookup.FetchLookupData: inconsistency');
|
||||
SetLength(FListKeys, KeyIndex+1); // Add one more
|
||||
FListKeys[KeyIndex] := FEmptyValue;
|
||||
KeyListCount := 1;
|
||||
end;
|
||||
|
||||
while not ListLinkDataSet.EOF do
|
||||
begin
|
||||
KeyIndex := FControlItems.Add(FListField.DisplayText);
|
||||
|
@ -21,6 +21,8 @@ constructor TDBLookupComboBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FLookup := TDBLookup.Create(Self);
|
||||
EmptyValue := '';
|
||||
DisplayEmpty := '';
|
||||
FDataLink.OnActiveChange := @ActiveChange;
|
||||
end;
|
||||
|
||||
@ -68,6 +70,16 @@ begin
|
||||
UpdateLookup;
|
||||
end;
|
||||
|
||||
function TDBLookupComboBox.GetDisplayEmpty: String;
|
||||
begin
|
||||
Result := FLookup.DisplayEmpty;
|
||||
end;
|
||||
|
||||
function TDBLookupComboBox.GetEmptyValue: string;
|
||||
begin
|
||||
Result := FLookup.EmptyValue;
|
||||
end;
|
||||
|
||||
procedure TDBLookupComboBox.DataChange(Sender: TObject);
|
||||
begin
|
||||
UpdateItemIndex;
|
||||
@ -153,6 +165,18 @@ begin
|
||||
result := FLookup.NullValueKey;
|
||||
end;
|
||||
|
||||
procedure TDBLookupComboBox.SetDisplayEmpty(AValue: String);
|
||||
begin
|
||||
FLookup.DisplayEmpty:=AValue;
|
||||
UpdateLookup;
|
||||
end;
|
||||
|
||||
procedure TDBLookupComboBox.SetEmptyValue(AValue: string);
|
||||
begin
|
||||
FLookup.EmptyValue:=AValue;
|
||||
UpdateLookup;
|
||||
end;
|
||||
|
||||
function TDBLookupComboBox.GetScrollListDataset: Boolean;
|
||||
begin
|
||||
Result := FLookup.ScrollListDataset;
|
||||
|
@ -20,6 +20,8 @@ constructor TDBLookupListBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FLookup:= TDBLookup.Create(Self);
|
||||
EmptyValue := '';
|
||||
DisplayEmpty := '';
|
||||
FDataLink.OnActiveChange:= @ActiveChange;
|
||||
end;
|
||||
|
||||
@ -41,6 +43,16 @@ begin
|
||||
UpdateLookup;
|
||||
end;
|
||||
|
||||
function TDBLookupListBox.GetDisplayEmpty: String;
|
||||
begin
|
||||
Result := FLookup.DisplayEmpty;
|
||||
end;
|
||||
|
||||
function TDBLookupListBox.GetEmptyValue: string;
|
||||
begin
|
||||
Result := FLookup.EmptyValue;
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.DataChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
@ -134,6 +146,18 @@ begin
|
||||
Result := FLookup.NullValueKey;
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.SetDisplayEmpty(AValue: String);
|
||||
begin
|
||||
FLookup.DisplayEmpty := AValue;
|
||||
UpdateLookup;
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.SetEmptyValue(AValue: String);
|
||||
begin
|
||||
FLookup.EmptyValue := AValue;
|
||||
UpdateLookup;
|
||||
end;
|
||||
|
||||
function TDBLookupListBox.GetScrollListDataset: Boolean;
|
||||
begin
|
||||
Result := FLookup.ScrollListDataset;
|
||||
|
Loading…
Reference in New Issue
Block a user