mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 19:39:18 +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;
|
FDataFieldNames: string;
|
||||||
FKeyFieldNames: string;
|
FKeyFieldNames: string;
|
||||||
FListFieldName: string;
|
FListFieldName: string;
|
||||||
|
FEmptyValue: string;
|
||||||
|
FDisplayEmpty: string;
|
||||||
FListFieldIndex: Integer;
|
FListFieldIndex: Integer;
|
||||||
FDataFields: TList; // Data Fields to lookup/edit
|
FDataFields: TList; // Data Fields to lookup/edit
|
||||||
FKeyFields: TList; // Keyfields in lookup dataset
|
FKeyFields: TList; // Keyfields in lookup dataset
|
||||||
@ -169,6 +171,8 @@ Type
|
|||||||
property ListSource: TDataSource read GetListSource write SetListSource;
|
property ListSource: TDataSource read GetListSource write SetListSource;
|
||||||
property NullValueKey: TShortcut read FNullValueKey write FNullValueKey;
|
property NullValueKey: TShortcut read FNullValueKey write FNullValueKey;
|
||||||
property ScrollListDataset: Boolean read FScrollListDataset write FScrollListDataset;
|
property ScrollListDataset: Boolean read FScrollListDataset write FScrollListDataset;
|
||||||
|
property EmptyValue : String read FEmptyValue write FEmptyVAlue;
|
||||||
|
property DisplayEmpty : String read FDisplayEmpty write FDisplayEmpty;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDBEdit }
|
{ TDBEdit }
|
||||||
@ -451,6 +455,8 @@ Type
|
|||||||
private
|
private
|
||||||
FLookup: TDBLookup;
|
FLookup: TDBLookup;
|
||||||
procedure ActiveChange(Sender: TObject);
|
procedure ActiveChange(Sender: TObject);
|
||||||
|
function GetDisplayEmpty: String;
|
||||||
|
function GetEmptyValue: String;
|
||||||
function GetKeyField: string;
|
function GetKeyField: string;
|
||||||
function GetKeyValue: Variant;
|
function GetKeyValue: Variant;
|
||||||
function GetListField: string;
|
function GetListField: string;
|
||||||
@ -459,6 +465,8 @@ Type
|
|||||||
function GetLookupCache: boolean;
|
function GetLookupCache: boolean;
|
||||||
function GetNullValueKey: TShortCut;
|
function GetNullValueKey: TShortCut;
|
||||||
function GetScrollListDataset: Boolean;
|
function GetScrollListDataset: Boolean;
|
||||||
|
procedure SetDisplayEmpty(AValue: String);
|
||||||
|
procedure SetEmptyValue(AValue: String);
|
||||||
procedure SetKeyField(const Value: string);
|
procedure SetKeyField(const Value: string);
|
||||||
procedure SetKeyValue(const AValue: Variant);
|
procedure SetKeyValue(const AValue: Variant);
|
||||||
procedure SetListField(const Value: string);
|
procedure SetListField(const Value: string);
|
||||||
@ -504,6 +512,8 @@ Type
|
|||||||
property ListSource: TDataSource read GetListSource write SetListSource;
|
property ListSource: TDataSource read GetListSource write SetListSource;
|
||||||
property LookupCache: boolean read GetLookupCache write SetLookupCache;
|
property LookupCache: boolean read GetLookupCache write SetLookupCache;
|
||||||
property NullValueKey: TShortCut read GetNullValueKey write SetNullValueKey default 0;
|
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 MultiSelect;
|
||||||
property OnClick;
|
property OnClick;
|
||||||
property OnDblClick;
|
property OnDblClick;
|
||||||
@ -852,6 +862,8 @@ Type
|
|||||||
private
|
private
|
||||||
FLookup: TDBLookup;
|
FLookup: TDBLookup;
|
||||||
procedure ActiveChange(Sender: TObject);
|
procedure ActiveChange(Sender: TObject);
|
||||||
|
function GetDisplayEmpty: String;
|
||||||
|
function GetEmptyValue: String;
|
||||||
function GetKeyField: string;
|
function GetKeyField: string;
|
||||||
function GetKeyValue: variant;
|
function GetKeyValue: variant;
|
||||||
function GetListField: string;
|
function GetListField: string;
|
||||||
@ -860,6 +872,8 @@ Type
|
|||||||
function GetLookupCache: boolean;
|
function GetLookupCache: boolean;
|
||||||
function GetNullValueKey: TShortCut;
|
function GetNullValueKey: TShortCut;
|
||||||
function GetScrollListDataset: Boolean;
|
function GetScrollListDataset: Boolean;
|
||||||
|
procedure SetDisplayEmpty(AValue: String);
|
||||||
|
procedure SetEmptyValue(AValue: String);
|
||||||
procedure SetKeyField(const Value: string);
|
procedure SetKeyField(const Value: string);
|
||||||
procedure SetKeyValue(const AValue: variant);
|
procedure SetKeyValue(const AValue: variant);
|
||||||
procedure SetListField(const Value: string);
|
procedure SetListField(const Value: string);
|
||||||
@ -915,6 +929,8 @@ Type
|
|||||||
property LookupCache: boolean read GetLookupCache write SetLookupCache;
|
property LookupCache: boolean read GetLookupCache write SetLookupCache;
|
||||||
// property MaxLength default -1;
|
// property MaxLength default -1;
|
||||||
property NullValueKey: TShortCut read GetNullValueKey write SetNullValueKey default 0;
|
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 OnChange;
|
||||||
property OnChangeBounds;
|
property OnChangeBounds;
|
||||||
property OnClick;
|
property OnClick;
|
||||||
|
@ -106,6 +106,8 @@ begin
|
|||||||
FDataFields := TList.Create;
|
FDataFields := TList.Create;
|
||||||
FKeyFields := TList.Create;
|
FKeyFields := TList.Create;
|
||||||
FListLink := TDBLookupDataLink.Create(Self);
|
FListLink := TDBLookupDataLink.Create(Self);
|
||||||
|
FDisplayEmpty := '';
|
||||||
|
FEmptyValue := '';
|
||||||
//FHasLookUpField := False;
|
//FHasLookUpField := False;
|
||||||
//FLookupCache := False;
|
//FLookupCache := False;
|
||||||
end;
|
end;
|
||||||
@ -281,8 +283,22 @@ begin
|
|||||||
ListLinkDataSet := FListLink.DataSet;
|
ListLinkDataSet := FListLink.DataSet;
|
||||||
if not (Assigned(ListLinkDataSet) and Assigned(FListField)) then
|
if not (Assigned(ListLinkDataSet) and Assigned(FListField)) then
|
||||||
Exit;
|
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;
|
Exit;
|
||||||
|
end;
|
||||||
Bookmark := ListLinkDataSet.GetBookmark;
|
Bookmark := ListLinkDataSet.GetBookmark;
|
||||||
//in fpc 2.6.4, TMemDataset does not supports BlockRead. Issues 26356, 27959
|
//in fpc 2.6.4, TMemDataset does not supports BlockRead. Issues 26356, 27959
|
||||||
{$IF FPC_FULLVERSION < 30000}
|
{$IF FPC_FULLVERSION < 30000}
|
||||||
@ -302,8 +318,18 @@ begin
|
|||||||
//needed to handle sqldb.TSQLQuery that does not has a reliable recordcount after Open
|
//needed to handle sqldb.TSQLQuery that does not has a reliable recordcount after Open
|
||||||
ListLinkDataSet.Last;
|
ListLinkDataSet.Last;
|
||||||
ListLinkDataSet.First;
|
ListLinkDataSet.First;
|
||||||
SetLength(FListKeys, ListLinkDataSet.RecordCount);
|
|
||||||
KeyListCount := 0;
|
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
|
while not ListLinkDataSet.EOF do
|
||||||
begin
|
begin
|
||||||
KeyIndex := FControlItems.Add(FListField.DisplayText);
|
KeyIndex := FControlItems.Add(FListField.DisplayText);
|
||||||
|
@ -21,6 +21,8 @@ constructor TDBLookupComboBox.Create(AOwner: TComponent);
|
|||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FLookup := TDBLookup.Create(Self);
|
FLookup := TDBLookup.Create(Self);
|
||||||
|
EmptyValue := '';
|
||||||
|
DisplayEmpty := '';
|
||||||
FDataLink.OnActiveChange := @ActiveChange;
|
FDataLink.OnActiveChange := @ActiveChange;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -68,6 +70,16 @@ begin
|
|||||||
UpdateLookup;
|
UpdateLookup;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TDBLookupComboBox.GetDisplayEmpty: String;
|
||||||
|
begin
|
||||||
|
Result := FLookup.DisplayEmpty;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDBLookupComboBox.GetEmptyValue: string;
|
||||||
|
begin
|
||||||
|
Result := FLookup.EmptyValue;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDBLookupComboBox.DataChange(Sender: TObject);
|
procedure TDBLookupComboBox.DataChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
UpdateItemIndex;
|
UpdateItemIndex;
|
||||||
@ -153,6 +165,18 @@ begin
|
|||||||
result := FLookup.NullValueKey;
|
result := FLookup.NullValueKey;
|
||||||
end;
|
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;
|
function TDBLookupComboBox.GetScrollListDataset: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := FLookup.ScrollListDataset;
|
Result := FLookup.ScrollListDataset;
|
||||||
|
@ -20,6 +20,8 @@ constructor TDBLookupListBox.Create(AOwner: TComponent);
|
|||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FLookup:= TDBLookup.Create(Self);
|
FLookup:= TDBLookup.Create(Self);
|
||||||
|
EmptyValue := '';
|
||||||
|
DisplayEmpty := '';
|
||||||
FDataLink.OnActiveChange:= @ActiveChange;
|
FDataLink.OnActiveChange:= @ActiveChange;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -41,6 +43,16 @@ begin
|
|||||||
UpdateLookup;
|
UpdateLookup;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TDBLookupListBox.GetDisplayEmpty: String;
|
||||||
|
begin
|
||||||
|
Result := FLookup.DisplayEmpty;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDBLookupListBox.GetEmptyValue: string;
|
||||||
|
begin
|
||||||
|
Result := FLookup.EmptyValue;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDBLookupListBox.DataChange(Sender: TObject);
|
procedure TDBLookupListBox.DataChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if FDatalink.Active then
|
if FDatalink.Active then
|
||||||
@ -134,6 +146,18 @@ begin
|
|||||||
Result := FLookup.NullValueKey;
|
Result := FLookup.NullValueKey;
|
||||||
end;
|
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;
|
function TDBLookupListBox.GetScrollListDataset: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := FLookup.ScrollListDataset;
|
Result := FLookup.ScrollListDataset;
|
||||||
|
Loading…
Reference in New Issue
Block a user