General query component design
Author: nxyc_twz@163.com
Some time ago, due to work, innocent documents, please understand! I will organize all relevant documents and source code for this component.
Saving the values procedure TDBFilterDialog.SaveParamValues; var i: Integer; begin // save the parameter values for i:. = 0 to FOriginalVariables.Count - 1 do TDBVariable (FOriginalVariables [i]) VariableValue: = TQuery (FDataSet) .ParamByName (TDBVariable (ForiginalVariables [I]). Variablename) .value;
Click the OK button procedure TMyDBFilterDialog.btnOkClick (Sender: TObject); var i: Integer; f: TMyFieldInfo; begin // click the OK button for i:. = FPreviousList.Count - 1 downto 0 do begin TMyFieldInfo (FPreviousList [i]) Free FPREVIOSTLIST.DELETE (I); END; getCriteria; // Get standard setcriteria; // set standard for i: = 0 to ffilterlist.count - 1 do begin f: = tmyfieldinfo.create; // field definition class F.ssign (TMYFIELDINFO (FfilterList [i])); fpreviouslist.add (f); end; end;
Obtaining standard procedure TMyDBFilterDialog.GetCriteria; // Get standard var FilterIndex, i: Integer; begin FilterIndex: = -1; i: = 0; while (i end else begin EndingValue: = ''; StartingValue: = ''; FilterValue: = edtFieldValue.Text; end; NonMatching: = cbxNonMatching.Checked; end; end else // The user removed a criteria that existed if FilterIndex> = 0 then begin // remove the Selected list item lstSelectedFields.Items.Delete (lstSelectedFields.Items.IndexOf (TMyFieldInfo (FFilterList [FilterIndex]) DisplayLabel).);. // Free the FieldInfo Object TMyFieldInfo (FFilterList [FilterIndex]) Free; // Delete it from the list ffilterlist.delete (fix); if ffilterlist.count = 0 Then btnviewsummary.enable; = false; Setting the standard procedure TMyDBFilterDialog.SetCriteria; var FilterIndex, i: Integer; DisplayName: String; begin DisplayName: = lstAllFields.Items [lstAllFields.ItemIndex]; i: = 0; FilterIndex: = -1; // Find the Item in the list If IT EXISTS While (I Newsql: = TStringStream.create (S1); SQL: = TstringStream.create (s); try // Save To FORIGINALSQL.SAVETOSTREAM (SQL); SQL.seek (0, SofromBeginning); P: = WordPos ('Where' SQL.DataString; IF P = 0 THEN // If there is no where clause in the SQL statement begin Haswhere: = false; p: = wordpos ('Group', sql.datastring); if p = 0 THEN / / If there is no group clause in the SQL statement P: = WordPos ('Having', Sql.datastring); if P = 0 Then // If there is no Having clause in the SQL statement P: = WordPos ('Order', Sql.DataString); if P = 0 Then // If there is no ORDER clause in the SQL statement P: = SQL.SIZE; END ELSE BEGIN / / SQL statement has WHERE clauses Haswhere: = true; inc (p, 5); end; newsql.writestring (SQL.Readstring (P - 1)); if NOT HASWHERE THEN // If there is no whee clause in the SQL statement, newsql.writestring ('where'); for i: = 0 to fdialog.Filterlist.count - 1 do begin newsql.writestring (fdialog [i ] .Createsql); if i // Pause the control Application.MessageBox (Pchar (newsql.datastring), '123', MB_OK), '123', MB_OK), '123', MB_OK); if FDataSet is Tquery Do Begin DisableControls; Close; Sql.clear; SQL. Add (NewSQL.DataString); for i: = 0 to FOriginalVariables.Count - 1 do begin ParamByName (TDBVariable (FOriginalVariables [i]) VariableName.) .Value:. = TDBVariable (FOriginalVariables [i]) VariableValue; end; // Set new variable for i: = 0 to fdialog.filterlist.count - 1 do fdialog [i] .Setvariables (fdatarated); try open; except restoreSQL; // If an error, restore the original SQL statement end; end; setfields FDataSet.enableControls; fmodifiedsql.assign (Tstrings (getordprings (fdataset, sqlprop))); Finally Sql.free; newsql.free; end; end;