From 439af454afedd49085b8c3089c1cc241d8e6a741 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Thu, 22 Sep 2011 17:07:49 +0000 Subject: [PATCH] new property in TRxCollumn - DirectInput - allow select input values in RxDBGrid only from PickList git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1985 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi | 372 +++++------------- .../rx/Demos/RxDBGrid/rxdbgridmainunit.lfm | 92 +++-- .../rx/Demos/RxDBGrid/rxdbgridmainunit.pas | 1 + components/rx/docs/WhatsNew.rus.txt | 5 + components/rx/languages/rxconst.es.po | 6 +- components/rx/rxdbgrid.pas | 35 +- components/rx/rxmemds.pas | 120 +++++- 7 files changed, 322 insertions(+), 309 deletions(-) diff --git a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi index 7ef3a917f..01b396867 100644 --- a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi +++ b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi @@ -20,7 +20,7 @@ - + @@ -51,20 +51,18 @@ - + - + - - + - @@ -72,10 +70,11 @@ + - - + + @@ -215,55 +214,55 @@ - + - + - + - + - + - + - + - + @@ -272,47 +271,40 @@ - + - - - - - - - - + - - - + + + - - - + + + - - + + - - + + @@ -321,22 +313,22 @@ - - + + - - - + + + - - + + @@ -345,8 +337,8 @@ - - + + @@ -355,74 +347,51 @@ - - + + - - + + - - - + + + - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - + + + - - - + + + - - - + + + @@ -430,42 +399,32 @@ - - - - - - - - - - - - - + + + - - - + + + - - - + + + - - + + @@ -473,9 +432,9 @@ - - - + + + @@ -483,9 +442,9 @@ - - - + + + @@ -493,8 +452,8 @@ - - + + @@ -502,192 +461,59 @@ - - - - - - - - - - - - + + - - - - - - - - - - - - + + - - - - - - - - - - + + - - - - + + + - - - + + - - - + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + @@ -705,6 +531,10 @@ + + + + diff --git a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm index 0f386f67e..e845e8fa0 100644 --- a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm +++ b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm @@ -1,21 +1,21 @@ object RxDBGridMainForm: TRxDBGridMainForm Left = 299 Height = 786 - Top = 1 - Width = 1012 + Top = 6 + Width = 1187 ActiveControl = Panel1 Caption = 'RxDBGrid Demo' - ClientHeight = 759 - ClientWidth = 1012 + ClientHeight = 761 + ClientWidth = 1187 Menu = MainMenu1 OnCreate = FormCreate ShowHint = True LCLVersion = '0.9.31' object RxDBGrid1: TRxDBGrid Left = 0 - Height = 695 - Top = 64 - Width = 1012 + Height = 696 + Top = 65 + Width = 1187 TitleButtons = True AutoSort = True Columns = < @@ -141,6 +141,25 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + end + item + ButtonStyle = cbsPickList + PickList.Strings = ( + '' + 'Positive' + 'Negative' + ) + Title.Alignment = taCenter + Title.Caption = 'Rait' + Title.PrefixOption = poNone + Title.Orientation = toHorizontal + FieldName = 'RAIT' + Filter.Font.Style = [fsItalic] + Filter.DropDownRows = 0 + Filter.EmptyValue = '(Нет)' + Filter.EmptyFont.Style = [fsItalic] + Filter.ItemIndex = -1 + DirectInput = False end> KeyStrokes = < item @@ -195,22 +214,22 @@ object RxDBGridMainForm: TRxDBGridMainForm end object Panel1: TPanel Left = 0 - Height = 64 + Height = 65 Top = 0 - Width = 1012 + Width = 1187 Align = alTop AutoSize = True - ClientHeight = 64 - ClientWidth = 1012 + ClientHeight = 65 + ClientWidth = 1187 TabOrder = 1 object Label1: TLabel AnchorSideLeft.Control = Button2 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 269 + Left = 260 Height = 18 Top = 7 - Width = 37 + Width = 36 BorderSpacing.Around = 6 Caption = 'Mode' ParentColor = False @@ -219,9 +238,9 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = Panel1 Left = 7 - Height = 27 + Height = 29 Top = 7 - Width = 86 + Width = 84 Action = actCalcTotal AutoSize = True BorderSpacing.Around = 6 @@ -231,10 +250,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Button1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 99 - Height = 27 + Left = 97 + Height = 29 Top = 7 - Width = 164 + Width = 157 Action = actOptimizeColumnsWidthAll AutoSize = True BorderSpacing.Around = 6 @@ -245,11 +264,11 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = CheckBox2 AnchorSideTop.Side = asrBottom - Left = 498 + Left = 489 Height = 22 Hint = 'Use filter line' Top = 35 - Width = 84 + Width = 81 BorderSpacing.Left = 6 Caption = 'Use filter' OnChange = CheckBox1Change @@ -259,8 +278,8 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Label1 AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom - Left = 275 - Height = 25 + Left = 266 + Height = 27 Top = 31 Width = 217 BorderSpacing.Around = 6 @@ -279,11 +298,11 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = ComboBox1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 498 + Left = 489 Height = 22 Hint = 'Auto fill column width' Top = 7 - Width = 133 + Width = 129 BorderSpacing.Around = 6 Caption = 'Auto fill columns' OnChange = CheckBox2Change @@ -293,10 +312,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = CheckBox2 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 637 + Left = 624 Height = 22 Top = 7 - Width = 121 + Width = 117 BorderSpacing.Around = 6 Caption = 'Show indicator' Checked = True @@ -309,10 +328,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = CheckBox3 AnchorSideTop.Side = asrBottom - Left = 637 + Left = 624 Height = 22 Top = 35 - Width = 116 + Width = 114 BorderSpacing.Around = 6 Caption = 'Show headers' Checked = True @@ -359,6 +378,12 @@ object RxDBGridMainForm: TRxDBGridMainForm DataType = ftInteger Precision = 0 Size = 0 + end + item + Name = 'RAIT' + DataType = ftString + Precision = 0 + Size = 15 end> OnFilterRecord = RxMemoryData1FilterRecordEx OnFilterRecordEx = RxMemoryData1FilterRecordEx @@ -434,6 +459,17 @@ object RxDBGridMainForm: TRxDBGridMainForm ReadOnly = False Required = False end + object RxMemoryData1RAIT: TStringField + DisplayWidth = 15 + FieldKind = fkData + FieldName = 'RAIT' + Index = 6 + LookupCache = False + ProviderFlags = [pfInUpdate, pfInWhere] + ReadOnly = False + Required = False + Size = 15 + end end object Datasource1: TDatasource DataSet = RxMemoryData1 diff --git a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas index 77a5b48c1..ca34425bd 100644 --- a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas +++ b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas @@ -20,6 +20,7 @@ type MenuItem8: TMenuItem; MenuItem9: TMenuItem; RxAboutDialog1: TRxAboutDialog; + RxMemoryData1RAIT: TStringField; sysExit: TAction; hlpAbout: TAction; CheckBox2: TCheckBox; diff --git a/components/rx/docs/WhatsNew.rus.txt b/components/rx/docs/WhatsNew.rus.txt index 5eb328f21..187a4a178 100644 --- a/components/rx/docs/WhatsNew.rus.txt +++ b/components/rx/docs/WhatsNew.rus.txt @@ -66,6 +66,11 @@ добавлено новое свойство KeyStrokes + Добавлен новый компонент RxCurredit + Добавлен новый компонент- TRxViewsPanel + + + у компоненты TRxMemoryData убрана зависимость от модуля Forms + + Улучшено отображение редактора полей типа TDateTime/TDate в RxDBGrid + + У TRxCollumn компоненты TRxDBGrid для стиля cbsPickList добавлено свойство DirectInput. + Если оно установлено в false - значения поля можно выбрать только из выпадающего списка 22.05.2008 - версия 2.0.0.136 (svn revision 100) + У объекта TRxCustomDBLookupCombo введён контроль на CircularDataLink + У объекта TRxCustomDBLookupCombo ускорена отрисовка данных diff --git a/components/rx/languages/rxconst.es.po b/components/rx/languages/rxconst.es.po index a55ba7e6e..057e077dc 100644 --- a/components/rx/languages/rxconst.es.po +++ b/components/rx/languages/rxconst.es.po @@ -23,7 +23,7 @@ msgstr "" #: rxconst.sbuttonalign msgid "Button align" -msgstr "Alineacin de Botones" +msgstr "Alineaci?n de Botones" #: rxconst.sbuttonalign1 msgid "None" @@ -111,7 +111,7 @@ msgstr "Proximo Mes|" #: rxconst.snextyear msgid "Next Year|" -msgstr "Proximo Ao|" +msgstr "Proximo A?o|" #: rxconst.snotimplemented msgid "Function not yet implemented" @@ -131,7 +131,7 @@ msgstr "Anterior Mes|" #: rxconst.sprevyear msgid "Previous Year|" -msgstr "Anterior Ao|" +msgstr "Anterior A?o|" #: rxconst.sqtwidgetset msgid "QT widget set" diff --git a/components/rx/rxdbgrid.pas b/components/rx/rxdbgrid.pas index 7746e9541..2b4fc32a7 100644 --- a/components/rx/rxdbgrid.pas +++ b/components/rx/rxdbgrid.pas @@ -269,6 +269,7 @@ type TRxColumn = class(TColumn) private + FDirectInput: boolean; FFooter: TRxColumnFooter; FFilter: TRxColumnFilter; FImageList: TImageList; @@ -294,6 +295,7 @@ type property NotInKeyListIndex: integer read FNotInKeyListIndex write SetNotInKeyListIndex default -1; property Filter: TRxColumnFilter read FFilter write SetFilter; + property DirectInput : boolean read FDirectInput write FDirectInput default true; end; { TRxDbGridColumns } @@ -690,6 +692,7 @@ type procedure msg_SelectAll(var Msg: TGridMessage); message GM_SELECTALL; public + constructor Create(Aowner : TComponent); override; // procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override; procedure EditingDone; override; end; @@ -791,6 +794,17 @@ end; procedure TRxDBGridDateEditor.WndProc(var TheMessage: TLMessage); begin + if FGrid<>nil then + case TheMessage.Msg of + LM_CLEAR, + LM_CUT, + LM_PASTE: + begin + if FGrid.EditorIsReadOnly then + exit; + end; + end; + if TheMessage.msg = LM_KILLFOCUS then begin if HWND(TheMessage.WParam) = HWND(Handle) then @@ -829,6 +843,12 @@ begin SelectAll; end; +constructor TRxDBGridDateEditor.Create(Aowner: TComponent); +begin + inherited Create(Aowner); + AutoSize := false; +end; + {procedure TRxDBGridDateEditor.SetBounds(aLeft, aTop, aWidth, aHeight: integer); begin BeginUpdateBounds; @@ -945,6 +965,7 @@ begin inherited Create(AOwner); FLDS := TDataSource.Create(nil); LookupSource := FLDS; + AutoSize := false; end; destructor TRxDBGridLookupComboEditor.Destroy; @@ -983,7 +1004,7 @@ begin CnvW := Max(DrawRect.Right - DrawRect.Left, 1); W := (ACanvas.TextWidth(Text) div CnvW) + 1; - DrawRect.Top := ((ARect.Top + ARect.Bottom) div 2) - W * ACanvas.TextHeight('W') div 2; + DrawRect.Top := ((ARect.Top + ARect.Bottom) div 2) - W * ACanvas.TextHeight('Wg') div 2; if DrawRect.Top < ARect.Top + 1 then DrawRect.Top := ARect.Top + 1; @@ -2646,7 +2667,7 @@ end; function TRxDBGrid.IsDefaultRowHeightStored: boolean; begin - Result := DefaultRowHeight = Canvas.TextHeight('W'); + Result := DefaultRowHeight = Canvas.TextHeight('Wg'); end; procedure TRxDBGrid.VisualChange; @@ -2680,6 +2701,15 @@ begin end; end; Result := inherited EditorByStyle(Style); + + if (Style = cbsPickList) and (Result is TCustomComboBox) then + begin + if TRxColumn(SelectedColumn).DirectInput then + TCustomComboBox(Result).Style:=csDropDown + else + TCustomComboBox(Result).Style:=csDropDownList; + end; + end; procedure TRxDBGrid.CalcStatTotals; @@ -3191,6 +3221,7 @@ begin FNotInKeyListIndex := -1; FFooter := TRxColumnFooter.Create(Self); FFilter := TRxColumnFilter.Create(Self); + FDirectInput := true; end; destructor TRxColumn.Destroy; diff --git a/components/rx/rxmemds.pas b/components/rx/rxmemds.pas index 326de1965..ceb63aeb7 100644 --- a/components/rx/rxmemds.pas +++ b/components/rx/rxmemds.pas @@ -37,7 +37,7 @@ unit rxmemds; interface -uses SysUtils, Classes, Controls, DB, dbutils; +uses SysUtils, Classes, DB; { TRxMemoryData } @@ -234,7 +234,7 @@ type implementation -uses Forms, rxdconst, dbconst, Variants; +uses CustApp, rxdconst, dbconst, Variants, math; const ftBlobTypes = [ftBlob, ftMemo, ftGraphic, ftFmtMemo, ftParadoxOle, @@ -984,7 +984,8 @@ begin OnFilterRecord(Self, Result); {$ENDIF} except - Application.HandleException(Self); +// Application.HandleException(Self); + CustomApplication.HandleException(Self); end; RestoreState(SaveState); end @@ -1241,7 +1242,8 @@ end; procedure TRxMemoryData.InternalHandleException; begin - Application.HandleException(Self); + CustomApplication.HandleException(Self); + //Application.HandleException(Self); end; procedure TRxMemoryData.InternalInitFieldDefs; @@ -1282,6 +1284,84 @@ begin Result := not Filtered; end; +{ DataSet locate routines } +function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string; + const KeyValues: Variant; Options: TLocateOptions): Boolean; +var + FieldCount: Integer; + Fields: TList; + Bookmark: TBookmarkStr; + + function CompareField(Field: TField; Value: Variant): Boolean; + var + S,S1: string; + + begin + if Field.DataType = ftString then + begin + S := Field.AsString; + S1:=Value; + if (loPartialKey in Options) then + Delete(S, Length(S1) + 1, MaxInt); + + if (loCaseInsensitive in Options) then + Result := AnsiCompareText(S, S1) = 0 + else + Result := AnsiCompareStr(S, S1) = 0; + end +// else Result := false //(Field.Value = Value); + else Result := (Field.Value = Value); + end; + + function CompareRecord: Boolean; + var + I: Integer; + begin + if FieldCount = 1 then + Result := CompareField(TField(Fields.First), KeyValues) + else begin + Result := True; + for I := 0 to FieldCount - 1 do + Result := Result and CompareField(TField(Fields[I]), KeyValues[I]); + end; + end; + +begin + Result := False; + with DataSet do begin + CheckBrowseMode; + if BOF and EOF then Exit; + end; + Fields := TList.Create; + try + DataSet.GetFieldList(Fields, KeyFields); + FieldCount := Fields.Count; + Result := CompareRecord; + if Result then Exit; + DataSet.DisableControls; + try + Bookmark := DataSet.Bookmark; + try + with DataSet do begin + First; + while not EOF do begin + Result := CompareRecord; + if Result then Break; + Next; + end; + end; + finally + if not Result and DataSet.BookmarkValid(PChar(Bookmark)) then + DataSet.Bookmark := Bookmark; + end; + finally + DataSet.EnableControls; + end; + finally + Fields.Free; + end; +end; + function TRxMemoryData.Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; begin @@ -1344,6 +1424,35 @@ begin CheckDataTypes(FieldDefs); CreateFields; end; +procedure AssignRecord(Source, Dest: TDataSet; ByName: Boolean); +var + I: Integer; + F, FSrc: TField; +begin +// if not (Dest.State in dsEditModes) then DBError(SNotEditing); + if ByName then begin + for I := 0 to Source.FieldCount - 1 do begin + F := Dest.FindField(Source.Fields[I].FieldName); + if F <> nil then begin + if (F.DataType = Source.Fields[I].DataType) and + (F.DataSize = Source.Fields[I].DataSize) then + F.Assign(Source.Fields[I]) + else F.AsString := Source.Fields[I].AsString; + end; + end; + end + else begin + for I := 0 to Min(Source.FieldDefs.Count - 1, Dest.FieldDefs.Count - 1) do + begin + F := Dest.FindField(Dest.FieldDefs[I].Name); + FSrc := Source.FindField(Source.FieldDefs[I].Name); + if (F <> nil) and (FSrc <> nil) then begin + if F.DataType = FSrc.DataType then F.Assign(FSrc) + else F.AsString := FSrc.AsString; + end; + end; + end; +end; function TRxMemoryData.LoadFromDataSet(Source: TDataSet; ARecordCount: Integer; Mode: TLoadMode): Integer; @@ -1614,7 +1723,8 @@ begin try FDataSet.DataEvent(deFieldChange, ptrint(FField)); except - Application.HandleException(Self); + CustomApplication.HandleException(Self); +// Application.HandleException(Self); end; end;