You've already forked lazarus-ccr
new editor in RxDBGrid for lookup fields from dataset
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@283 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
- In TCurrencyEdit property BorderSpacing now published
|
||||
+ New procedure StrToStrings in module rxstrutils - fill List:TStrings
|
||||
procedure StrToStrings(const S:string; const List:TStrings; const Delims:Char);
|
||||
+ New editor for TField object with Lookup source in TRxDBGrid - base on class TRxDBLookupCombo
|
||||
29.08.2007 - ������ 1.1.5.98 (svn revision 39)
|
||||
+ In RxDBgrid - after close dataset list of SelectedRows is cleared
|
||||
+ fix resaizing find form for RxDbGrd
|
||||
|
@@ -21,6 +21,8 @@
|
||||
TRxLookupEdit � TRxDBLookupCombo
|
||||
+ TRxDBLookupCombo ����������� ��������� �������� AutoSize
|
||||
+ ��� ��������� �������� Font � TRxDBLookupCombo ���������� ������ ���������� ���� �� �����
|
||||
+ ���� � ������� TField ������������ �������� ��������� �� ��� �������������� � RxDBGrid
|
||||
������ ���� ���������� �������� �� ������ TRxDBLookupCombo
|
||||
29.08.2007 - ������ 1.1.5.98 (svn revision 39)
|
||||
+ � RxDBGrid ����� �������� ������ ������ ������ ���������� ����� (SelectedRows)
|
||||
���������
|
||||
|
@@ -228,6 +228,7 @@ type
|
||||
|
||||
FVersion: Integer;
|
||||
FPropertyStorageLink:TPropertyStorageLink;
|
||||
FRxDbGridLookupComboEditor:TCustomControl;
|
||||
|
||||
function GetColumns: TRxDbGridColumns;
|
||||
function GetPropertyStorage: TCustomPropertyStorage;
|
||||
@@ -279,6 +280,7 @@ type
|
||||
procedure FFilterListEditorOnCloseUp(Sender: TObject);
|
||||
procedure InternalOptimizeColumnsWidth(AColList:TList);
|
||||
function IsDefaultRowHeightStored:boolean;
|
||||
function EditorByStyle(Style: TColumnButtonStyle): TWinControl; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@@ -390,52 +392,10 @@ type
|
||||
property OnUserCheckboxBitmap;
|
||||
end;
|
||||
|
||||
{
|
||||
type
|
||||
PCharArray1 = Array[0..12] of PChar;
|
||||
|
||||
|
||||
const
|
||||
IMGMarkerUp : PCharArray1 =
|
||||
(
|
||||
'10 9 3 1',
|
||||
'. c None',
|
||||
'# c #808080',
|
||||
'a c #ffffff',
|
||||
|
||||
'..........',
|
||||
'....#a....',
|
||||
'...#..a...',
|
||||
'...#..a...',
|
||||
'..#....a..',
|
||||
'..#....a..',
|
||||
'.#......a.',
|
||||
'.aaaaaaaa.',
|
||||
'..........'
|
||||
);
|
||||
|
||||
IMGMarkerDown : PCharArray1 =
|
||||
(
|
||||
'10 9 3 1',
|
||||
'. c None',
|
||||
'# c #808080',
|
||||
'a c #ffffff',
|
||||
'..........',
|
||||
'.#######a.',
|
||||
'.#......a.',
|
||||
'..#....a..',
|
||||
'..#....a..',
|
||||
'...#..a...',
|
||||
'...#..a...',
|
||||
'....#a....',
|
||||
'..........')
|
||||
;
|
||||
}
|
||||
|
||||
procedure RegisterExDBGridSortEngine(ExDBGridSortEngineClass:TExDBGridSortEngineClass; DataSetClass:TDataSetClass);
|
||||
|
||||
implementation
|
||||
uses Math, rxdconst, rxstrutils, rxdbgrid_findunit, rxdbgrid_columsunit;
|
||||
uses Math, rxdconst, rxstrutils, rxdbgrid_findunit, rxdbgrid_columsunit, rxlookup;
|
||||
|
||||
var
|
||||
ExDBGridSortEngineList:TStringList;
|
||||
@@ -460,6 +420,101 @@ begin
|
||||
for I := 0 to Grid.ColCount - 1 do Grid.InvalidateCell(I, Row);
|
||||
end;
|
||||
|
||||
type
|
||||
|
||||
{ TRxDBGridLookupComboEditor }
|
||||
|
||||
TRxDBGridLookupComboEditor = class(TRxCustomDBLookupCombo)
|
||||
private
|
||||
FGrid: TRxDBGrid;
|
||||
FCol,FRow: Integer;
|
||||
FLDS:TDataSource;
|
||||
protected
|
||||
procedure WndProc(var TheMessage : TLMessage); override;
|
||||
procedure KeyDown(var Key : Word; Shift : TShiftState); override;
|
||||
procedure msg_SetGrid(var Msg: TGridMessage); message GM_SETGRID;
|
||||
procedure msg_SetValue(var Msg: TGridMessage); message GM_SETVALUE;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TRxDBGridLookupComboEditor }
|
||||
|
||||
procedure TRxDBGridLookupComboEditor.WndProc(var TheMessage: TLMessage);
|
||||
begin
|
||||
if TheMessage.msg=LM_KILLFOCUS then
|
||||
begin
|
||||
if HWND(TheMessage.WParam) = HWND(Handle) then
|
||||
begin
|
||||
// lost the focus but it returns to ourselves
|
||||
// eat the message.
|
||||
TheMessage.Result := 0;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
inherited WndProc(TheMessage);
|
||||
end;
|
||||
|
||||
procedure TRxDBGridLookupComboEditor.KeyDown(var Key: Word; Shift: TShiftState
|
||||
);
|
||||
|
||||
procedure doGridKeyDown;
|
||||
begin
|
||||
if Assigned(FGrid) then
|
||||
FGrid.KeyDown(Key, shift);
|
||||
end;
|
||||
|
||||
begin
|
||||
case Key of
|
||||
VK_UP,
|
||||
VK_DOWN :
|
||||
if (not PopupVisible) and (not (ssAlt in Shift)) then
|
||||
begin
|
||||
doGridKeyDown;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
inherited KeyDown(Key, Shift);
|
||||
end;
|
||||
|
||||
procedure TRxDBGridLookupComboEditor.msg_SetGrid(var Msg: TGridMessage);
|
||||
begin
|
||||
FGrid:=Msg.Grid as TRxDBGrid;
|
||||
Msg.Options:=EO_AUTOSIZE;
|
||||
end;
|
||||
|
||||
procedure TRxDBGridLookupComboEditor.msg_SetValue(var Msg: TGridMessage);
|
||||
var
|
||||
F, LF:TField;
|
||||
begin
|
||||
FCol := Msg.Col;
|
||||
FRow := Msg.Row;
|
||||
F:=FGrid.SelectedField;
|
||||
DataSource:=FGrid.DataSource;
|
||||
if Assigned(F) then
|
||||
begin
|
||||
DataField:=F.FieldName;
|
||||
LookupDisplay:=F.LookupKeyFields;
|
||||
LookupField:=F.LookupResultField;
|
||||
FLDS.DataSet:=F.LookupDataSet;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
constructor TRxDBGridLookupComboEditor.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FLDS:=TDataSource.Create(nil);
|
||||
LookupSource:=FLDS;
|
||||
end;
|
||||
|
||||
destructor TRxDBGridLookupComboEditor.Destroy;
|
||||
begin
|
||||
FreeAndNil(FLDS);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TRxDBGrid }
|
||||
const
|
||||
ALIGN_FLAGS: array[TAlignment] of Integer =
|
||||
@@ -1016,7 +1071,10 @@ begin
|
||||
begin
|
||||
if F.dataType <> ftBlob then
|
||||
begin
|
||||
S := F.DisplayText;
|
||||
{ if Assigned(F.LookupDataSet) and (F.LookupResultField<>'') then
|
||||
S := F.LookupDataSet.FieldByName(F.LookupResultField).DisplayText
|
||||
else}
|
||||
S := F.DisplayText;
|
||||
if Assigned(C) and (C.KeyList.Count > 0) and (C.PickList.Count>0) then
|
||||
begin
|
||||
J:=C.KeyList.IndexOf(S);
|
||||
@@ -1545,6 +1603,25 @@ begin
|
||||
Result:=DefaultRowHeight = Canvas.TextHeight('W');
|
||||
end;
|
||||
|
||||
function TRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;
|
||||
var
|
||||
F:TField;
|
||||
begin
|
||||
if Style = cbsAuto then
|
||||
begin
|
||||
F:=SelectedField;
|
||||
if Assigned(F) then
|
||||
begin
|
||||
if Assigned(F.LookupDataSet) and (F.LookupKeyFields<>'') and (F.LookupResultField<>'') and (F.KeyFields<>'') then
|
||||
begin
|
||||
Result:=FRxDbGridLookupComboEditor;
|
||||
exit;
|
||||
end
|
||||
end
|
||||
end;
|
||||
Result:=inherited EditorByStyle(Style);
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid.CalcStatTotals;
|
||||
var
|
||||
P:TBookmark;
|
||||
@@ -1659,10 +1736,15 @@ begin
|
||||
OnCloseUp := @FFilterListEditorOnCloseUp;
|
||||
end;
|
||||
FColumnResizing := false;
|
||||
|
||||
FRxDbGridLookupComboEditor:=TRxDBGridLookupComboEditor.Create(nil);
|
||||
FRxDbGridLookupComboEditor.Name:='RxDBGridLookupComboEditor';
|
||||
FRxDbGridLookupComboEditor.Visible:=false;
|
||||
end;
|
||||
|
||||
destructor TRxDBGrid.Destroy;
|
||||
begin
|
||||
FreeAndNil(FRxDbGridLookupComboEditor);
|
||||
FreeAndNil(FMarkerDown);
|
||||
FreeAndNil(FMarkerUp);
|
||||
FreeAndNil(FPropertyStorageLink);
|
||||
|
@@ -175,13 +175,13 @@ type
|
||||
procedure DataLinkActiveChanged;
|
||||
procedure DataLinkRecordChanged(Field: TField);
|
||||
procedure UpdateFieldValues;
|
||||
procedure ShowList;
|
||||
procedure SetValueKey(const Value: string);
|
||||
procedure UpdateKeyValue;
|
||||
procedure KeyValueChanged;
|
||||
procedure UpdateData;
|
||||
procedure OnClosePopup(AResult:boolean);
|
||||
protected
|
||||
procedure ShowList; virtual;
|
||||
procedure OnClosePopup(AResult:boolean);virtual;
|
||||
procedure DoAutoSize; override;
|
||||
procedure SetEnabled(Value: Boolean); override;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
@@ -234,6 +234,8 @@ type
|
||||
|
||||
{ TRxDBLookupCombo }
|
||||
TRxDBLookupCombo = class(TRxCustomDBLookupCombo)
|
||||
protected
|
||||
procedure OnClosePopup(AResult:boolean);override;
|
||||
published
|
||||
property AutoSize;
|
||||
property Align;
|
||||
@@ -924,7 +926,7 @@ begin
|
||||
FLookupDataLink.DataSet.First;
|
||||
|
||||
FRxPopUpForm:=ShowRxDBPopUpForm(Self, FLookupDataLink.DataSet, @OnClosePopup,
|
||||
FPopUpFormOptions, FLookupDisplay, LookupDisplayIndex, ButtonWidth, Font);
|
||||
FPopUpFormOptions, FLookupDisplay, LookupDisplayIndex, 0 {ButtonWidth}, Font);
|
||||
end
|
||||
end;
|
||||
|
||||
@@ -975,11 +977,6 @@ begin
|
||||
FDataLink.Edit;
|
||||
UpdateData;
|
||||
end;
|
||||
SetFocus;
|
||||
if (Owner is TWinControl) then
|
||||
TWinControl(Owner).Repaint
|
||||
else
|
||||
Parent.Repaint;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBLookupCombo.DoAutoSize;
|
||||
@@ -1326,4 +1323,16 @@ begin
|
||||
FDataControl.LookupDataSetChanged;
|
||||
end;
|
||||
|
||||
{ TRxDBLookupCombo }
|
||||
|
||||
procedure TRxDBLookupCombo.OnClosePopup(AResult: boolean);
|
||||
begin
|
||||
inherited OnClosePopup(AResult);
|
||||
SetFocus;
|
||||
if (Owner is TWinControl) then
|
||||
TWinControl(Owner).Repaint
|
||||
else
|
||||
Parent.Repaint;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user