Procedure preparation
1. Variable Declaration D All variables are not in the type, and begins with V, such as: var vWorkername: string; Vyear: integer; vDate: tdate;
_Recordset object's prefix is VRS.
Special variable: VSQL: Basically all SQL statements are first use variables vsql bin value, such as: var vsql: string; begin vsql: = 'SELECT A.FDWORKER'; vsql: = vsql 'from tabworker a'; end; control named class prefix exemplary TEdit ed edWorkerNo TDBGrid grd grdWorker TCombobox cbo cboWorker TDateTimePicker dp dpDate TButton c cOk cCancel TCheckBox chk chkCancel TSpeedButton sb sbWorker TClientDataSet cln clnWorker TDataSource ds dsWorker TAdoDataSet adods adodsWorker TPanel pan panTop TForm frm frmWorker TDataSetProvider pvd pvdWorker TTreeview trv trvRawType TListView LstwstWorker TPAGECONTROL PC PCWORKERINFORMATION TIMAGE IMGWORKER TMEMO ED EDMEMO
2, function and process naming 3, function prefix with f, for example: Function of processing data check: Function FcheckData: boolean;
The prefix of the process is used, for example: process the process of handling workers: Procedure PWORLEVE;
Naming Rules All variables or controls are named in English, and they don't want to use abbreviations. For example: Name the TEDIT of the input worker name: EdWorkerName instead of name: Edwn and other abbreviation form Data table prefix is Tab, field prefix is FD. For example: The name of the worker table is: the field of the TabWorker worker number is: fdWorkerno database operation method Operation database (selection, insert, update, delete): Basically with SQL statements to operate the database, avoid using the Data Aware class control Operate the database. For example: inserting a production record: var vsql: string; vWorkerid: string; vproductnum: string; begin xxxxxx; .........; vsql: = 'INSERT INTO TABPRODUCT (fddate, fdworkerid, fdproductnum) VALUES ('; vsql: = vsql vinfo.vdbsqldate (date); vsql: = vsql ',' (vWorkerID); vsql: = vsql ',' (vproductnum); vsql: = vsql ')'; vinfo.execute (vsql); end; * Note : Vinfo represents an instance of a custom class TINFO, which has various functions, and details are described later.
Method for displaying data with TDBGRID: 1. Use the TDBGRID TDataSource TclientDataSet TDataSetProvider TadodataSet control. 2. Connection is TDBGRID-> TDataSource-> TclientDataSet-> TdataSetProvider-> TadodataSet 3. First use the _Recordset object to receive data, 4. Then put the _recordset object to the TadodataSet control, 5. Then call the TclientDataSet's Close method, the OPEN method. Multi-user operation data processing: Typically lock the table to be operated, the lock method is the PLOCKTABLE method with the TINFO class. Data legitimacy checking method Typically check the data legitimacy before you want to save the data, 检查 合 合 合 合 合 合. Check includes: 1. Check if it is an integer; judges using the Fisint function of TINFO. 2. Check if it is a floating point number; judges the Fisfloat function using TINFO. 3. Check if it is a date; the date is used with TDATETIMEPICKER, usually does not need to be checked. 4. Check if there is no input; judgment using the Flen function of Tinfo. 5. The inspection of data integrity (the inspection content will be explained in the development document); 6. Data logic checks (check content will be described in the development document);
For data types of characters, be careful to clear the front and rear spaces with the TRIM function. TINFO's Description TINFO class encapsulates some basic functions, processes and constants: Function and process: 6. Function Fisfloat (VDATA: String): Boolean; 7. Function Fisint (VDATA: STRING): Boolean; 8. Function Flen (VDATA: String): Boolean; 9. Procedure pbegintrans; // Transaction start 10. Procedure pcommittrans; // Transaction submission 11. Procedure prollback; // transaction rollback 12. Procedure execute (const vsql: string; var vrs: _recordset; vAbort: Boolean = false; overload; secure SQL execution function 1, vsql is the SQL statement to be executed, VRS is a _recordset object that receives the return value, VABORT is said Whether the processing is aborted when an error is a connection (network interrupt). Usually use TRUE when the SQL statement included in a transaction is usually executed, not the SQL statement in the transaction is not specified. For example: VAR vsql: string; vrsworker begin vsql: = 'select a.fdWorkerno, A.fdWorkerName'; vsql: = vsql 'from tabworker a'; vinfo.execute (vsql, vrsworker); // This sentence is not specified VABORT, The default is false {above this sentence is executed, if the network is interrupted, resulting in a prompt to retry if it is necessary to try it, if you don't try again; if you retry, you will try again. Go to the database, but if you still don't connect, you will be prompted until you connect or unconnected by the user to exit the system} VINFO.EXECUTE (VSQL, VRSWORKER, TRUE); // This sentence specifies the VABORT {above this sentence, if Network interrupt, resulting in unconnected databases, prompting cannot be connected to the database, so abort. And try connect to the database. If you can't connect, you should try again if you want to try it, if you don't try again, you will exit the entire system; if you retry, you will try again to connect to the database, but if you still can't connect, repeat your prompt until you cancel or by the user Connect to exit system} END; 13. Procedure Execute (const vsql: string; vabort: boolean = false); overload; secure SQL execution function 2, the difference from 1 is that there is a returned data set. constant: 1. VDATESTR: Date format of the current computer, 2. If the format of the current computer is 2 years, 3. Then convert to 4 years. For example, the current computer's short-term format is 'yy-mm-dd', and vdatestr is 'YYYY-MM-YY'. 4. VcurrentUserno: The number of the current login operator. 5. VcurrentUsername: Name 6 of the current login operator. "Said.