You've already forked lazarus-ccr
fix in RxDBLoockupcombo and in Popup window from Aleksey Kozlov
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@788 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -11,11 +11,14 @@ uses
|
|||||||
|
|
||||||
const
|
const
|
||||||
TextMargin = 5;
|
TextMargin = 5;
|
||||||
|
|
||||||
type
|
type
|
||||||
TRxCustomDBLookupCombo = class;
|
TRxCustomDBLookupCombo = class;
|
||||||
TRxCustomDBLookupEdit = class;
|
TRxCustomDBLookupEdit = class;
|
||||||
|
|
||||||
|
{For deciding, what we need to show in combobox in case we cannot find curvalue in lookup table.}
|
||||||
|
TRxDBValueVariant = (rxufNone, rxufLastSuccessful, rxufOriginal);
|
||||||
|
|
||||||
{ TLookupSourceLink }
|
{ TLookupSourceLink }
|
||||||
TDataSourceLink = class(TDataLink)
|
TDataSourceLink = class(TDataLink)
|
||||||
private
|
private
|
||||||
@@ -139,6 +142,8 @@ type
|
|||||||
FOnButtonClick : TNotifyEvent;
|
FOnButtonClick : TNotifyEvent;
|
||||||
FReadOnly: boolean;
|
FReadOnly: boolean;
|
||||||
FDisplayAll: boolean;
|
FDisplayAll: boolean;
|
||||||
|
FUnfindedValue: TRxDBValueVariant;
|
||||||
|
FSuccesfullyFind : boolean;
|
||||||
function GetDataSource: TDataSource;
|
function GetDataSource: TDataSource;
|
||||||
function GetDisplayAll: Boolean;
|
function GetDisplayAll: Boolean;
|
||||||
function GetDropDownCount: Integer;
|
function GetDropDownCount: Integer;
|
||||||
@@ -186,6 +191,7 @@ type
|
|||||||
procedure UpdateKeyValue;
|
procedure UpdateKeyValue;
|
||||||
procedure KeyValueChanged;
|
procedure KeyValueChanged;
|
||||||
procedure UpdateData;
|
procedure UpdateData;
|
||||||
|
procedure NeedUpdateData;
|
||||||
protected
|
protected
|
||||||
procedure ShowList; virtual;
|
procedure ShowList; virtual;
|
||||||
procedure OnClosePopup(AResult:boolean);virtual;
|
procedure OnClosePopup(AResult:boolean);virtual;
|
||||||
@@ -203,6 +209,8 @@ type
|
|||||||
procedure CMVisibleChanged(var Msg: TLMessage); message CM_VISIBLECHANGED;
|
procedure CMVisibleChanged(var Msg: TLMessage); message CM_VISIBLECHANGED;
|
||||||
procedure CMEnabledChanged(var Msg: TLMessage); message CM_ENABLEDCHANGED;
|
procedure CMEnabledChanged(var Msg: TLMessage); message CM_ENABLEDCHANGED;
|
||||||
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
||||||
|
procedure Click; override;
|
||||||
|
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
|
|
||||||
procedure LookupDataSetChanged(Sender: TObject); virtual;
|
procedure LookupDataSetChanged(Sender: TObject); virtual;
|
||||||
@@ -234,6 +242,7 @@ type
|
|||||||
property LookupSource: TDataSource read GetLookupSource write SetLookupSource;
|
property LookupSource: TDataSource read GetLookupSource write SetLookupSource;
|
||||||
property OnGetGridCellProps: TGetCellPropsEvent read GetOnGetGridCellProps
|
property OnGetGridCellProps: TGetCellPropsEvent read GetOnGetGridCellProps
|
||||||
write SetOnGetGridCellProps;
|
write SetOnGetGridCellProps;
|
||||||
|
property UnfindedValue : TRxDBValueVariant read FUnfindedValue write FUnfindedValue default rxufNone;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@@ -302,6 +311,7 @@ type
|
|||||||
property LookupDisplayIndex;
|
property LookupDisplayIndex;
|
||||||
property LookupField;
|
property LookupField;
|
||||||
property LookupSource;
|
property LookupSource;
|
||||||
|
property UnfindedValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@@ -504,10 +514,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
DataSet := FLookupDataLink.DataSet;
|
DataSet := FLookupDataLink.DataSet;
|
||||||
FKeyField := DataSet.FieldByName(FLookupField);
|
FKeyField := DataSet.FieldByName(FLookupField);
|
||||||
end;
|
end;
|
||||||
FLocateObject.DataSet := DataSet;
|
FLocateObject.DataSet := DataSet;
|
||||||
|
|
||||||
|
|
||||||
UpdateKeyValue
|
UpdateKeyValue
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -809,14 +818,14 @@ begin
|
|||||||
else
|
else
|
||||||
ACanvas.Pen.Color := clBtnShadow;
|
ACanvas.Pen.Color := clBtnShadow;
|
||||||
LastIndex := FValuesList.Count-1;
|
LastIndex := FValuesList.Count-1;
|
||||||
TxtWidth := ACanvas.TextWidth('M');
|
TxtWidth := ACanvas.TextWidth('W');
|
||||||
ATop := Max(0, (HeightOf(R) - ACanvas.TextHeight('Xy')) div 2);
|
ATop := Max(0, (HeightOf(R) - ACanvas.TextHeight('Xy')) div 2);
|
||||||
ARight := R.Right;
|
ARight := R.Right;
|
||||||
Inc(R.Left, ALeft);
|
Inc(R.Left, ALeft);
|
||||||
for I := 0 to LastIndex do
|
for I := 0 to LastIndex do
|
||||||
begin
|
begin
|
||||||
F:=LookupSource.DataSet.FieldByName(FFieldList[i]);
|
F:=LookupSource.DataSet.FieldByName(FFieldList[i]);
|
||||||
S := FValuesList[i];// F.DisplayText;
|
S := FValuesList[i];
|
||||||
|
|
||||||
if FPopUpFormOptions.Columns.Count>i then
|
if FPopUpFormOptions.Columns.Count>i then
|
||||||
W := FPopUpFormOptions.Columns[i].Width
|
W := FPopUpFormOptions.Columns[i].Width
|
||||||
@@ -895,7 +904,7 @@ begin
|
|||||||
else
|
else
|
||||||
SetValueKey(FEmptyValue);
|
SetValueKey(FEmptyValue);
|
||||||
end
|
end
|
||||||
{ else
|
{else
|
||||||
SetValueKey(Field.AsString);}
|
SetValueKey(Field.AsString);}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -911,12 +920,20 @@ begin
|
|||||||
FValuesList.Add(FEmptyValue)
|
FValuesList.Add(FEmptyValue)
|
||||||
else
|
else
|
||||||
if FLookupDataLink.Active then
|
if FLookupDataLink.Active then
|
||||||
for i:=0 to FFieldList.Count-1 do
|
if (Self.FSuccesfullyFind) or (Self.UnfindedValue = rxufLastSuccessful) then
|
||||||
begin
|
begin
|
||||||
F:=FLookupDataLink.DataSet.FieldByName(FFieldList[i]);
|
for i:=0 to FFieldList.Count-1 do
|
||||||
k:=FValuesList.Add(F.DisplayText);
|
begin
|
||||||
FValuesList.Objects[k]:=TObject(PtrInt(F.DisplayWidth));
|
F:=FLookupDataLink.DataSet.FieldByName(FFieldList[i]);
|
||||||
end;
|
k:=FValuesList.Add(F.DisplayText);
|
||||||
|
FValuesList.Objects[k]:=TObject(PtrInt(F.DisplayWidth));
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
case Self.UnfindedValue of
|
||||||
|
rxufNone : {Do nothing};
|
||||||
|
rxufOriginal : FValuesList.Add(FValue);//Show original field value...
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -929,7 +946,10 @@ begin
|
|||||||
if FDataField <> nil then FValue := FDataField.AsString
|
if FDataField <> nil then FValue := FDataField.AsString
|
||||||
else FValue := FEmptyValue;
|
else FValue := FEmptyValue;
|
||||||
if Assigned(FDataField) and not FDataField.IsNull then
|
if Assigned(FDataField) and not FDataField.IsNull then
|
||||||
FLocateObject.Locate(FLookupField, FValue, true, false)
|
Begin
|
||||||
|
if not FLocateObject.Locate(FLookupField, FValue, true, false) then
|
||||||
|
FLookupDataLink.DataSet.First;//In case we cannot find curvalue...
|
||||||
|
End
|
||||||
else
|
else
|
||||||
if FLookupDataLink.Active then
|
if FLookupDataLink.Active then
|
||||||
FLookupDataLink.DataSet.First;
|
FLookupDataLink.DataSet.First;
|
||||||
@@ -947,7 +967,7 @@ begin
|
|||||||
FValue := Value;
|
FValue := Value;
|
||||||
if Assigned(FLookupDataLink.DataSet) and (FLookupDataLink.DataSet.Active) then
|
if Assigned(FLookupDataLink.DataSet) and (FLookupDataLink.DataSet.Active) then
|
||||||
begin
|
begin
|
||||||
FLocateObject.Locate(FLookupField, FValue, true, false);
|
FSuccesfullyFind := FLocateObject.Locate(FLookupField, FValue, true, false);
|
||||||
KeyValueChanged;
|
KeyValueChanged;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -955,10 +975,12 @@ end;
|
|||||||
|
|
||||||
procedure TRxCustomDBLookupCombo.UpdateKeyValue;
|
procedure TRxCustomDBLookupCombo.UpdateKeyValue;
|
||||||
begin
|
begin
|
||||||
if FDataField <> nil then FValue := FDataField.AsString
|
if FDataField <> nil then
|
||||||
else FValue := FEmptyValue;
|
FValue := FDataField.AsString
|
||||||
|
else
|
||||||
|
FValue := FEmptyValue;
|
||||||
if not FDataField.IsNull then
|
if not FDataField.IsNull then
|
||||||
FLocateObject.Locate(FLookupField, FValue, true, false);
|
FSuccesfullyFind := FLocateObject.Locate(FLookupField, FValue, true, false);
|
||||||
KeyValueChanged;
|
KeyValueChanged;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -970,11 +992,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRxCustomDBLookupCombo.UpdateData;
|
procedure TRxCustomDBLookupCombo.UpdateData;
|
||||||
|
begin
|
||||||
|
//We have nothing to do here...
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRxCustomDBLookupCombo.NeedUpdateData;
|
||||||
begin
|
begin
|
||||||
if FLookupDataLink.Active and Assigned(FDataField) then
|
if FLookupDataLink.Active and Assigned(FDataField) then
|
||||||
begin
|
begin ;
|
||||||
if FKeyField.IsNull then FDataField.Clear
|
if FKeyField.IsNull then FDataField.Clear
|
||||||
else FDataField.AsString:=FKeyField.AsString;
|
else FDataField.AsString:=FKeyField.AsString
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -987,7 +1014,7 @@ begin
|
|||||||
if AResult and Assigned(FDataLink.DataSource) then
|
if AResult and Assigned(FDataLink.DataSource) then
|
||||||
begin
|
begin
|
||||||
FDataLink.Edit;
|
FDataLink.Edit;
|
||||||
UpdateData;
|
NeedUpdateData;//We need to update DataField;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -1037,7 +1064,8 @@ begin
|
|||||||
FDataLink.Edit;
|
FDataLink.Edit;
|
||||||
if not FDataField.IsNull then
|
if not FDataField.IsNull then
|
||||||
begin
|
begin
|
||||||
FLocateObject.Locate(FLookupField, FDataField.AsString, true, false);
|
//FLocateObject.Locate(FLookupField, FDataField.AsString, true, false);
|
||||||
|
If not FLocateObject.Locate(FLookupField, FDataField.AsString, true, false) then FLookupDataLink.DataSet.First;
|
||||||
case Key of
|
case Key of
|
||||||
VK_UP: if not FLookupDataLink.DataSet.BOF then
|
VK_UP: if not FLookupDataLink.DataSet.BOF then
|
||||||
FLookupDataLink.DataSet.Prior;
|
FLookupDataLink.DataSet.Prior;
|
||||||
@@ -1045,11 +1073,13 @@ begin
|
|||||||
FLookupDataLink.DataSet.Next;
|
FLookupDataLink.DataSet.Next;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
FDataLink.UpdateRecord;
|
//FDataLink.UpdateRecord; -- no need more...
|
||||||
|
Self.NeedUpdateData;
|
||||||
KeyValueChanged;
|
KeyValueChanged;
|
||||||
Key:=0;
|
Key:=0;
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRxCustomDBLookupCombo.KeyPress(var Key: char);
|
procedure TRxCustomDBLookupCombo.KeyPress(var Key: char);
|
||||||
@@ -1099,14 +1129,15 @@ end;
|
|||||||
|
|
||||||
procedure TRxCustomDBLookupCombo.DoButtonClick(Sender: TObject);
|
procedure TRxCustomDBLookupCombo.DoButtonClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if not FReadOnly then
|
if not FReadOnly then//We can do something if and only if that's not ReadOnly field...
|
||||||
|
Begin
|
||||||
if Assigned(FOnButtonClick) then
|
if Assigned(FOnButtonClick) then
|
||||||
FOnButtonClick(Self);
|
FOnButtonClick(Self);
|
||||||
|
|
||||||
{ if PopupVisible then
|
{ if PopupVisible then
|
||||||
HideList
|
HideList
|
||||||
else}
|
else}
|
||||||
ShowList;
|
ShowList;
|
||||||
|
End;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRxCustomDBLookupCombo.Loaded;
|
procedure TRxCustomDBLookupCombo.Loaded;
|
||||||
@@ -1139,10 +1170,16 @@ end;
|
|||||||
procedure TRxCustomDBLookupCombo.MouseDown(Button: TMouseButton;
|
procedure TRxCustomDBLookupCombo.MouseDown(Button: TMouseButton;
|
||||||
Shift: TShiftState; X, Y: Integer);
|
Shift: TShiftState; X, Y: Integer);
|
||||||
begin
|
begin
|
||||||
inherited MouseDown(Button, Shift, X, Y);
|
inherited MouseDown(Button,Shift, X, Y);
|
||||||
DoButtonClick(Self);
|
{ If not Self.PopupVisible then
|
||||||
|
DoButtonClick(Self);}
|
||||||
|
end;
|
||||||
|
procedure TRxCustomDBLookupCombo.Click;
|
||||||
|
begin
|
||||||
|
inherited Click;
|
||||||
|
If not Self.PopupVisible then
|
||||||
|
DoButtonClick(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRxCustomDBLookupCombo.Paint;
|
procedure TRxCustomDBLookupCombo.Paint;
|
||||||
var
|
var
|
||||||
Selected:boolean;
|
Selected:boolean;
|
||||||
@@ -1236,6 +1273,7 @@ begin
|
|||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
Height := 23;
|
Height := 23;
|
||||||
Width := 100;
|
Width := 100;
|
||||||
|
FUnfindedValue:=rxufNone;
|
||||||
FFieldList := TStringList.Create;
|
FFieldList := TStringList.Create;
|
||||||
FValuesList:= TStringList.Create;
|
FValuesList:= TStringList.Create;
|
||||||
FLocateObject:=CreateLocate(nil);
|
FLocateObject:=CreateLocate(nil);
|
||||||
|
@@ -201,7 +201,6 @@ procedure FillPopupWidth(APopUpFormOptions:TPopUpFormOptions; ARxPopUpForm:TPopU
|
|||||||
implementation
|
implementation
|
||||||
uses dbutils, math;
|
uses dbutils, math;
|
||||||
|
|
||||||
{.$DEFINE LINUX}
|
|
||||||
function ShowRxDBPopUpForm(AControl:TWinControl; ADataSet:TDataSet;
|
function ShowRxDBPopUpForm(AControl:TWinControl; ADataSet:TDataSet;
|
||||||
AOnPopUpCloseEvent:TPopUpCloseEvent; APopUpFormOptions:TPopUpFormOptions;
|
AOnPopUpCloseEvent:TPopUpCloseEvent; APopUpFormOptions:TPopUpFormOptions;
|
||||||
AFieldList:string; ALookupDisplayIndex, BtnWidtn: integer; const Font:TFont):TPopUpForm;
|
AFieldList:string; ALookupDisplayIndex, BtnWidtn: integer; const Font:TFont):TPopUpForm;
|
||||||
@@ -242,7 +241,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPopUpForm }
|
{ TPopUpForm }
|
||||||
|
|
||||||
procedure TPopUpForm.SetDataSet(const AValue: TDataSet);
|
procedure TPopUpForm.SetDataSet(const AValue: TDataSet);
|
||||||
begin
|
begin
|
||||||
if FDataSource.DataSet=AValue then exit;
|
if FDataSource.DataSet=AValue then exit;
|
||||||
@@ -287,7 +285,10 @@ procedure TPopUpForm.KeyDown(var Key: Word; Shift: TShiftState);
|
|||||||
begin
|
begin
|
||||||
case Key of
|
case Key of
|
||||||
VK_ESCAPE:Deactivate;
|
VK_ESCAPE:Deactivate;
|
||||||
VK_RETURN:CloseOk;
|
VK_RETURN:begin
|
||||||
|
CloseOk;
|
||||||
|
exit;{In that case we need to exit away.}
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
inherited KeyDown(Key, Shift);
|
inherited KeyDown(Key, Shift);
|
||||||
end;
|
end;
|
||||||
@@ -466,7 +467,6 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
FGrid.Anchors:=[akLeft, akRight, akTop, akBottom];
|
FGrid.Anchors:=[akLeft, akRight, akTop, akBottom];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//Set options
|
//Set options
|
||||||
if not (pfgIndicator in FPopUpFormOptions.FOptions) then
|
if not (pfgIndicator in FPopUpFormOptions.FOptions) then
|
||||||
FGrid.Options:=FGrid.Options - [dgIndicator];
|
FGrid.Options:=FGrid.Options - [dgIndicator];
|
||||||
|
Reference in New Issue
Block a user