Filtration Condition Defining Form (Old)

xiaoxiao2021-03-06  112

/ / =========================================================================================================================================================================================== ======================================== 国辉 // Date: 2004-07-20 // Site: http: //kacarton.yeah .NET /// blog: http://blog.9cbs.net/nhconch/ Email: kacarton@sohu.com// The article is the author, please do not reprint! // My blog: Programming Handbook http://blog.9cbs.net/nhconch//============================= ===================================================

frm file content :( click to open or folded) object frmTFilter: TfrmTFilter Left = 199 Top = 117 BorderStyle = bsDialog Caption = 'defined filter criteria' ClientHeight = 343 ClientWidth = 628 Color = clBtnFace Font.Charset = GB2312_CHARSET Font.Color = clWindowText Font .Height = -12 Font.Name = 'Arial' Font.Style = [] OldCreateOrder = False Position = poOwnerFormCenter ShowHint = True OnCreate = FormCreate OnDestroy = FormDestroy DesignSize = (628 343) PixelsPerInch = 96 TextHeight = 12 object btnInfo1: TSpeedButton Left = 8 TOP = 40 width = 19 heiGHT = 19 enabled = false flat = true glyph.data =

{DE010000424DDE01000000000000760000002800000024000000120000000100 0400000000006801000000000000000000001000000000000000000000000000 8000008000000080800080000000800080008080000080808000C0C0C0000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFF9999999FFFFFFFFFFFFFFFFFFFFFFF 0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFFFFF0000FFF999FF9999F999FFFF FFF22FFFFFFFFFFF0000FF999FFF9999FF999FFFFFF222FFFFFFFFFF0000FF99 FFFF9999FFF99FFFFF2222FFFFFFFFFF0000F99FFFFF9999FFFF99FFFF22222F FFFFFFFF0000F99FFFFF9999FFFF99FFF222F22FFFFFFFFF0000F99FFFFF9999 FFFF99FF222FF222FFFFFFFF0000F99FFFFF9999FFFF99FFFFFFFF222FFFFFFF 0000F99FFFFF9999FFFF99FFFFFFFFF222FFFFFF0000F99FFFFFFFFFFFFF99FF FFFFFFFF22FFFFFF0000FF99FFFF9999FFF99FFFFFFFFFFFF22FFFFF0000FF99 9FFF9999FF999FFFFFFFFFFFFF22FFFF0000FFF999FF9999F999FFFFFFFFFFFF FFF222FF0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFF22F0000FFFFFF999999 9FFFFFFFFFFFF FFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0000} NumGlyphs = 2 Visible = False end object btnInfo2: TSpeedButton Left = 8 Top = 80 Width = 19 Height = 19 Enabled = False Flat = True Glyph.Data =

{DE010000424DDE01000000000000760000002800000024000000120000000100 0400000000006801000000000000000000001000000000000000000000000000 8000008000000080800080000000800080008080000080808000C0C0C0000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFF9999999FFFFFFFFFFFFFFFFFFFFFFF 0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFFFFF0000FFF999FF9999F999FFFF FFF22FFFFFFFFFFF0000FF999FFF9999FF999FFFFFF222FFFFFFFFFF0000FF99 FFFF9999FFF99FFFFF2222FFFFFFFFFF0000F99FFFFF9999FFFF99FFFF22222F FFFFFFFF0000F99FFFFF9999FFFF99FFF222F22FFFFFFFFF0000F99FFFFF9999 FFFF99FF222FF222FFFFFFFF0000F99FFFFF9999FFFF99FFFFFFFF222FFFFFFF 0000F99FFFFF9999FFFF99FFFFFFFFF222FFFFFF0000F99FFFFFFFFFFFFF99FF FFFFFFFF22FFFFFF0000FF99FFFF9999FFF99FFFFFFFFFFFF22FFFFF0000FF99 9FFF9999FF999FFFFFFFFFFFFF22FFFF0000FFF999FF9999F999FFFFFFFFFFFF FFF222FF0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFF22F0000FFFFFF999999 9FFFFFFFFFFFF FFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0000} NumGlyphs = 2 Visible = False end object btnInfo3: TSpeedButton Left = 8 Top = 120 Width = 19 Height = 19 Enabled = False Flat = True Glyph.Data =

{DE010000424DDE01000000000000760000002800000024000000120000000100 0400000000006801000000000000000000001000000000000000000000000000 8000008000000080800080000000800080008080000080808000C0C0C0000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFF9999999FFFFFFFFFFFFFFFFFFFFFFF 0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFFFFF0000FFF999FF9999F999FFFF FFF22FFFFFFFFFFF0000FF999FFF9999FF999FFFFFF222FFFFFFFFFF0000FF99 FFFF9999FFF99FFFFF2222FFFFFFFFFF0000F99FFFFF9999FFFF99FFFF22222F FFFFFFFF0000F99FFFFF9999FFFF99FFF222F22FFFFFFFFF0000F99FFFFF9999 FFFF99FF222FF222FFFFFFFF0000F99FFFFF9999FFFF99FFFFFFFF222FFFFFFF 0000F99FFFFF9999FFFF99FFFFFFFFF222FFFFFF0000F99FFFFFFFFFFFFF99FF FFFFFFFF22FFFFFF0000FF99FFFF9999FFF99FFFFFFFFFFFF22FFFFF0000FF99 9FFF9999FF999FFFFFFFFFFFFF22FFFF0000FFF999FF9999F999FFFFFFFFFFFF FFF222FF0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFF22F0000FFFFFF999999 9FFFFFFFFFFFF FFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0000} NumGlyphs = 2 Visible = False end object btnInfo4: TSpeedButton Left = 8 Top = 160 Width = 19 Height = 19 Enabled = False Flat = True Glyph.Data =

{DE010000424DDE01000000000000760000002800000024000000120000000100 0400000000006801000000000000000000001000000000000000000000000000 8000008000000080800080000000800080008080000080808000C0C0C0000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFF9999999FFFFFFFFFFFFFFFFFFFFFFF 0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFFFFF0000FFF999FF9999F999FFFF FFF22FFFFFFFFFFF0000FF999FFF9999FF999FFFFFF222FFFFFFFFFF0000FF99 FFFF9999FFF99FFFFF2222FFFFFFFFFF0000F99FFFFF9999FFFF99FFFF22222F FFFFFFFF0000F99FFFFF9999FFFF99FFF222F22FFFFFFFFF0000F99FFFFF9999 FFFF99FF222FF222FFFFFFFF0000F99FFFFF9999FFFF99FFFFFFFF222FFFFFFF 0000F99FFFFF9999FFFF99FFFFFFFFF222FFFFFF0000F99FFFFFFFFFFFFF99FF FFFFFFFF22FFFFFF0000FF99FFFF9999FFF99FFFFFFFFFFFF22FFFFF0000FF99 9FFF9999FF999FFFFFFFFFFFFF22FFFF0000FFF999FF9999F999FFFFFFFFFFFF FFF222FF0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFF22F0000FFFFFF999999 9FFFFFFFFFFFF FFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0000} NumGlyphs = 2 Visible = False end object btnInfo5: TSpeedButton Left = 8 Top = 200 Width = 19 Height = 19 Enabled = False Flat = True Glyph.Data =

{DE010000424DDE01000000000000760000002800000024000000120000000100 0400000000006801000000000000000000001000000000000000000000000000 8000008000000080800080000000800080008080000080808000C0C0C0000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFF9999999FFFFFFFFFFFFFFFFFFFFFFF 0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFFFFF0000FFF999FF9999F999FFFF FFF22FFFFFFFFFFF0000FF999FFF9999FF999FFFFFF222FFFFFFFFFF0000FF99 FFFF9999FFF99FFFFF2222FFFFFFFFFF0000F99FFFFF9999FFFF99FFFF22222F FFFFFFFF0000F99FFFFF9999FFFF99FFF222F22FFFFFFFFF0000F99FFFFF9999 FFFF99FF222FF222FFFFFFFF0000F99FFFFF9999FFFF99FFFFFFFF222FFFFFFF 0000F99FFFFF9999FFFF99FFFFFFFFF222FFFFFF0000F99FFFFFFFFFFFFF99FF FFFFFFFF22FFFFFF0000FF99FFFF9999FFF99FFFFFFFFFFFF22FFFFF0000FF99 9FFF9999FF999FFFFFFFFFFFFF22FFFF0000FFF999FF9999F999FFFFFFFFFFFF FFF222FF0000FFFF999FFFFF999FFFFFFFFFFFFFFFFFF22F0000FFFFFF999999 9FFFFFFFFFFFF FFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0000} NumGlyphs = 2 Visible = False end object Label1: TLabel Left = 32 Top = 232 Width = 84 Height = 12 Caption = 'filters Preview:' end object StaticText2: TStaticText Left = 8 Top = 12 Width = 495 Height = 2 Anchors = [akLeft, akTop, akRight] AutoSize = False BevelInner = bvNone BorderStyle = sbsSunken TabOrder = 0 end object StaticText3: TStaticText Left = 515 Top = 8 Width = 2 Height = 329 Anchors = [akTop, akRight, akBottom] AutoSize = False Bevelinner = Bvnone Border = SBSSunken Taborder =

1 end object btnOK: TBitBtn Left = 531 Top = 24 Width = 81 Height = 25 Anchors = [akTop, akRight] Caption = 'OK (& O)' TabOrder = 34 Kind = bkOK end object btnCancel: TBitBtn Left = 531 Top = 64 Width = 81 Height = 25 Anchors = [akTop, akRight] Caption = 'canceled (& C)' TabOrder = 35 Kind = bkCancel end object staticText1: TStaticText Left = 74 Top = 20 Width = 28 Height = 16 Caption = 'field' TabOrder = 8 end object chkIsField1: TCheckBox Tag = 1 Left = 248 Top = 42 Width = 41 Height = 17 Caption = 'field' TabOrder = 11 OnClick = chkIsFieldClick end object cbbLogical1: TComboBox Tag = 1 Left = 416 Top = 40 Width = 89 Height = 20 Style = csDropDownList ItemHeight = 12 ItemIndex = 0 TabOrder = 13 Text = 'and (aND)' OnChange = SettingChange Items.Strings = ( 'and (aND)' ', or (oR)') end object cbbValue1: TComboBox Tag = 1 left = 296 TOP = 40 width = 113 Height = 20 Style = csSimple ItemHeight = 12 TabOrder = 12 OnChange = SettingChange end object cbbOperators1: TComboBox Tag = 1 Left = 152 Top = 40 Width = 89 Height = 20 Style = csDropDownList ItemHeight = 12 TabOrder = 10 OnChange = SettingChange Items.Strings = ('=' '<>' '>' '> =' '<' '<=

'' Comprising 'does not contain') end object cbbFields1: TComboBox Tag = 1 Left = 32 Top = 40 Width = 113 Height = 20 Style = csDropDownList ItemHeight = 12 TabOrder = 9 OnChange = cbbFieldsChange end object StaticText4: TStaticText Left = 176 Top = 20 Width = 40 Height = 16 Caption = 'operator' TabOrder = 6 end object StaticText5: TStaticText Left = 323 Top = 20 Width = 58 Height = 16 Caption = 'value / field value' TabOrder = 5 end object StaticText6: TStaticText Left = 422 Top = 20 Width = = 16 Caption = 'relationship between the conditions' 76 Height TabOrder = 3 end object StaticText7: TStaticText Left = 148 Top = 14 Width = 1 Height = 215 AutoSize = False BorderStyle = sbsSunken TabOrder = 2 end object StaticText8: TStaticText Left = 244 Top = 14 Width = 1 Height = 215 AutoSize = False BorderStyle = sbsSunken TabOrder = 4 end object StaticText9: TStaticText Left = 412 Top = 14 Width = 1 Hei ght = 215 AutoSize = False BorderStyle = sbsSunken TabOrder = 7 end object cbbFields2: TComboBox Tag = 2 Left = 32 Top = 80 Width = 113 Height = 20 Style = csDropDownList ItemHeight = 12 TabOrder = 14 OnChange = cbbFieldsChange end object cbbOperators2: TComboBox Tag = 2 left = 152 TOP = 80 width = 89 height = 20 style = csdropdownlist itemheight = 12 Taborder =

15 onchange = settingchange itEms.strings = ('=' <<> ''> '> =' '<' '<=' 'contains' 'does not include') end object chkisfield2: tCheckbox tag = 2 left = 248 TOP = 82 Width = 41 Height = 17 Caption = 'field' TabOrder = 16 OnClick = chkIsFieldClick end object cbbValue2: TComboBox Tag = 2 Left = 296 Top = 80 Width = 113 Height = 20 Style = csSimple ItemHeight = 12 TabOrder = 17 OnChange = SettingChange end object cbbLogical2: TComboBox Tag = 2 Left = 416 Top = 80 Width = 89 Height = 20 Style = csDropDownList ItemHeight = 12 ItemIndex = 0 TabOrder = 18 Text = 'and (aND)' OnChange = SettingChange Items.Strings = ( ' and (aND) '', or (oR) ') end object cbbLogical3: TComboBox Tag = 3 Left = 416 Top = 120 Width = 89 Height = 20 Style = csDropDownList ItemHeight = 12 ItemIndex = 0 TabOrder = 23 Text =' product (aND ) 'Onchange = settingchange items.str ings = ( 'and (AND)' ', or (OR)') end object cbbValue3: TComboBox Tag = 3 Left = 296 Top = 120 Width = 113 Height = 20 Style = csSimple ItemHeight = 12 TabOrder = 22 OnChange = SettingChange end object Chkisfield3: tcheckbox tag = 3 left = 248 TOP = 122 width = 41 height = 17 caption = 'field'

TabOrder = 21 OnClick = chkIsFieldClick end object cbbOperators3: TComboBox Tag = 3 Left = 152 Top = 120 Width = 89 Height = 20 Style = csDropDownList ItemHeight = 12 TabOrder = 20 OnChange = SettingChange Items.Strings = ( '=' '<>' '>'> = '' <'<=' ') End Object Cbbfields3: TcomboBox Tag = 3 Left = 32 TOP = 120 width = 113 Height = 20 style = csdropdownlist itemHeight = 12 Taborder = 19 OnChange = cbbFieldsChange end object cbbLogical4: TComboBox Tag = 4 Left = 416 Top = 160 Width = 89 Height = 20 Style = csDropDownList ItemHeight = 12 ItemIndex = 0 TabOrder = 28 Text = 'and (aND)' OnChange = SettingChange Items.Strings = ('And (and)' or (or) ') end object cbbvalue4: tcomboBox tag = 4 left = 296 TOP = 160 width = 113 height = 20 style = cssimple itemheight = 12 Taborder = 27 onchange = settingchange end object chkIsField4: TCheckBox Tag = 4 Left = 248 Top = 162 Width = 41 Height = 17 Caption = 'field' TabOrder = 26 OnClick = chkIsFieldClick end object cbbOperators4: TComboBox Tag = 4 Left = 152 Top = 160 Width = 89 Height = 20 Style = csdropdownlist itemHeight = 12 Taborder = 25 onchange = settingchange item.strings =

('=' <> ''> ''> = '' <'' <= '' Contains' 'does not include') end object cbfields4: tcomboBox tag = 4 left = 32 TOP = 160 width = 113 height = 20 Style = csDropDownList ItemHeight = 12 TabOrder = 24 OnChange = cbbFieldsChange end object cbbLogical5: TComboBox Tag = 5 Left = 416 Top = 200 Width = 89 Height = 20 Style = csDropDownList Enabled = False ItemHeight = 12 ItemIndex = 0 TabOrder = 33 Text = ' and (aND) 'OnChange = SettingChange Items.Strings = (' and (aND) '', or (oR) ') end object cbbValue5: TComboBox Tag = 5 Left = 296 Top = 200 Width = 113 Height = 20 Style = csSimple ItemHeight = 12 TabOrder = 32 OnChange = SettingChange end object chkIsField5: TCheckBox Tag = 5 Left = 248 Top = 202 Width = 41 Height = 17 Caption = 'field' TabOrder = 31 OnClick = chkIsFieldClick end object cbbOperators5: TComboBox Tag = 5 Left = 152 TOP = 200 Width = 89 height = 20 style = csdropdownlist itemHeight = 12 Taborder = 30 onchange = settingchange item.strings = ('=' '' <> ''> '> =' '<' '' '' "" 不 " ') End Object Cbbfields5: Tcombobox Tag = 5 Left = 32 TOP = 200 Width =

113 Height = 20 Style = csDropDownList ItemHeight = 12 TabOrder = 29 OnChange = cbbFieldsChange end object txtFilter: TStaticText Left = 32 Top = 248 Width = 471 Height = 83 Anchors = [akLeft, akTop, akRight, akBottom] AutoSize = False BorderStyle = sbsSunken Taborder = 36 Endend

PAS file: unit FormTFilter; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls, Buttons, DB, StrUtils; type TComponentType = (ctField, ctOperator, ctCheckBox, ctValue, ctLogical) ; TFilterString = record FilterStr, DisplayText, ErrorStr: String; end; TfrmTFilter = class (TForm) staticText1: TStaticText; StaticText2: TStaticText; StaticText3: TStaticText; btnOK: TBitBtn; btnCancel: TBitBtn; cbbFields1: TComboBox; cbbOperators1: TComboBox; cbbValue1: TComboBox; chkIsField1: TCheckBox; cbbLogical1: TComboBox; StaticText4: TStaticText; StaticText5: TStaticText; StaticText6: TStaticText; StaticText7: TStaticText; StaticText8: TStaticText; StaticText9: TStaticText; cbbFields2: TComboBox; cbbOperators2: TComboBox; chkIsField2: TCheckBox; cbbValue2: TComboBox; CBBLogical2: TcomboboX; Cbblogical3: Tcombobox; Cbbvalue3: Tcombobox; Chkisfield3: Tcheckbox; cbbOperators3: TComboBox; cbbFields3: TComboBox; cbbLogical4: TComboBox; cbbValue4: TComboBox; chkIsField4: TCheckBox; cbbOperators4: TComboBox; cbbFields4: TComboBox; cbbLogical5: TComboBox; cbbValue5: TComboBox; chkIsField5: TCheckBox; cbbOperators5: TComboBox; cbbFields5: TComboBox; txtFilter: TStaticText; btnInfo1: TSpeedButton; btnInfo2: TSpeedButton; btnInfo3: TSpeedButton; btnInfo4: TSpeedButton; btnInfo5: TSpeedButton; Label1: TLabel; procedure FormCreate (Sender: TObject); procedure FormDestroy (Sender: TObject); procedure cbbFieldsChange (Sender: TObject); Procedure ChkisfieldClick (Sender: TOBJECT); Procedure Settingchange (Sender: TOBJECT);

private Fields: TFields; FFilterString: String; procedure ListFieldsToComboBox (cbbTarget: TCombobox); procedure SetFilterString (const Value: String); procedure SynchronizeFilterString; function ParseFilter (Field: TField; Opeartor: String; cbbValue: TComboBox): TFilterString; public property FilterString : String read FFilterString write SetFilterString; end; var frmTFilter: TfrmTFilter; implementation {$ R * .dfm} uses FormTList; {TfrmTFilter} procedure TfrmTFilter.FormCreate (Sender: TObject); var i: Integer; begin if not (Owner is TfrmTList ) The Raise EcomponEnterror.createfmt ('When the form is created, the error describes the following:' # 13 # 10 'Form The host must be a TFRMTList object or inherit in the TFRMTList object, but in actually use% s', [ Owner.ClassName]); fields: = (Owner as TfrmTList) .ADODataSet1.Fields; for i: = 1 to 5 do begin // add all valid field cbbFields, cbbValue in ListFieldsToComboBox (TComboBox (Self.FindComponent ( 'cbbFields ' INTOSTR (I)))))))))); ListfieldStocomboBox (Tcombobox (Self.FindComponent (' Cbbvalue ' INTOSTR (I)))))))))) d; end; procedure TfrmTFilter.FormDestroy (Sender: TObject); begin Fields: = nil; end; procedure TfrmTFilter.ListFieldsToComboBox (cbbTarget: TCombobox); var i: Integer; begin // add fields to the specified ComboBox, ComboBox displayed Field.displayLabel, // You can get a field // not add BLOB, Graphic, Ole, Reference, Bytes, etc. Cbbtarget.items.clear; for i: = 0 To Fields.count-1 DO if (NOT (FTUNKNOWN, FTBLOB, FTGRAPHIC, FTBYTES, FTBLOB, FTGRAPHIC, FTBYTES, FTVARBYTES, FTPARADOOLE, FTDBASEOLE, FTCURSOR, FTADT, FTARRAY, FTReference, ftdataSet])))) and (fields [i] .visible) and (fields [i] .fieldkind=

fkData) then cbbTarget.Items.AddObject (Fields [i] .DisplayLabel, Fields [i]); end; procedure TfrmTFilter.cbbFieldsChange (Sender: TObject); var cbbOperators: TComboBox; begin // different according to the selected type of field, the refresh operation List CBBOPERATORS: = Tcombobox (Self.FindComponent ('CBBOPERATORS' INTOSTR ((Sender as Tcomponent)))); if cbopertors = nil the raise ecomponenterror.createfmt (errors when the list is refreshed, error description : '# 13 # 10' Try to refresh the unsaved component% s', ['CBBOPERATORS' INTOSTR ((Sender as Tcomponent)]); CBBopertors.Items.clear; with (Sender As Tcombobox) Do Begin Case TField (Items.Objects [ItemIndex]) DataType of ftString, ftMemo, ftFmtMemo, ftFixedChar, ftWideString:. begin cbbOperators.Items.Add ( '='); cbbOperators.Items.Add ( '<>'); cbbOperators.Items. Add ('Take .. beginning'); CBBOPERATORS.ITEMS.ADD ('contains'); CBBOPERATORS.ITEMS.ADD ('does not include'); end; ftboolean: Begin Cbootors.i tems.Add ( '='); cbbOperators.Items.Add ( '<>'); end; ftSmallInt, ftInteger, ftWord, ftFloat, ftCurrency, ftDate, ftTime, ftDateTime, ftBCD, ftAutoInc, ftTypedBinary, ftLargeInt: begin cbbOperators. Items.add ('='); cbbopertorsers.items.add ('<>'); CBBOPERATORS.ITEMS.Add ('>'); CBBOPERATORS.ITEMS.ADD ('> ='); CBBOPERATORS.ITEMS.ADD ( '<'); CBBOPERATORS.ITEMS.ADD ('<='); END;

end; end; SynchronizeFilterString; end; procedure TfrmTFilter.chkIsFieldClick (Sender: TObject); var cbbValue: TComboBox; begin cbbValue: = TComboBox (Self.FindComponent ( 'cbbValue' IntToStr ((Sender as TComponent) .Tag))); If CBBVALUE = NIL THEN RAISE ECOMPONENTERROR.CREATEFMT ('Attempting to switch the value / field value editing box, an error is described as follows:' # 13 # 10 'Try to refresh the unsavement component% s', ['Cbbvalue' INTSTR ( (Sender as TComponent) .Tag)]); if (Sender as TCheckBox) .Checked then cbbValue.Style: = csDropDownList else cbbValue.Style: = csSimple; SynchronizeFilterString; end; procedure TfrmTFilter.SetFilterString (const Value: String); begin // TODO: The Value of each control updates (not required) FFilterString: = Value; end; procedure TfrmTFilter.SynchronizeFilterString; var cbbField, cbbOpeartor, cbbValue, cbbLogical: TComboBox; chkIsField: TCheckBox; btnInfo: TSpeedButton; i: Integer; FilterStr : Tfilterstring; logicalstr: string; begin // Refresh filter conditions, including filterString, TXTFILTER.CAPTION, and display the correct or error prompt with btninfo // Cbbfieldsx, Cbootorsx, Cbbvaluex, Cbblo GicalX, Chkisfieldx, BTNInfox depends on a set of // PARSEFILTER Returns TFILTERSTRING in each set of settings, including filter strings, displayed text and error prompt information TXTFILTER.CAPTION: = ''; ffilterstring: = '; LogicalStr : = '; For i: = 1 to 5 do beg cbbfield: = tcomboBox (Self.FindComponent (' cbbfields' INTOSTR (I))); CBBopertor: = Tcombobox (Self.Findcomponent ('CBBOPERATORS' INTSTR (I )))); Cbbvalue: = tcomboBox (Self.FindComponent ('cbbvalue' INTOSTR (I))); cbBLogical: = Tcombobox (Self.FindComponent ('cbblogical' INTOSTR (I))); chkisfield: =

Tcheckbox (Self.FindComponent ('Chkisfield' INTOSTR (I))); btninfo: = TspeedButton ('btninfo' INTOSTR (I))); if (CBBField <> nil) and (CBBopertor <> nil ) and (cbblogical <> nil) AND (chkisfield <> nil) and (btninfo <> nil) and (Cbbfield.ItemIndex <> - 1) The begin filterStr: = PARSEFILTER (TField (Cbbfield. Items.Objects [cbbField.ItemIndex]), cbbOpeartor.Text, cbbValue); if FilterStr.FilterStr <> '' then begin // FilterString and filters were processed for display text FFilterString: = IfThen (FFilterString <> '', '(' Ffilterstring ')', '') ifthen (i> 0, logicalstr, '') filterstr.filterstr; txtfilter.caption: = ifthen (txtfilter.caption <> ", '(' txtfilter .Caption ')', '') ifehen (i> 0, logicalstr, ') filterstr.displaytext; logicalstr: = ifthen (cbBLogical.Index = 0,' and ',' or '); // Let The buttons show the correct green hook btninfo.ENABLED: = false; btninfo.visi BLE: = true; Else Begin if filterstr.rrorstr = '' Then btninfo.visible: = false // The return value is all empty strings, indicating that the user does not use the control group Else Begin // display error prompt btninfo.ENABLED: = True; btninfo.hint: = filterStr.Errorstr; btninfo.visible: = true; end; end; end; end;

function TfrmTFilter.ParseFilter (Field: TField; Opeartor: String; cbbValue: TComboBox): TFilterString; begin // returns the corresponding filter parameters according Result.FilterStr string: = ''; Result.DisplayText: = ''; Result.ErrorStr : = '; If (OPEARTOR =' ') or (cbbvalue.text =' ') THEN EXIT; if (cbbvalue.style <> cssimple) and (cbbvalue.itemindex = -1) Then EXIT; CASE Field.DataType of // According to the field type processing, ftstring, ftmemo, ftfmtmemo, ftfixedchar, ftwidestring: begin if cbbvalue.style = cssimple dam If (OPEARTOR = '<>') The Begin Result. Filterstr: = Format ('% s% s''% s' ', [field.fieldname, OPEARTOR, CBBVALUE.TEXT]); result.displaytext: = format ('% s% s'% s' '" , [Field.disPlayLabel, Opertor, Cbbvalue.Text]); End; if Opertor = 'That .. beginning' Then Begin Result.Filterstr: = '(' Field.fieldName 'Like' '' Trim (Cbbvalue. TEXT) '%' ')'; Result.Displaytext: = '(' Field.displayLabel 'starts with' '' TRIM (CBBVALUE.TEXT) '' '' '' '' '' '' '' '' '' '' '' '' 'THEN BEGIN Result.Filterstr: =' (' Field.fieldName ' Like ' '%' Trim (cbbvalue.text) '%' ')'; Result.Displaytext: = '(' Field.displayLabel 'contains' ' Trim (Cbbvalue.Text) '

'') '; End; if Opertor =' does not include 'Ten Begin Result.Filterstr: =' (' Field.fieldName NOT LIKE' ''% ' TRIM (CBBVALUE.TEXT) '% ')' Result.displaytext: = '(' Field.displayLabel 'does not contain' ' TRIM (Cbbvalue.Text) ' ')'; END; END ELSE BEGIN IF NOT (TField (Cbbvalue.Items.Objects [ Cbbvalue.ItemIndex]). DataType in [ftstring, ftmemo, ftfmtmemo, ftfixedchar, ftwideString]) THEN BEGIN RESULT.ERRORSTR: = 'The difference between the two field data types is too large, and cannot be used as comparison'; exit; end; if (OPEARTOR = '=') or (OPEARTOR = '<>') Then Begin Result.Filterstr: = format ('% s% s% s', [Field.fieldName, Opertor, Tfield (Cbbvalue.Items.Objects [CBBValue .Itemindex]). FieldName]); result.displaytext: = format ('% s% s% s', [field.displaylabel, opeartor, cbbvalue.text]); end; if (OPEARTOR =' Trip) ) or (OPEARTOR = 'contains') or (OPE Artor = 'does not include') The begin result.errorstr: = 'Two fields and fields cannot be used with "in .. beginning", "contain" or "not contain" operator'; End; End; end; ftdate , fttime, ftdatetime: begin if cbbvalue.style = cssimple dam Try StrtodateTime (cbbvalue.text) Except result.errorstr: = '"value / field value" content is not valid date / time format'; exit; end; result. FILTERSTR: =

Field.fieldName Opertor '' '' Trim (Cbbvalue.Text) '' '; Result.DisplayText: = Field.displayLabel OpeartOR ' '' ' Trim (Cbbvalue.Text) ' '' ELSE BEGIN if not (tfield (cbbvalue.Items.Objects [cbbvalue.itemindex]). DataType In [ftdate, fttime, ftdatetime]) THEN BEGIN RESULT.ERRORSTR: = 'The two field data types specified are different, cannot be used comparing '; Exit; end; Result.FilterStr:. = Field.FieldName Opeartor TField (cbbValue.Items.Objects [cbbValue.ItemIndex]) FieldName; Result.DisplayText: = Field.DisplayLabel Opeartor ' '' ' TRIM (CBBVALUE.TEXT) '' '; end; end; ftboolean: Begin if cbbvalue.style = cssimple the beginning mustage mustage (cbbvalue.text) Except results (CBBVALUE.TEXT) Except result.errorstr: =' "value / field value" content must For Boolean type '; exit; end; result.filterstr: = field.f ieldName Opeartor BoolToStr (StrToBool (cbbValue.Text)); Result.DisplayText: = Field.DisplayLabel Opeartor BoolToStr (StrToBool (cbbValue.Text)); end else begin if TField (cbbValue.Items.Objects [cbbValue.ItemIndex ]). DataType <> ftboolean life begin result.errorstr: = 'The two field data types specified are different, and cannot be used as comparison'; EXIT; End; Result.Filterstr: = Field.fieldName OPEARTOR

. TField (cbbValue.Items.Objects [cbbValue.ItemIndex]) FieldName; Result.DisplayText: = Field.DisplayLabel Opeartor BoolToStr (StrToBool (cbbValue.Text)); end; end; ftSmallInt, ftInteger, ftWord, ftFloat, ftCurrency , ftBCD, ftAutoInc, ftTypedBinary, ftLargeInt: begin if cbbValue.Style = csSimple then begin try StrToFloat (cbbValue.Text) except Result.ErrorStr: = ' "value / field value" content is invalid'; Exit; end; Result.FilterStr: = Field.FieldName Opeartor cbbValue.Text; Result.DisplayText:. = Field.DisplayLabel Opeartor cbbValue.Text; end else begin if not (TField (cbbValue.Items.Objects [cbbValue.ItemIndex]) DataType in [ftSmallInt , ftinteger, ftword, ftfloat, ftcurrency, ftbcd, ftautoinc, fttyped, ftlargeint]) THEN BEGIN RESULT.ERRORSTR: = 'The specified two field data type difference is too large, and cannot be used as a comparison'; Exit; end; Result.FilterStr:. = Field.FieldName Opeartor TField (cbbValue.Items.Objects [cbbValue.ItemIndex]) FieldName; Result.DisplayText: = Field.DisplayLabel Opeartor cbbValue.Text; end; end; End; end; procedure tfrmtfilter.settingchange (sender: TOBJECT); begin synchronizefilterstring; end; end.

转载请注明原文地址:https://www.9cbs.com/read-100761.html

New Post(0)