Copyright Notice
 
Please respect the original works. Reprint please keep the article integrity, and in the form of hyperlinks to the original author "Tingsking18" and the main site address, convenient for other friends to ask and correct.
 
 
First, improve the query effectiveness of the first to prepare query operations:
Customerquery.close;
If not (customerquery.prepared) then--> query is ready
Customerquery.prepare; --> Query Preparation
Customerquery.open; --> Execute Query
 
Two, to access the parameters in the runtime, there are three ways to choose: (Suitable for the BDE control Tquery)
(1) Parambyname: Set the value of the parameter by name
(2) Params: Set the value of the parameter by ordinal
(3) The Params.paramvalues property sets the value of the parameter by name. This method can set the value of one or more parameters in a row
Suppose an SQL statement has three parameters:
INSERT into "COUNTRY. DB "
(Name, capital, continent)
VALUES (: Name,: Capital,: Continent)
(1) QUERY1.PARAMS[1]. Asstring: = Edit1.text;
(2) Query1.parambyname (' capital '). Asstring: = Edit1.text;
(3) Query1.params.paramvalues[' Country; capital; Continent ']: = vararrayof ([Edit1.text,edit2.text, Edit3.text]);
 
Third, to allow users to edit the results of the query in the Data control:
Query1.requestlive:= True.
Note: Setting requestlive:= true does not guarantee "live data result sets."
 
Iv. releasing resources occupied by SQL statements
Customerquery.unprepare;
The Unprepare method sets prepared to false. Its work is mainly:
(1) Make sure the SQL properties are ready before querying again
(2) "Notification" BDE releases the internal resources allocated for the SQL statement
(3) "Notification" the database server releases the internal resources allocated for the SQL statement
Tip: When changing the Tquery SQL properties, the Tquery widget automatically closes and releases the resource that is occupied
 
V. (1) Executing queries that return results
Customerquery.close;
Customerquery.open;
(2) Executing queries that do not return results
such as INSERT, UPDATE, or DELETE, call Execsql directly. Like what:
Customerquery.execsql; {Query does not return a result set}
 
Vi. executing queries during run time (dynamic query)
If you cannot determine whether you want to return query results during design time, you can use the Try ... The except structure writes both processes, the general open is called in the Try section, and the Execsql is called in the except section, which can be performed to execsql even if the open call fails. You can intercept the type of the exception in the except section. If this exception is not a Enoresult exception, then this exception must be caused by other causes and has to be processed.
Try
Query2.open;
Except
On E:exception do
If not (E. Enoresultset) Then
Raise
End
 
Seven, embedded in the Delphi assembly
Procedure Tform1.button1click (Sender:tobject);
Begin
Asm
Push BX//This assembly must have, and in the first line
MOV AX,0FFH
Add ax,033h
Pop bx//must restore BX register,
Otherwise, the system has unexpected errors, be careful when the machine
End;
End
 
 
 Eight common actions for a list of strings 
 count the number of strings in a list: 
 Fontcount:=screen.fonts.count 
 Access to the specified string: 
 memol.lines.strings[0]:= ' is the ' the ' '. 
 <=> memol.lines[0]:= ' This is the ' the ' '; 
 Find the location of the string: FileListBox1.Items.IndexOf (' AUTOEXEC. BAT ') 
 Note: You can only find a partial string that matches the full string. Returns the value of the position) 
 Add a string to the list: 1.Add 2.Insert (2, ' Three ') if less than three exceptions are generated. 
 Moves the string in the list: Move (2,4);//Moves the third string to the fifth 
 Copy a complete list of strings: 
 Outline1.lines:=combobox1.items;//Copy List < overlay 
 Outline1.addstrings (Combobox1.items); Connection List < add to tail 
 Delete the string in the list: Delete (I:integer) i:0 ... N 
 with Listbox1.items do 
 begin 
 If Indexof (' bureaucracy ') >-1 then 
 Delete (Indexof (' bureaucracy ')); 
 End 
 Load, save string list: 
 The following code mounts the Autoexec.bat file and backs up the file name with Autoexec.bak. 
 Procedure Tform1.formcreat (sender:tobject); 
 var 
 filename:string; 
 Begin 
 Filename:= ' c:/autoexec. BAT '; 
 with Memo1 do 
 begin 
 LoadFromFile (filename) 
 SaveToFile (changefileext (filename, ' BAK ')); 
 End  
 End; 
 
 
 Nine action on a file: 
 Text file: definition: var textfilevar:text; 
 1. The opening of a text file requires two steps: 
 (1). File variables are associated with file names; 
 AssignFile (Textfilevar, filename); 
 (2). Initialize read/write (three ways) 
 1>. Reset: Open the file for reading and move the file pointer to the top of the file; 
 2>. Rewrite: Creates a new file for writing; 
 3>. Append: Opens the existing file for writing and positions the file pointer at the end of the file. 
 Note: An I/O exception is thrown when the reset or append procedure is used and the file does not exist. The 
 I/O Exception class Einouterror is created after an attempt to operate on a file or peripheral in a program run, and it derives from exception by adding a public data member errorcode to save the code for the error that occurred. This member can be used to take a different approach to different situations after an I/O exception occurs. 
 When a compilation indicates {$I-} is set, the I/O exception class is not generated and the error code is returned to the predefined variable ioresult. 
 2. Closing of text file: CloseFile 
 3. Read/write to text file: Read (LN) (textfilenamevar,num1,num2,...) 
 4. Editing of text files: Memo1.Lines.LoadFromFile (textfilename) 
                     Memo1.Lines.SaveToFile (textFileName); 
 
Record file var recordfilevar:file of RecordType
No type file
Non-type files provide the underlying I/O channel and can be used to access files with variable length records. After the commonly used
In the copy operation of the file. There are better ways to do this in Delphi, so files with no type are rarely used. Can
See Blockread, blockwrite two online Help topics.
Delphi's file Management standard process:
1. Open and close the file:
AssignFile: Correlate an external file name with a file variable
Reset: Open a file that exists
Rewrite: Create and open a new file (or overwrite an existing file)
Append: Opens a file as an addition (applies only to text files)
CloseFile: Close an open file
FileOpen: Opens a specific file and returns a handle to the file
Filecreate: Creates a file with a given filename and returns a file handle
FileClose: Closes a file with a specific handle
Note: The following three files are primarily for internal use within the system, and in the programming of file copying
are often used. The objects they manipulate are file handles rather than file variables.
 
2. File positioning:
Seek: Move the current position of the file to the specified section
Filepos: Returns the current location of the file
Eoln: Return line End Flag
EOF: Return file End Flag
FileSeek: Change the position of the current file pointer
Note: The difference between Seek and FileSeek is:
<1>. Seek is used only for recording files;
<2>. The FileSeek parameter is the file handle, offset, and start position. Where the starting position has a file
The first, current position, the end of the file three choices. The argument for seek is a file variable, an offset, or an offset
Position from the beginning of the file. 3. The offset of the FileSeek is computed in bytes, while Seek is the root
Movement according to the record number. < routines See Delphi Primary Tutorial File Management (ii) >
 
3. File deletion and truncation:
Erase: Deletes a file that exists
DeleteFile: Delete a file
Truncate: Truncate files from the current location of the file
Note: The difference between erase and DeleteFile is that erase takes a file variable as a parameter, and when the file cannot
An exception is caused when the deletion occurs; deletefile the file name as a parameter, when the file does not exist or cannot be deleted
Returns false in addition to, without causing an exception.
 
4. Part name operation
Rename: File Rename, file variable as action object
RenameFile: File name renamed, parameter is the original name of the file and new names
Changefileext: Changing the file name extension
Expandfilename: Return file full path name
Extractfileext: Returns the file name extension
Extractfilename: Returns the filename from the full path name
Extractfilepath: Returns the path to a specific file
 
5. File properties
Filegetattr: Returning file properties
Filesetattr: Setting file properties
 
6. File status
FileSize: Returns the size of the file object
IOResult: Returns the status of the last I/O operation
FileExists: Detects if a file exists
 
7. File Date
Datetimetofiledate: Convert Delphi date format to DOS date format
Filedatetodatetime: Convert the DOS date format to Delphi date format
Filegetdate: Returns a DOS date timestamp for a file
Filesetdate: Set the file's DOS date time stamp
 
8. File reading and writing
READ,READLN: Reading variables from text or record files
Write: Writes the specified variable to a text or record file
Writeln: Writes the specified variable to a text file and writes a line end flag
Fileread: Reading variables from a specified file
FileWrite: Write data to the specified file
Fileread and FileWrite are the object of the file handle, mainly for internal use of the system.
 
9. Directory operation
MkDir: Create subdirectories of current directory
ChDir: Changing the current directory
Getdir: Returns the current directory for a specific disk
RmDir: Delete an empty directory
 
10. Disk operation
Diskfree: Back to disk free space
DiskSize: Returns the size of a specific disk
6.1.4.11 File Lookup
FileSearch: Find out if a particular file exists in the directory
FindFirst: Find in the directory with the given file name (can contain a match) and the property set of the horse
With the first file
FindNext: Returns the next file that meets the criteria
FindClose: Abort a findfirst/findnext sequence
 
Ten transfer text using the Clipboard (three methods)
1. CopyToClipboard
2. Cuttoclipboard
3. Pastefromclipboard
 
11 Operations on strings:
1. A typical function:
function Stringstatus (const str:string): string;
Begin
Result: = ' address: ' + inttostr (Integer (STR)) +
', Length: ' + inttostr (STR) +
', References: ' +inttostr (Pinteger (Integer (STR)-8) ^) +
', Value: ' + Str;
End
2. Format string:
Format (' Second%d ', [N1, N2]);
Format ('%8d ', [N1]); The sentence converts the number N1 into a 8-character string,
and align the text to the right by padding the D-space, with a minus sign (-) left-aligned.
 
12 types
1. Character type: #78 <=>chr () Ord (k) =78
#9 tabs; #10 line Change; #13 carriage return (enter key)
 
2. Ordered type:
Routine action
DEC decrements the parameter value in the routine by 1 or a specific value, where a specific value can be
The Second optional parameter is defined
INC adds 1 or a specific value to the parameter value in the routine
ODD returns True if the argument is odd
Pred returns the precursor value of a parameter value based on a sequence of parameters in its data type definition
SUCC returns the subsequent value of the parameter value
ORD returns the ordinal number of the parameter value in its data Type value collection
Low returns the minimum value of the ordered data type corresponding to the parameter
High returns the maximum value of the ordered data type corresponding to the parameter
 
 3. Date Time Type 
 Example: FormatDateTime (' yyyy ', ' mm ', ' dd ', ' ' Day ', now ') 
 present: Return to Today's datetime date: Back to today's date time: Back to today's times 
 DayOfWeek: Calculates the day of the week on the basis of the passed date parameter 
 Decodedate: Returns a year based on the value of the date. Month. Day value 
 Decodetime: When returned based on the time value. Minutes, seconds, milliseconds 
 Encodedate: Combination year. Month. The day value is tdatetime type value 
 Encodetime: when combined. Minutes. Millisecond value is tdatetime type value 
 
4. Type conversion System routines
Routine action
CHR converts an ordered data to an ANSI character
ORD converts an ordered type value to its ordinal
Round converts an integer value that is rounded after a real value
Trunc converts an integer value that has a real value of fractional truncation
int returns the integer portion of a floating-point number
INTTOSTR converts a numeric value to a string
Inttohex converts a number to a hexadecimal string
Strtoint converts a string to an integer number;
The strtointdef string is converted to an integer, such as a string that is not valid returns a default value
Val converts a string to a number
STR converts a number to a formatted string
Strpas converts a 0-terminated string to a Pascal-type string, in 32-bit
This type of conversion is done automatically in Delphi
Strpcopy copies a Pascal-type string to a 0-terminated string, in 32
This type of conversion is done automatically in the bit Delphi
Strplcopy copy Pascal type string part to a 0 terminating string
Floattodecimal converts a floating-point number to a decimal that contains indices, numbers, and symbols
Floating-point record types
Floattostr A string that converts a floating-point value to the default format
FLOATTOSTRF convert floating-point values to a string of a specific format
Floattotext uses a specific format to copy a floating-point value to a string buffer
FLOATTOTEXTFMT uses a specific format to copy a floating-point value to a string buffer
Strtofloat converts a Pascal string to a floating-point number
Texttofloat converts a 0-terminated string to a floating-point number
Note: In the most recent version of the Delphi Pascal compiler, the Round function is
The CPU is based on the FPU (floating point part) processor. This kind of processor uses the so-called
Banker rounding, that is, when you implement the round function for intermediate values (such as 5.5, 6.5),
The processor determines whether rounding is based on the singularity and parity of the digits before the decimal point, such as 5.5 Round
The result is 6, and the 6.5 Round result is 6, because 6 is an even number.
 
13 Return car tab down CONTROL
 
 When you need to use the ENTER key instead of the tab button to move down one control, set KeyPress to True, and add 
 The following code to intercept the keystroke: 
 Procedure tform1.formkeypress (sender:tobject; Var Key:char); 
 Begin 
 If key= #13 then {The judge is to press the execution key} 
 if not (ActiveControl is TDbgrid) then 
 begin {Not in the TDbgrid control} 
 key:=# 0; 
 Perform (wm_nextdlgctl,0,0); {Move to Next control}   
 End Else 
 if (ActiveControl are TDbgrid) then{is in TDbgrid control 
 Part} 
 begin 
 with TDbgrid (ActiveControl) do 
 If selectedindex< (FieldCount-1) then 
 selectedindex:=selectedindex+1{move to the next field} 
 else selectedindex:=0; 
 E nd 
 End;