General query component design

zhaozj2021-02-16  42

General query component design

Author: nxyc_twz@163.com

In the current MIS system, data maintenance and data query is its two core functions. How to design a universal query component that enables the development of the MIS system with a unified query interface, which is a problem that MIS system developers have been solving. In the development and design of many years of MIS systems, the author has been designed and practiced, and finally designed to complete this relatively complete, universal query component.

The component inherits from the Tcomponet component, which mainly includes a query form and a form that displays a summary summary. The main design idea is to achieve the purpose of the general query by setting the PARAMS (parameter) of the TQuery component. For how to design a custom component, please refer to: Create a custom component

It is now published its design ideas and skills to share with the majority of programming enthusiasts. Define universal query class

Find strings in the specified string

Function WordPos (Const AWORD, Astring: String): Integer;

/ / Find strings in the specified string

Var s: string;

I, P: Integer;

Begin

S: = '' ANSIUPPERCASE (astring) ''; // ignore the case

For i: = 1 to length (s) do if not (s [i] in identifiers) THEN S [i]: = ''; // constant definition

P: = POS ('' AnsiUppercase (AWORD) '', S);

Result: = P;

END;

Define universal query class

Type

TDBFILTERDIALOG = Class (Tcomponent)

Private

FDIALOG: TMYDBFILTERDIALOG; / / Query Form

ForiginalSQL: TSTRINGS; / / The original SQL statement

FMODIFIEDSQL: TSTRINGS; // Modified SQL statement

FDataSet: tQuery; // Dataset

FDEFAULTMATCHPE: TDBFILTERMATCHPE; // Filter type

FOPTIONS: TDBOPTIONS; // Filter options

FCAPTION: STRING; / / Form Title

Ffields: tstringlist; // field list

ForiginalVariables: TList; // Variable list

SQLProp: String; // SQL attribute

Procedure setDataSet (Const value: tQuery); // Setting the data set

Procedure SetOptions (Const Value: TDBOPTION); // Settings Options

Procedure setcaption (const value: string); // Set the title

Procedure setDefaultMatchType (const value: tdbfiltermatchType); // Set the default match type

Procedure setfields; // set field

Procedure setfieldslist (const value: tstringlist); // Set field list

Procedure setoriginalsql (const value: tstrings); // Set SQL

Procedure restoreSQL; // Restore SQL

Procedure saveparamvalues; // Save the parameter value

{Private Declarations}

protected

{Protected Declarations}

Procedure loaded; override; // Load filter dialog

Procedure Notification; Operation: TOPERATION; override; // Transfer Message

Property Originalsql: Tstrings Read fortersql Write SetoriginalSql;

public

{Public declarations}

Constructor Create (Aowner: Tcomponent); OVERRIDE; // Constructor

DESTRUCTOR Destroy; Override; // Destructor

Function Execute: Boolean; // Execute Query

Procedure rebuildsql; // Rebuild SQL statement

Property Modifiedsql: Tstrings Read Fmodifiedsql;

Published

{Published Declarations}

Property Caption: String Read Fcaption Write setCaption; // Set the title

Property DataSet: TQuery Read FDataSet Write SetDataSet; // Setting Data Set

Property DefaultMatchType: TDBFiltermatchType Read FDefaultmatchType Write SetDefaultMatchType

DEFAULT fdmatchstart; // Filter type

Property Options: TDBOPTIONS Read FOPTIONS WRITE SETOPTIONS DEFAULT

[fdshowcasesensitive, fdshownonmatching]; // filter options

Property Fields: Tstringlist Read Ffields Write setfieldslist;

END;

Define the parameter data variable class

TDBVARIABLE = Class // Parameter data variable

public

Variablename: String; // Variable name

VariableValue: variant; // Variable value

Constructor create (name: string; value: variant); // Construct function, set variable name and variable value

END;

Constructor, set variable name and variable value

Constructor tdbvariable.create (Name: string; value: variant);

Begin

// Construct function, set variable name and variable value

Variablename: = name;

VariableValue: = value;

END;

Constant definition

Const

Identifiers = ['a' .. 'Z', 'a' .. 'Z', '0'. '9', '_', '#', '$', '.', '", '@'];

Procedure register; // Registration component

Registration component

PROCEDURE register;

// Register components

Begin

Registercomponents ('My Database Components', [TDBFilterDialog]);

End; {of register}

Filter type

// Filter match type: Fully match, start space match, match, any location match, range match, no match

TDBFILTERMATCHPE = (fdmatchstart, fdmatchstart, fdmatchend,

FDMATCHANY, FDMATCHRANGE, FDMATCHNON; Filter options

// Filter option: Size-write sensitive display case sensitive display mismatch record

TDBOPTION = (FDSHOWCaseSensitive, fdshownonmatch);

TDBOPTIONS = set of tdboption;

Set data set

Procedure tdbfilterdialog.setDataSet (Const value: tQuery);

Begin

// Set the data set

If not (value is tquery) or (value = nil)) then // If you do not specify a data set or the specified data set is not tQuery, an exception is issued.

Raise Exception.create (SDBFilternondBerror);

//otherwise

FDataSet: = Value;

Sqlprop: = 'sql';

IF ([csdesigning, cslineing] * ComponentState) = [] THEN

Begin

SetFields; // Set field

Originalsql: = Tstrings (getordprings (fdataset, sqlprop); //

END;

END;

Setting Options

Procedure TdbfilterDialog.SetOptions (Const Value: TDBOPTION);

Begin

//Setting Options

FOPTIONS: = Value;

END;

Set the title

Procedure tdbfilterdialog.setcaption (const value: String);

Begin

// Set the title

FCAPTION: = VALUE;

FDIALOG.CAPTION: = fcaption;

END;

(Endlessly)

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

New Post(0)