ABS (x) absolute value
Arctan (x) anyway
COS (x) back the string function value
X Power of Exp (X) E
FRAC (X) Take a small number
INT (x)
Ln (x) natural logarithm
SIN (X) is transmitted back to the string function
SQR (x) x * x
SQRT (x) square root
other
PRED (x) PRED ('d') = 'c', PRED (TRUE) = 1;
SUCC (X) SUCC ('Y') = 'Z', SUCC (PRED (x)) = X
ORD (X) finds the serial number in the character set, such as ORD ('A') = 65
CHR (X) CHR (65) = 'a'
Round (x)
Trunc (x) Trunc (4.8) = 4, Trunc ('- 3.6') = - 3
Upcase (x) Upcase ('a') = 'a'
Hi (i) Hi ($ 2A30) = $ 2A
LO (i) LO ($ 2A30) = $ 30
Random (N) generates random integers between [0, N)
SIZEOF (NAME) finds a number of bytes occupying a type or variable in memory
SWAP (NUM) SWAP ($ 3621) = $ 2136
=======================================================================================================================================================
Arithmetic Routines Mathematics Operation
=======================================================================================================================================================
ABS absolute value
-------------------------------------------------- -------
Unit system
Function prototype Function ABS (x);
Description X is an integer OR implement.
example
VAR
R: REAL;
i: integer;
Begin
R: = ABS (-2.3); {2.3}
I: = ABS (-157); {157}
END;
-------------------------------------------------- ------------
Arctan triangle function
-------------------------------------------------- ------------
example
COS
Var r: extended;
Begin
R: = COS (PI);
END;
-------------------------------------------------- ------------
Sin
-------------------------------------------------- ------------
example
VAR
R: extended;
String;
Begin
R: = sin (pi);
STR (r: 5: 3, s);
Canvas.TextOut (10, 10, 'the sin of pi is' s);
END;
-------------------------------------------------- -------- Unit system
Function prototype Function Arctan (x: extended): Extended;
Function prototype Function CoS (x: extended): extended;
Function prototype Function SIN (x: extended): Extended;
-------------------------------------------------- ------------
Description X is the diameter.
Tan (x) === sin (x) / cos (x)
Arcsin (x) = Arctan (X / SQRT (1-SQR (X)))))
Arccos (x) = Arctan (SQRT (1-SQR (X)) / x)
These three are not functions on the left, but the right operation.
example
VAR
R: extended;
Begin
R: = Arctan (Pi);
END;
Example VAR
R: extended;
String;
Begin
R: = sin (pi);
STR (r: 5: 3, s);
Canvas.TextOut (10, 10, 'the sin of pi is' s);
END;
-------------------------------------------------- ------------
FRAC seeks a decimal part of a real number
-------------------------------------------------- ------------
Unit system
Function prototype Function FRAC (X: REAL): REAL
Description X is real.
Example VAR
R: REAL;
Begin
R: = FRAC (123.456); {0.456}
R: = FRAC (-123.456); {-0.456}
END;
------------------------------------------
INT seeks a real number of integers
------------------------------------------
Unit system
Function Prototype Function Int (x: Real): Real;
Description X is real.
Example VAR
R: REAL;
Begin
R: = Int (123.456); {123.0}
R: = INT (-123.456); {-123.0}
END;
------------------------------------------
Pi is the math PI
------------------------------------------
Unit system
Function prototype Function PI: extended;
Explain that it is a function, but we use it as a preset variable!
Pi = 3.1415926535897932385
------------------------------------------
SQR X square
-----------------------------------------
example
VAR
S, TEMP: STRING;
Begin
STR (SQR (5.0): 3: 1, TEMP);
S: = '5 Squared is' TEMP # 13 # 10;
STR (SQRT (2.0): 5: 4, TEMP);
S: = S 'The Square Root of 2 IS' TEMP;
Messagedlg (s, mtinformation, [mbok], 0);
-----------------------------------------
Squorian root of SQRT X
------------------------------------------
Unit system
Function prototype Function SQR (x: extended): Extended;
Function prototype Function SQRT (x: extended): extended;
Example VAR
S, TEMP: STRING;
Begin
STR (SQR (5.0): 3: 1, TEMP);
S: = '5 Squared is' TEMP # 13 # 10;
STR (SQRT (2.0): 5: 4, TEMP);
S: = S 'The Square Root of 2 IS' TEMP;
Messagedlg (s, mtinformation, [mbok], 0);
END;
------------------------------------------
LN natural logarithm
------------------------------------------
example
VAR
E: Real;
String;
Begin
E: = EXP (1.0);
STR (ln (e): 3: 2, s);
S: = 'E =' floattostr (e) '; ln (e) =' S;
Canvas.Textout (10, 10, s);
END;
----------------------------------------
EXP index
------------------------------------------
Unit system
Function Prototype Function LN (X: REAL): REAL;
Function Prototype Function Exp (X: REAL): REAL;
Example VAR
E: Real;
String;
Begin
E: = EXP (1.0);
STR (ln (e): 3: 2, s);
S: = 'ln (e) =' S;
Canvas.Textout (10, 10, s);
END;
------------------------------------------
Date and Time Routines Date and Time Functions
------------------------------------------
Date back now date
Unit sysutils
Function prototype Function Date: tdatetime;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Begin
Label1.caption: = 'Today Is' DateTostr (Date);
END;
------------------------------------------
DateTimetostr Date Time Convert into an internal string (1996/12/20 09:12:20 PM)
------------------------------------------
Unit sysutils
Function prototype Function DateTimetostr (datetime: tdatetime): String;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Begin
Label1.caption: = DateTimetostr (now);
-------------------------------------------------- --------
DateTimetString Date Time Convert to a self-defined string
-------------------------------------------------- -----
Unit sysutils
Function prototype Procedure DateTimetostring (var Result: string; const format:
String; datetime: tdatetime);
Sample Procedure TFORM1.FORMCREATE (Sender: TOBJECT);
VAR
String;
Begin
DateTimetostring (S, 'DDDD, MMMM D, YYYY "AT" hh: mm
AM / PM ', NOW;
Label1.caption: = S;
END;
RESULTS Friday, December 20,1996 At 09:20 PM
-------------------------------------------------- ---------------------------
**** Format format 考 below. Formtdatetime.
-------------------------------------------------- --------
The datetostr date is converted into an internal set string. (1996/12/20)
-------------------------------------------------- --------
Unit sysutils
Function prototype Function DateTostr (date: tdatetime): String;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Begin
Label1.caption: = 'Today Is' DateTostr (Date);
END;
# Date, DateTostr EXAMPLE
-------------------------------------------------- --------
Dayofweek is a few days.
-------------------------------------------------- --------
Unit sysutils
Function Prototype Function Dayofweek (date: tdatetime): Integer;
Note The return value is an integer, 1 to 7.
Sunday is 1.
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Adate: tdatetime;
Days: array [1..7] of string;
Begin
Days [1]: = 'sunday';
Days [2]: = 'monday';
Days [3]: = 'Tuesday';
Days [4]: = 'Wednesday';
Days [5]: = 'Thursday';
Days [6]: = 'frIDay';
Days [7]: = 'SATURDAY';
Adate: = strtodate (edit1.text);
ShowMessage (edit1.text 'is a' days [dayofweek (adate)];
END;
# Stradate, Dayofweek Example --------------------------------------------- -----------
Decodedate varies the date variable to the word TDATE.
-------------------------------------------------- --------
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Present: TDATETIME;
Year, Month, Day, Hour, min, sec, msec: word;
Begin
Present: = NOW;
Decodedate (Present, Year, Month, DAY);
Label1.caption: = 'Today Is Day' INTOSTOSTR (DAY) 'of MONTH'
INTOSTR (MONTH) 'of year' INTOSTR (YEAR);
Decodetime (Present, Hour, Min, Sec, MSEC);
Label2.caption: = 'Time Is Minute' INTOSTR (min) 'of Hour'
INTSTOSTR (HOUR);
END;
# Decodedate, Decodetime Example
-------------------------------------------------- --------
Decodetime converts the TDATETIME type to Word type.
-------------------------------------------------- --------
Unit sysutils
Function prototype Procedure Decodedate (Date: TDATETIME; VAR YEAR, MONTH, DAY: WORD);
Function Prototype Procedure Decodetime (Time: Tdatetime; Var Hour, Min, Sec, Msec: Word);
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Present: TDATETIME;
Year, Month, Day, Hour, min, sec, msec: word;
Begin
Present: = NOW;
Decodedate (Present, Year, Month, DAY);
Label1.caption: = 'Today Is Day' INTOSTOSTR (DAY) 'OF
Month ' INTOSTR (MONTH) ' of year ' INTOSTOSTR (YEAR);
Decodetime (Present, Hour, Min, Sec, MSEC);
Label2.caption: = 'Time is minute' inttostr (min) 'of
Hour ' INTOSTR (HOUR);
END;
-------------------------------------------------- --------
EncodeDate changes the date variable of the Word type to the TDATETIME type.
-------------------------------------------------- ------example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
MyDate: tdatetime;
Begin
MyDate: = Encodedate (strt ", strthannel (edit2.text), start (edit3.text));
Label1.caption: = DATETOSTR (MyDate);
END;
-------------------------------------------------- -----
Encodetime changes the time variable of the Word type to the TDATETIME type.
-------------------------------------------------- --------
Unit sysutils
Function prototype Function Encodedate (Year, Month, Day: Word): TDATETIME
Function prototype Function EncoDetime (Hour, min, sec, msec: word):
TDATETIME;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
MyDate: tdatetime;
Mytime: tdatetime;
Begin
MyDate: = Encodedate (83, 12, 31);
Label1.caption: = DATETOSTR (MyDate);
Mytime: = Encodetime (0, 45, 45, 7);
Label2.caption: = Timetostr (MyTime);
END;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Mytime: tdatetime;
Begin
Mytime: = Encodetime (0, 45, 45, 7);
Label1.caption: = Timetostr (MyTime);
END;
-------------------------------------------------- --------
FormatDateTime converts the date time in format format to a string.
-------------------------------------------------- --------
Unit sysutils
Function prototype Function FormatdateTime (const format: string; datetime:
TDATETIME: STRING;
**** Similar to DateTimetostring.
Format format
C The format of the memory shortdateformat. (1996/12/20 09:20:15 PM).
D Date, not add 0. 1-31)
DD date, previously added 0. (01-31)
DDD week. (Sunday).
DDDD Chinese version 2.01, the same.
DDDDD date. (1996/12/20)
DDDDD Date. (December 20, 1996)
Month, not added to 0. (1-12)
MM month, front, 0. (01-12)
MMM Chinese display. (December)
MMMM Chinese version 2.01, the same.
YY year. (00-99)
YYYY year. (0000-9999)
H hours. (0-23)
HH hours. (00-23)
N minutes. (0-59)
NN minutes. (00-59)
s second. (0-59)
SS seconds. (00-59)
T time. (09:20 pm)
TT time. (09:20:15 pm)
AM / PM separately displays AM OR PM. (If uppercase, the uppercase is displayed) A / P separately displays A or P.
example
The Following Example Assigns 'The Meeting Is On Wednesday, February 15, 1995 At 10:30 am' to the string variable s.
S: = formatdatetime ('"The Meeting IS On" DDDD, MMMM D, YYYY, "AT" HH: MM AM / PM',
StrtodateTime ('2/15/95 10:30 am')); //???
-------------------------------------------------- --------
NOW back to the current date time.
-------------------------------------------------- --------
Unit sysutils
Function prototype Function now: TDATETIME;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Begin
Label1.caption: = datetimetostr (now);
END;
# Now, DateTimetostr Example
-------------------------------------------------- --------
Strtodate turns a string to the TDATETIME type.
-------------------------------------------------- --------
Unit sysutils
Function prototype FUNCTION STRTODATE (const s: string): TDATETIME;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Adate: tdatetime;
Begin
Adate: = strtodate (edit1.text);
Label1.caption: = DATETOSTR (ADATE);
END;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Adate: tdatetime;
Days: array [1..7] of string;
Begin
Days [1]: = 'sunday';
Days [2]: = 'monday';
Days [3]: = 'Tuesday';
Days [4]: = 'Wednesday';
Days [5]: = 'Thursday';
Days [6]: = 'frIDay';
Days [7]: = 'SATURDAY';
Adate: = strtodate (edit1.text);
ShowMessage (edit1.text 'is a' days [dayofweek (adate)];
END;
#Stodate, Dayofweek Example
-------------------------------------------------- --------
StrtodateTime will turn the strings to the date time of the TDATETIME type.
-------------------------------------------------- --------
Unit sysutils
Function prototype Function StrtodateTime (const s: string): TDATETIME; example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
AdatendTime: TDATETIME;
Begin
AdateandTime: = StrtodateTime (Edit1.Text);
Table1.fieldbyName ('TimeStamp'). AsdateTime: = AdatendTime;
END;
-------------------------------------------------- --------
Strtotime converts the string to the TDATETIME type.
-------------------------------------------------- --------
Unit sysutils
Function prototype Function Strtotime (const s: string): TDATETIME;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Atime: TDATETIME;
Begin
Atime: = startIME (Edit1.Text);
IF atime <0.50 THEN
ShowMessage ('Good Morning')
Else
ShowMessage ('GoodAfternoon');
END;
-------------------------------------------------- --------
Time is passed back to the current time.
-------------------------------------------------- --------
Unit sysutils
Function prototype Function Time: TDATETIME;
example
Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT);
VAR
DateTime: TDATETIME;
Str: string;
Begin
DateTime: = Time; // Store The Current Date and Time
Str: = Timetostr (datetime); // Convert The Time Into A String
CAPTION: = Str; // Display the time on the form's caption
{Note this Could Have Been Done with the Following Line Of Code:
CAPTION: = Timetostr (Time);
END;
# TIME, TIMETOSTR EXAMPLE
-------------------------------------------------- --------
Timetostr Time is converted into an internal set string. (09:20:15 pm)
-------------------------------------------------- --------
Unit sysutils
Function prototype Function Timetostr (Time: tdatetime): String;
GetMem Procedure Configuring Memory Programs
NEW Configures the memory space of the nylon P,
The size is the size of the styles.
-------------------------------------------------- --------
Dispose releases the memory configured by NEW.
-------------------------------------------------- ------ Unit system
Function prototype Procedure New (var P: Pointer);
Function Prototype Procedure Dispose (VAR P: POINTER);
Example Type
PListentry = ^ TListentry;
TListentry = Record
Next: plistentry;
Text: String;
Count: integer;
END;
VAR
List, p: plistentry;
Begin
...
NEW (P);
P ^ .next: = List;
P ^ .text: = 'Hello World';
P ^ .count: = 1;
List: = P;
...
Dispose (P);
...
END;
example
Type
STR18 = String [18];
VAR
P: ^ STR18;
Begin
NEW (P);
P ^: = 'now you see it it it it it ...';
Dispose (p); {now you don't ...}
END;
-------------------------------------------------- --------
GetMEM Configure the memory space of the nylurger P, and the size can be set by itself.
-------------------------------------------------- --------
example
VAR
F: File;
Size: integer;
Buffer: pchar;
Begin
AssignFile (f, 'test.txt');
Reset (f, 1);
Try
Size: = filesize (f);
GetMem (buffer, size);
Try
Blockread (f, buffer ^, size);
ProcessFile (buffer, size);
Finally
FreeMem (buffer);
END;
Finally
Closefile (f);
END;
END;
-------------------------------------------------- --------
FreeMem releases the memory configured by GetMem.
-------------------------------------------------- --------
Unit system
Function Prototype Procedure GetMem (var P: Pointer; SIZE: Integer);
Function prototype Procedure FreeMem (VAR P: Pointer [; size: integer]);
Example VAR
F: File;
Size: integer;
Buffer: pchar;
Begin
AssignFile (f, 'test.txt');
Reset (f, 1);
Try
Size: = filesize (f);
GetMem (buffer, size);
Try
Blockread (f, buffer ^, size);
ProcessFile (buffer, size);
Finally
FreeMem (buffer);
END;
Finally
Closefile (f);
END;
END;
============================================= File-management routines file management
=====================================
-------------------------------------------------- --------
ChangefileExt changes the file name
-------------------------------------------------- --------
Unit sysutils
Function prototype Function ChangeFileExt (const filename, extension: string):
String;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
P1: String;
P2: String;
Begin
P1: = 'abc.txt';
P2: = '. INI';
S: = ChangefileExt (P1, P2);
Label1.caption: = S;
END;
Result S == 'Abc.ini'
P1: = 'ABC'
P2: = '. INI'
S == 'abc.ini'
P1: = 'c: /windows/abc.txt'
P2: = '. INI'
S == 'c: /windows/abc.ini'
P1: = 'abc.txt'
P2: = 'INI'
S == 'abcini'
** Note: The first element of P2 must have a little '.ini'
example
Procedure TFORM1.CONVERTICON2BITMAPCLICK (Sender: TOBJECT);
VAR
String;
Icon: ticon;
Begin
OpenDialog1.default: = '.ico';
OpenDialog1.filter: = 'icons (* .ico) | * .ico';
OpenDialog1.Options: = [ofoverwriteprompt, offilemustexist, offidereadonly];
IF openDialog1.execute the
Begin
Icon: = ticon.create;
Try
Icon.LoadFromFile (OpenDialog1.FileName);
S: = ChangefileExt (OpenDialog1.FileName, '. BMP');
Image1.width: = icon.width;
Image1.height: = icon.height;
Image1.canvas.draw (0,0, icon);
Image1.picture.savetofile (s); showMessage (OpenDialog1.FileName Saved to ' S);
Finally
Icon.free;
END;
END;
END;
# Savetofile, Create, Height, Width, Canvas, ChangefileExt Example
-------------------------------------------------- --------
ExpandFileName plus the file name after the current path of the current path
-------------------------------------------------- --------
Unit sysutils
Function prototype Function ExpandFileName (const filename: String): String;
Description Sets the current directory to c: / windows file name is abc.txt
The result is C: /Windows/abc.txt
**** This function is not the path to Abc.txt.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
Begin
S: = ExpandFileName ('abc.txt');
Label1.caption: = S;
END;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT)
Begin
ListBox1.items.add (ExpandFileName (Edit1.Text));
END;
-------------------------------------------------- ----------------
Does the DirectoryExists directory exists -------------------------------------------- --------------------
Unit
FileCtrl
Uses filectrl;
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Begin
IF not Directoryexists ('C: / Temp') THEN
IF not createdir ('c: / temp') THEN
Raise Exception.create ('Cannot Create C: / Temp');
END;
-------------------------------------------------- --------
FORCEDIRECTORIES directory
-------------------------------------------------- -------
Unit FileCtrl
Function prototype Function Forcedirectories (DIR: STRING): Boolean;
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Dir: String;
Begin
DIR: = 'c: / apps / sales / local';
IF Directoryexists (DIR) THEN
Label1.caption: = DIR 'WAS CREATED'
END;
-------------------------------------------------- --------
ExpanduncFileName is the same as above (just getting the path on the network)
-------------------------------------------------- ------ Unit sysutils
Function prototype Function ExpanduncFileName (const filename: String): String;
ExtractFileDir Analysis of the path in the string
Unit sysutils
Function Prototype Function ExtractFileDir (const filename: string): string;
Description Set the S string is c: / windows/abc.txt
The result is C: / Windows
**** The function is to analyze its path by any part of any part.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
P1: String;
Begin
P1: = 'c: /windows/abc.txt';
S: = ExtractFileDir (P1);
Label1.caption: = S;
END;
S == 'c: / windows'
P1: = 'abc.txt'
S == '
P1: = 'c: abc.txt'
S == 'c:'
P1: = 'c: /abc.txt'
S == 'c: /'
-------------------------------------------------- --------
ExtractFileDrive Analysis Stroke Machine Name
-------------------------------------------------- --------
Unit sysutils
Function Prototype Function ExtractFileDrive (const filename: string): string;
**** functionally, only the name of the disc server is passed.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
P1: String;
Begin
P1: = 'c: /windows/abc.txt';
S: = ExtractFileDrive (P1);
Label1.caption: = S;
END;
S: = 'c:'
P1: = 'abc.txt'
S == '
-------------------------------------------------- --------
ExtractFileExt analysis of the file name of the file name in the string
-------------------------------------------------- --------
Unit sysutils
Function prototype FUNCTION EXTRACTFILEEXT (const filename: string): String;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
P1: String;
Begin
P1: = 'c: /windows/abc.txt';
S: = extractfileext (p1);
Label1.caption: = S;
END;
S == '. Txt'
P1: = 'c: / windows / abc'
S == '
Example MyFileSextension: = extractfileext (myFileName);
-------------------------------------------------- ------ ExtractFileName Analysis String Archive Name (Transfer file name only)
-------------------------------------------------- --------
Unit sysutils
Function prototype Function ExtractFileName (const filename: String): String;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
P1: String;
Begin
P1: = 'c: /windows/abc.txt';
S: = ExtractFileName (P1);
Label1.caption: = S;
END;
S == 'abc.txt'
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Backupname: String;
FileHandle: Integer;
Stringlen: Integer;
X: integer;
Y: integer;
Begin
if Savedialog1.execute THEN
Begin
If FileExists (Savedialog1.FileName) THEN
Begin
Backupname: = ExtractFileName (Savedialog1.FileName);
Backupname: = ChangefileExt (backupname, '.bak');
IF not renamefile (Savedialog1.FileName, Backupname) THEN
Raise Exception.create ('unable to create backup file.');
END;
FileHandle: = FileCreate (Savedialog1.FileName);
{Write out the number of rows and columns in the grid.
FileWrite (FileHandle,
StringGrid1.colcount, sizeof (stringgrid1.colcount);
FileWrite (FileHandle,
StringGrid1.rowcount, sizeof (stringgrid1.rowcount);
For x: = 0 to stringgrid1.colcount? 1 do
Begin
For Y: = 0 to stringgrid1.rowcount? 1 do
Begin
{WRITE OUT The Length of Each String, Followed by The String Itself.
Stringlen: = Length (StringGrid1.cells [x, y]);
FileWrite (FileHandle, Stringlen, Sizeof (Stringlen);
FileWrite (FileHandle,
StringGrid1.cells [x, y], length (stringgrid1.cells [x, y]);
END;
END;
FileClose (FileHandle);
END;
END;
## FileExists, Renamefile, FileCreate, FileWrite, FileClose, ExtractFileName Example
-------------------------------------------------- ------ ExtractFilePath analysis string path
-------------------------------------------------- --------
Unit sysutils
Function prototype Function ExtractFilePath (const filename: string): String;
Description Set the S string is c: / windows/abc.txt
The result is a c: / windows example procedure tform1.button1click (sender: TOBJECT);
VAR
String;
P1: String;
Begin
P1: = 'c: /windows/abc.txt';
S: = ExtractFilePath (P1);
Label1.caption: = S;
END;
example
Begin
WITH session do
Begin
CONFIGMODE: = CMSession;
Try
Addstandardalias ('Tempdb', ExtractFilePath (paramstr (0)), 'paradox');
Finally
CONFIGMODE: = CMALL;
END;
END;
## Configmode, AddStandardalias, ExtractFilePath Example
-------------------------------------------------- --------
FileSearch looks for the correct path in the file in the disk
-------------------------------------------------- --------
Unit sysutils
Function prototype Function FileSearch (const name, dirlist: string): String;
Example VAR
String;
Begin
s: = filesearch ('abc.txt', 'c: / window /');
Label1.caption: = S;
END;
Description Replaced C: /Window/abc.txt Can't pass the empty string.
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Buffer: array [0..255] of char;
Filetofind: String;
Begin
GetWindowsDirectory (Buffer, SIZEOF (BUFFER);
FileTofind: = filesearch (Edit1.Text, getCurrentDir ';' buffer);
IF filetofind = 'THEN
ShowMessage ('couldn't Find' Edit1.Text '.')
Else
ShowMessage ('Found' FileTOfind ');
END;
## FileSearch, ShowMessage Example
-------------------------------------------------- --------
Fileage Retrieves the date and time (DOS type) of the file.
-------------------------------------------------- --------
Unit sysutils
Function Prototype Function Fileage (const filename: string): Integer; Description is the change date of the archive content wrap surface in the archive total.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
FileDate1: integer;
Datetime1: tdatetime;
Begin
Filedate1: = fileage ('c: /delphi_d/delphi_help1.txt');
DateTime1: = FileDateTodateTime (FileDate1);
S: = DateTimetostr (datetime1);
Label1.caption: = S;
END;
-------------------------------------------------- --------
FileDateTodateTime converts the DOS type date time to a TDATETIME type.
-------------------------------------------------- --------
Unit sysutils
Function prototype Function FileDateTodateTime (FileDate: Integer): TDATETIME;
-------------------------------------------------- ---------------------------
DateTimetOfileDate converts the datetime of the TDATETIME type to a DOS.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function DateTimetOfileDate (datetime: tdatetime): Integer;
FilegetDate Remove the date and time (DOS type) of the file.
Unit sysutils
Function prototype FUNCTION Filegetdate (Handle: Integer): Integer;
The description is the change date of the archive content wrap surface in the archive total.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
FileHandle: Integer;
String;
FileDate1: integer;
Datetime1: tdatetime;
Begin
FileHandle: = FileOpen ('c: /delphi_d/delphi_help2.txt',
FmopenReadwrite;
IF filehandle> 0 THEN
Begin
FileDate1: = filegetdate (filehandle);
DateTime1: = FileDateTodateTime (FileDate1);
S: = DateTimetostr (datetime1);
FileClose (FileHandle);
End
Else
S: = 'Open file error';
Label1.caption: = S;
END;
-------------------------------------------------- ---------------------------
FileSetDate Sets the date and time (DOS type) of the file.
-------------------------------------------------- ---------------------------
Unit sysutils
Function Prototype Function FileSetdate (Handle: Integer): Integer; Description The return value is 0.
-------------------------------------------------- ---------------------------
Deletefile delete files
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function Deletefile (const filename: string): boolean;
Sample 1 deletefile ('delete.me');
Sample IF FileExists (filename) THEN
IF messageDLG ('do you really want to delete'
ExtractFileName (filename) '?'), []) = IDYES THEN
Deletefile (filename);
## FileExists, deletefile example
-------------------------------------------------- ---------------------------
RenameFile Change the file name
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function RenameFile (const6ame: string): boolean
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Backupname: String;
FileHandle: Integer;
Stringlen: Integer;
X: integer;
Y: integer;
Begin
if Savedialog1.execute THEN
Begin
If FileExists (Savedialog1.FileName) THEN
Begin
Backupname: = ExtractFileName (Savedialog1.FileName);
Backupname: = ChangefileExt (backupname, '.bak');
IF not renamefile (Savedialog1.FileName, Backupname) THEN
Raise Exception.create ('unable to create backup file.');
END;
FileHandle: = FileCreate (Savedialog1.FileName);
{Write out the number of rows and columns in the grid.
FileWrite (FileHandle,
StringGrid1.colcount, sizeof (stringgrid1.colcount);
FileWrite (FileHandle,
StringGrid1.rowcount, sizeof (stringgrid1.rowcount);
For x: = 0 to stringgrid1.colcount? 1 do
Begin
For Y: = 0 to stringgrid1.rowcount? 1 do
Begin
{Write out the length of each string, followed by the string itself.} Stringlen: = Length (StringGrid1.cells [x, y]);
FileWrite (FileHandle, Stringlen, Sizeof (Stringlen);
FileWrite (FileHandle,
StringGrid1.cells [x, y], length (stringgrid1.cells [x, y]);
END;
END;
FileClose (FileHandle);
END;
END;
-------------------------------------------------- ---------------------------
DiskFree disk retention remaining space (Bytes)
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function DiskFree (drive: byte): integer;
Example VAR
String;
Begin
S: = INTOSTR (DiskFree (0) Div 1024) 'KBytes Free.';
Label1.caption: = S;
END;
Description Drive
0 = current disk machine, 1 = A disk machine, 2 = B disk machine ... return value is -1, indicating that the disk machine detection error is indicated.
example
VAR
String;
AMTFREE: INT64;
Total: int64;
Begin
AMTFREE: = DiskFree (0);
Total: = disksize (0);
S: = INTSTR (AMTFREE DIV TOTAL) 'Percent of the space on drive 0 is free:' (Amtfree Div 1024) 'KBytes Free.';
Canvas.Textout (10, 10, s);
END;
## DiskFree, Disksize Example
-------------------------------------------------- ---------------------------
Disksize disk space size (Bytes)
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function Disksize (drive: Byte): Integer;
Example VAR
String;
Begin
S: = INTOSTR (Disksize (0) Div 1024) 'KBytes Free.';
Label1.caption: = S;
END;
Description Drive
0 = Current drive, 1 = A disk, 2 = B disk machine .... If the transmission value is -1, the disk machine detection error is indicated.
## DiskFree, Disksize Example
-------------------------------------------------- ---------------------------
FileExists determines if the file exists.
-------------------------------------------------- ---------------------------
Unit sysutils
Function Prototype Function FileExists (const filename: string): boolean;
Similar to FileExists, Renamefile, FileCreate, FileWrite, FileClose, ExtractFileName Example
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Backupname: String;
FileHandle: Integer;
Stringlen: Integer;
X: integer;
Y: integer;
Begin
if Savedialog1.execute THEN
Begin
If FileExists (Savedialog1.FileName) THEN
Begin
Backupname: = ExtractFileName (Savedialog1.FileName);
Backupname: = ChangefileExt (backupname, '.bak');
IF not renamefile (Savedialog1.FileName, Backupname) THEN
Raise Exception.create ('unable to create backup file.');
END;
FileHandle: = FileCreate (Savedialog1.FileName);
{Write out the number of rows and columns in the grid.
FileWrite (FileHandle,
StringGrid1.colcount, sizeof (stringgrid1.colcount);
FileWrite (FileHandle,
StringGrid1.rowcount, sizeof (stringgrid1.rowcount);
For x: = 0 to stringgrid1.colcount? 1 do
Begin
For Y: = 0 to stringgrid1.rowcount? 1 do
Begin
{WRITE OUT The Length of Each String, Followed by The String Itself.
Stringlen: = Length (StringGrid1.cells [x, y]);
FileWrite (FileHandle, Stringlen, Sizeof (Stringlen);
FileWrite (FileHandle,
StringGrid1.cells [x, y], length (stringgrid1.cells [x, y]);
END;
END;
FileClose (FileHandle);
END;
END;
## FileExists, deletefile example
## FileExists, Renamefile, FileCreate, FileWrite, FileClose, ExtractFileName Example
-------------------------------------------------- ---------------------------
Fileopen opens.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function FileOpen (const filename: string; mode:
Integer: integer;
**** Failed to return -1.
Note The following related file reads are low-order, such as the part of the file in DOS INT 21H.
FmopenRead = 0000;
FMOpenWrite = $ 0001;
FmopenReadwrite = $ 0002;
FMShareCompat = $ 0000;
FMShareExClusive = $ 0010;
FMSharednywrite = $ 0020;
FMSharednyRead = $ 0030;
FMSharedenynone = $ 0040;
FMopenRead Open for Read Access Only.
FMOpenWrite Open for Write Access ONLY.
FmopenReadwrite Open for Read and Write Access.
FMShareCompat Compatible with the Way FCBS Are
OPENED.
FMShareExClusive Read and Write Access is Denied.
FMSharednywrite Write Access Is Denied.
FMSharedenyRead Read Access is Denied.
FMSharednynone Allows Full Access for other.
example
Procedure OpenFORSHARE (const filename: string);
VAR
FileHandle: Integer;
Begin
FileHandle: = FileOpen (filename, fmopenwrite or fmsharedenynone);
IF filehandle> 0 THEN
{Valid File Handle}
Else
{Open Error: FileHandle = Negative Dos Error Code}
END;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
IFILEHANDLE: Integer;
IFileLength: Integer;
IbytesRead: integer;
Buffer: pchar;
i: integer
Begin
IF openDialog1.execute the
Begin
Try
iFileHandle: = FileOpen (OpenDialog1.FileName, FmopenRead);
IFileLength: = Fileseek (ifilehandle, 0, 2);
Fileseek (ifilehandle, 0, 0);
Buffer: = Pchar (AllocMem (iFileLength 1);
IbytesRead = FileRead (ifileHandle, Buffer, IFileLength);
FILECLOSE (ifilehandle);
For i: = 0 to ibytesread-1 do
Begin
StringGrid1.rowcount: = stringgrid1.rowcount 1;
StringGrid1.cells [1, i 1]: = Buffer [i];
StringGrid1.cells [2, i 1]: = INTOSTR (Integer (buffer [i]));
END;
Finally
FreeMem (buffer);
END;
END;
END;
## FileOpen, Fileseek, FileRead Example
-------------------------------------------------- -------------------------- FileCreate
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype FUNCTION FileCreate (const filename: string): integer;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Backupname: String;
FileHandle: Integer;
Stringlen: Integer;
X: integer;
Y: integer;
Begin
if Savedialog1.execute THEN
Begin
If FileExists (Savedialog1.FileName) THEN
Begin
Backupname: = ExtractFileName (Savedialog1.FileName);
Backupname: = ChangefileExt (backupname, '.bak');
IF not renamefile (Savedialog1.FileName, Backupname) THEN
Raise Exception.create ('unable to create backup file.');
END;
FileHandle: = FileCreate (Savedialog1.FileName);
{Write out the number of rows and columns in the grid.
FileWrite (FileHandle,
StringGrid1.colcount, sizeof (stringgrid1.colcount);
FileWrite (FileHandle,
StringGrid1.rowcount, sizeof (stringgrid1.rowcount);
For x: = 0 to stringgrid1.colcount? 1 do
Begin
For Y: = 0 to stringgrid1.rowcount? 1 do
Begin
{WRITE OUT The Length of Each String, Followed by The String Itself.
Stringlen: = Length (StringGrid1.cells [x, y]);
FileWrite (FileHandle, Stringlen, Sizeof (Stringlen);
FileWrite (FileHandle,
StringGrid1.cells [x, y], length (stringgrid1.cells [x, y]);
END;
END;
FileClose (FileHandle);
END;
END;
## FileExists, Renamefile, FileCreate, FileWrite, FileClose, ExtractFileName Example
-------------------------------------------------- ---------------------------
FILECLOSE
-------------------------------------------------- ---------------------------
Unit sysutils
Function Prototype Procedure FileClose (Handle: Integer);
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR
Backupname: String;
FileHandle: Integer;
Stringlen: Integer;
X: integer;
Y: integer;
Begin
if Savedialog1.execute THEN
Begin
If FileExists (Savedialog1.FileName) THEN
Begin
Backupname: = ExtractFileName (Savedialog1.FileName);
Backupname: = ChangefileExt (backupname, '.bak');
IF not renamefile (Savedialog1.FileName, Backupname) THEN
Raise Exception.create ('unable to create backup file.');
END;
FileHandle: = FileCreate (Savedialog1.FileName);
{Write out the number of rows and columns in the grid.
FileWrite (FileHandle,
StringGrid1.colcount, sizeof (stringgrid1.colcount);
FileWrite (FileHandle,
StringGrid1.rowcount, sizeof (stringgrid1.rowcount);
For x: = 0 to stringgrid1.colcount? 1 do
Begin
For Y: = 0 to stringgrid1.rowcount? 1 do
Begin
{WRITE OUT The Length of Each String, Followed by The String Itself.
Stringlen: = Length (StringGrid1.cells [x, y]);
FileWrite (FileHandle, Stringlen, Sizeof (Stringlen);
FileWrite (FileHandle,
StringGrid1.cells [x, y], length (stringgrid1.cells [x, y]);
END;
END;
FileClose (FileHandle);
END;
END;
## FileExists, Renamefile, FileCreate, FileWrite, FileClose, ExtractFileName Example
==============================================
**** It is a number of Handle.
==============================================
FileRead reads the file
-------------------------------------------------- -------------------------- Unit sysutils
Function Prototype Function FileRead (Handle: Integer; Count: Integer): Integer;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
IFILEHANDLE: Integer;
IFileLength: Integer;
IbytesRead: integer;
Buffer: pchar;
i: integer
Begin
IF openDialog1.execute the
Begin
Try
iFileHandle: = FileOpen (OpenDialog1.FileName, FmopenRead);
IFileLength: = Fileseek (ifilehandle, 0, 2);
Fileseek (ifilehandle, 0, 0);
Buffer: = Pchar (AllocMem (iFileLength 1);
IbytesRead = FileRead (ifileHandle, Buffer, IFileLength);
FILECLOSE (ifilehandle);
For i: = 0 to ibytesread-1 do
Begin
StringGrid1.rowcount: = stringgrid1.rowcount 1;
StringGrid1.cells [1, i 1]: = Buffer [i];
StringGrid1.cells [2, i 1]: = INTOSTR (Integer (buffer [i]));
END;
Finally
FreeMem (buffer);
END;
END;
END;
## FileOpen, Fileseek, FileRead Example
-------------------------------------------------- ---------------------------
FileWrite Write into the file
-------------------------------------------------- ---------------------------
Unit sysutils
Function Prototype Function FileWrite (Handle: Integer; Count: Integer): Integer;
example
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Backupname: String;
FileHandle: Integer;
Stringlen: Integer;
X: integer;
Y: integer;
Begin
if Savedialog1.execute THEN
Begin
If FileExists (Savedialog1.FileName) THEN
Begin
Backupname: = ExtractFileName (Savedialog1.FileName);
Backupname: = ChangefileExt (backupname, '.bak');
IF not renamefile (Savedialog1.FileName, Backupname) THEN
Raise Exception.create ('unable to create backup file.');
END;
FileHandle: = FileCreate (Savedialog1.FileName); {Write out the number of rows and columns in the grid.
FileWrite (FileHandle,
StringGrid1.colcount, sizeof (stringgrid1.colcount);
FileWrite (FileHandle,
StringGrid1.rowcount, sizeof (stringgrid1.rowcount);
For x: = 0 to stringgrid1.colcount do
Begin
For Y: = 0 to stringgrid1.rowcount do
Begin
{WRITE OUT The Length of Each String, Followed by The String Itself.
Stringlen: = Length (StringGrid1.cells [x, y]);
FileWrite (FileHandle, Stringlen, Sizeof (Stringlen);
FileWrite (FileHandle,
StringGrid1.cells [x, y], length (stringgrid1.cells [x, y]); // ????????? /
END;
END;
FileClose (FileHandle);
END;
END;
## FileExists, Renamefile, FileCreate, FileWrite, FileClose, ExtractFileName Example
-------------------------------------------------- ---------------------------
Fileseek mobile archive indicator location
-------------------------------------------------- ---------------------------
Unit sysutils
Function Prototype Function Fileseek (Handle, Offset, Origin: Integer): Integer;
Description Origin = 0 Read / write indicators count from the beginning of the file.
Origin = 1 read / write indicators are counted by the current location.
ORIGIN = 2 read / write indicators move to the end of the file.
**** The function is the same as the DOS INT 21H interrupted 42h.
Failure back -1.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
FileHandle: Integer;
FILENAME: STRING;
Buffer: pchar;
String;
Readbytes: Integer;
Begin
Filename: = 'c: /delphi_test/abc.tt';
S: = '1234567890';
If FileExists (fileEname) THEN
FileHandle: = FileOpen (FileName, Fmopenreadwrite)
Else
FileHandle: = FileCreate (filename);
IF FileHandle <0 THEN
Begin
Messagedlg ('Opening Failed ", Mtinformation, [Mbok], 0);
EXIT;
END;
GetMem (Buffer, 100);
Try
Strpcopy (Buffer, s);
FileWrite (FileHandle, Buffer ^, 10);
Fileseek (FileHandle, 4, 0);
ReadBytes: = FileRead (FileHandle, Buffer ^, 100); buffer [readbytes]: = # 0;
Label1.caption: = INTTOSTR (READBYTES) ''
StrPas (buffer);
Finally
FreeMem (buffer);
END;
FileClose (FileHandle);
END;
Results After Archive, Abc.tt has a total of ten bytes such as 1234567890.
Read from the fifth bit, and a total of six bits are taken.
567890
(Displacement is starting from 0)
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
IFILEHANDLE: Integer;
IFileLength: Integer;
IbytesRead: integer;
Buffer: pchar;
i: integer
Begin
IF openDialog1.execute the
Begin
Try
iFileHandle: = FileOpen (OpenDialog1.FileName, FmopenRead);
IFileLength: = Fileseek (ifilehandle, 0, 2);
Fileseek (ifilehandle, 0, 0);
Buffer: = Pchar (AllocMem (iFileLength 1);
IbytesRead = FileRead (ifileHandle, Buffer, IFileLength);
FILECLOSE (ifilehandle);
For i: = 0 to ibytesread-1 do
Begin
StringGrid1.rowcount: = stringgrid1.rowcount 1;
StringGrid1.cells [1, i 1]: = Buffer [i];
StringGrid1.cells [2, i 1]: = INTOSTR (Integer (buffer [i]));
END;
Finally
FreeMem (buffer);
END;
END;
END;
## FileOpen, Fileseek, FileRead Example
-------------------------------------------------- ---------------------------
Filegetttr file properties
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function Filegetttr (const filename: string): integer;
Description FareadOnly = $ 00000001;
Fahidden = $ 00000002;
Fasysfile = $ 00000004;
Favolumeid = $ 00000008;
Fadirectory = $ 00000010;
Faarchive = $ 00000020;
FAANYFILE = $ 0000003F;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
String;
Begin
S: = INTOSTR (Filegetttr ('c: /delphi_d/delphi_help1.txt');
Label1.caption: = S;
END;
-------------------------------------------------- --------------------------- FileSetattr Settings file properties
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function FileSetattr (Const filename: String; Attr: Integer):
Integer;
Description Setting successfully transferred 0
-------------------------------------------------- ---------------------------
FindClose ends FINDFIRST / FINDNEXT
-------------------------------------------------- ---------------------------
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
SR: TSEARCHREC;
FileAttrs: integer;
Begin
StringGrid1.rowcount: = 1;
if CheckBox1.checked Then
FileAtTRS: = Fareadonly
Else
FileAtTRS: = 0;
if Checkbox2.checked THEN
FileAtTRS: = FileAtTRS FAHIDEN
If Checkbox3.checked Then
FileAtTRS: = FileAtTRS FASYSFILE;
if Checkbox4.checked THEN
FileAtTRS: = FileAtTRS FavolumeID;
if Checkbox5.checked THEN
FileAtTRS: = FileAtTRS Fadirectory;
if Checkbox6.checked THEN
FileAtTRS: = FileAtTRS Faarchive;
If Checkbox7.checked Then
FileAtTRS: = FileAtTRS FAANYFILE;
IF FindFirst (Edit1.Text, FileAtTRS, SR) = 0 THEN
Begin
With stringgrid1 do
Begin
IF (sr.attr and fileattrs) = sr.attr THEN
Begin
Cells [1, RowCount-1]: = Sr.Name;
Cells [2, RowCount-1]: = INTOSTR (sr.size);
END;
While FindNext (SR) = 0 DO
Begin
IF (sr.attr and fileattrs) = sr.attr THEN
Begin
Rowcount: = rowcount 1;
Cells [1, RowCount-1]: = Sr.Name;
Cells [2, RowCount-1]: = INTOSTR (sr.size);
END;
END;
FindClose (SR);
END;
END;
END;
## Findfirst, FindNext, FindClose Example
-------------------------------------------------- ---------------------------
Findfirst Looking for the first unit. ----------------------------------------- ------------------------------------
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
SR: TSEARCHREC;
FileAttrs: integer;
Begin
StringGrid1.rowcount: = 1;
if CheckBox1.checked Then
FileAtTRS: = Fareadonly
Else
FileAtTRS: = 0;
if Checkbox2.checked THEN
FileAtTRS: = FileAtTRS FAHIDEN
If Checkbox3.checked Then
FileAtTRS: = FileAtTRS FASYSFILE;
if Checkbox4.checked THEN
FileAtTRS: = FileAtTRS FavolumeID;
if Checkbox5.checked THEN
FileAtTRS: = FileAtTRS Fadirectory;
if Checkbox6.checked THEN
FileAtTRS: = FileAtTRS Faarchive;
If Checkbox7.checked Then
FileAtTRS: = FileAtTRS FAANYFILE;
IF FindFirst (Edit1.Text, FileAtTRS, SR) = 0 THEN
Begin
With stringgrid1 do
Begin
IF (sr.attr and fileattrs) = sr.attr THEN
Begin
Cells [1, RowCount-1]: = Sr.Name;
Cells [2, RowCount-1]: = INTOSTR (sr.size);
END;
While FindNext (SR) = 0 DO
Begin
IF (sr.attr and fileattrs) = sr.attr THEN
Begin
Rowcount: = rowcount 1;
Cells [1, RowCount-1]: = Sr.Name;
Cells [2, RowCount-1]: = INTOSTR (sr.size);
END;
END;
FindClose (SR);
END;
END;
END;
## Findfirst, FindNext, FindClose Example
-------------------------------------------------- ---------------------------
Findnext looks for the next compliant file.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Procedure FindClose (VAR F: TSEARCHREC);
Function prototype Function FINDFIRST (Const path: string; attr: integer;
VAR F: TSEARCHREC): Integer;
Function prototype Function FINDNEXT (VAR F: TSEARCHREC): Integer;
Description Successful transmission back 0
Example VAR
SREC: TSEARCHREC;
Procedure TFORM1.SearchClick (Sender: TOBJECT); Begin
Findfirst ('C: / Delphi / bin /*.* ", FAANYFILE, SREC);
Label1.caption: = SREC.NAME 'IS' INTOSTR (SREC.SIZE)
'Bytes in size';
END;
Procedure TFORM1.AGAINCLICK (Sender: TOBJECT);
Begin
FindNext (SREC);
Label1.caption: = SREC.NAME 'IS' INTOSTR (SREC.SIZE)
'Bytes in size';
END;
Procedure TFORM1.FORMCLOSE (Sender: TOBJECT);
Begin
FindClose (SREC);
end
TsearchRec = Record
Time: integer;
Size: integer;
Attr: integer;
Name: tfilename;
XCludeAttr: Integer;
FindHandle: Thandle;
Finddata: twin32finddata;
END;
==============================================
FLOATING-POINT Conversion Routines floating point digital conversion
==============================================
FLOATTODECIMAL converts floating point numbers to decimal number.
-------------------------------------------------- ---------------------------
Unit sysutils
Function Prototype Procedure Floattodecimal (Var Result: TfloatRec; Const Value;
ValueType: TfloatValue; Precision, Decimals: Integer;
-------------------------------------------------- ---------------------------
FLOATTOSTRF converts floating point numbers to format strings.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function floattostrf (value: extended; Format: tfloatformat;
Precision, Digits: Integer: String;
-------------------------------------------------- -------------------------- FLOATTOSTR converts floating point numbers into strings.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function Floattostr (value: extended): String;
-------------------------------------------------- ---------------------------
FLOATTTEXT converts floating point numbers to format ten into bits.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function Floattotext (Buffer: Pchar; Const value; value): VALUETYPE:
TfloatValue; Format: TfloatFormat; Precision, Digits:
Integer: integer;
-------------------------------------------------- ---------------------------
FLOATTEXTFMT converts floating point numbers to formatted ten into bits.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function FloattotextFMT (Buffer: pchar; const value;
ValueType: TfloatValue; Format: Pchar): Integer;
-------------------------------------------------- ---------------------------
FormatFloat converts floating point numbers to formatted strings.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function Formatfloat (const format: string; value: extended):
String;
-------------------------------------------------- ---------------------------
StrtOFLOAT converts strings to floating point numbers.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function StrtOFLOAT (Const S: String): Extended;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Value: Double;
String;
Begin
S: = '1234.56';
Value: = strtofloat (s);
Label1.caption: = format ('converted to [% 9.3f]', [value]);
END;
Note If the S-string contains non-digital characters, an error signal is generated.
-------------------------------------------------- -------------------------- TEXTTOFLOAT converts the null-terminated string into floating point numbers.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function TEXTTTTOFLOAT (BUFFER: PCHAR; VARUE; VALUETYPE:
TfloatValue): boolean;
===================================================
Flow-Control Routines Process Control Circular
===================================================
Break Terminates from For, While, or Repeat.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Break;
Example VAR
String;
Begin
While True DO
Begin
Readln (s);
Try
IF s = 'THEN BREAK;
Writeln (s);
Finally
{Do Something for All Cases}
END;
END;
END;
-------------------------------------------------- ---------------------------
Continue continues from for, while, or review.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Continue;
Example VAR
F: File;
i: integer;
Begin
For i: = 0 to (filelistbox1.items.count - 1) DO
Begin
Try
IF filelistbox1.selected [i] THEN
Begin
IF not fileexists (filelistbox1.items.strings [i]) THEN
Begin
Messagedlg ('file:' filelistbox1.items.strings [i]
'Not Found', mTerror, [Mbok], 0);
CONTINUE;
END;
AssignFile (f, filelistbox1.items.strings [i]);
Reset (f, 1);
ListBox1.Items.Add (INTTOSTR (FileSize (f)); Closefile (f);
END;
Finally
{Do something here}
END;
END;
END;
example
VAR
F: File;
i: integer;
Begin
For i: = 0 to (filelistbox1.items.count - 1) do begin
Try
IF filelistbox1.selected [i] THEN
Begin
IF not fileexists (fileElistbox1.items.strings [i]) THEN Begin
Messagedlg ('file:' filelistbox1.items.strings [i]
'Not found', mTerror, [Mbok], 0);
CONTINUE;
END;
AssignFile (f, filelistbox1.items.strings [i]);
Reset (f, 1);
ListBox1.Items.Add (INTTOSTR (FileSize (f));
Closefile (f);
END;
Finally
{Do something here}
END;
END;
END;
## Continue, Items, SELECTED EXAMPLE
-------------------------------------------------- ---------------------------
EXIT will leave a program directly.
-------------------------------------------------- ---------------------------
Unit system
Function prototype procedure exit;
-------------------------------------------------- ---------------------------
HALT ends return the job system.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Halt [(EXITCODE: Integer);
Example Begin
IF 1 = 1 THEN
Begin
IF 2 = 2 THEN
Begin
IF 3 = 3 THEN
Begin
Halt (1); {HALT Right Here!}
END;
END;
END;
Canvas.TextOut (10, 10, 'this will not be executed ");
END;
-------------------------------------------------- ---------------------------
The RUNERROR stop program execution and executes Run-Time Error.
-------------------------------------------------- ---------------------------
Unit system
Function Prototype Procedure RuNerror [(ErrorCode: Byte)];
Example Begin
{$ IFDEF Debug}
IF p = nil dam
RUNERROR (204);
{$ ENDIF}
END;
============================================== i / o ROUTINES I / O
=====================================
AssignFile specifies a file variable.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure AssignFile (var f; filename: string);
Note ** A file cannot be repeatedly executed more than two times.
EXAMPLE
VAR
F: TextFile;
String;
Begin
If OpenDialog1.execute Then {Display Open Dialog Box}
Begin
AssignFile (f, openDialog1.filename); {file selected in dialog box}
RESET (F);
Readln (f, s); {Read the first line out of the file}
Edit1.text: = s; {PUT STRING IN A TEDIT CONTOL}
Closefile (f);
END;
END;
## AssignFile, OpenDialog, Readln, Closefile Example
-------------------------------------------------- ---------------------------
Closefile Close the file.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Closefile (VAR F);
#### Assignfile, OpenDialog, Readln, Closefile Example
-------------------------------------------------- ---------------------------
IResult is back to the last time I / O function, is there an error.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function ioresis: integer;
Example VAR
F: file of byte;
String;
Begin
S: = 'c: /ka/aaa.txt';
AssignFile (f, s);
{$ I-}
RESET (F);
{$ I }
IResult = 0 THEN
Label1.caption: = 'FILE SIZE IN BYTES:' INTOSTR (FileSize (f);
Else
Label1.caption: = 'Open Failure';
END;
Note Transfer 0 means there is no error.
EXAMPLE
VAR
F: file of byte;
Begin
IF OpenDialog1.execute THEN Begin
AssignFile (f, openDialog1.filename);
{$ I-}
RESET (F);
{$ I }
IResult = 0 THEN
Messagedlg ('File Size in Bytes:' INTOSTR (FileSize (f)),
Mtinformation, [Mbok], 0)
Else
Messagedlg ('File Access Error', MTWARNING, [Mbok], 0);
END;
END;
-------------------------------------------------- ---------------------------
RESET opens a file available.
-------------------------------------------------- ---------------------------
Unit system
Function Prototype Procedure Reset (var F [: File; Recsize: Word]);
-------------------------------------------------- ---------------------------
ReWrite builds a new file available.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Rewrite (var f: file [; recsize: word]);
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
F: TextFile;
I1, I2, I3: Integer;
S1, S2, S3: STRING;
Begin
I1: = 1234;
I2: = 5678;
I3: = 90;
S1: = 'abcd';
S2: = 'EFGH';
S3: = 'ij';
AssignFile (f, 'c: /ka/aaa.txt');
Rewrite (f);
Write (f, i1);
Write (f, i2);
Write (f, i3);
Write (f, s1);
Write (f, s2);
Write (f, s3);
Write (F, I1, I2, I3);
Write (f, s1, s2, s3);
Writeln (f, i1);
Writeln (f, i2);
Writeln (f, i3);
Writeln (f, s1);
Writeln (f, s2);
Writeln (f, s3);
Writeln (F, I1, I2, I3);
Writeln (f, s1, s2, s3);
RESET (F);
READLN (F, S1);
READLN (F, I1);
Label1.caption: = S1 '' INTOSTR (I1);
Closefile (f);
END;
Results 1234567890abcdefghij1234567890abcdefghij1234..
5678 ..
90 ..
Abcd ..
EFGH..ij ..
1234567890 ..
Abcdefghij ..
Abcdefghij ..
The above is the archive result, two representative # 13 # 10, two bits.
Archiflow by WRITELN, multiple wrap symbols # 13 # 10.
And if Writeln (F, I1, I2, I3) will be used as the same string,
There is no interval between variables, causing the expected effect when READ is caused.
Read result
S1 = 1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ1234
Length 44 and no # 13 # 10 two bits.
I1 = 5678
** Write (f, i1: 10: 2, i2: 8: 2);
Formatted features, like STR.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
F: file of byte;
I1, I2, I3: BYTE;
Begin
I1: = 16;
I2: = 32;
I3: = 48;
AssignFile (f, 'c: /ka/aaa.txt');
Rewrite (f);
Write (f, i1);
Write (f, i2);
Write (f, i3);
Write (F, I1, I2, I3);
I1: = 0;
RESET (F);
READ (F, I1);
Label1.caption: = INTTOSTR (I1);
Closefile (f);
END;
Result File of Byte and File of Record
You can only write and read with Write and Read,
WriteLn and Readln are not available.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Type
PPREC = Record
PP_NO: STRING [5];
PP_NAME: String [10];
PP_AGE: Integer;
PP_SUM: DOUBLE;
END;
VAR
.
Rec2: pprec;
F: file of pprec;
Begin
With Rec Do
Begin
PP_NO: = '0001';
PP_NAME: = 'ABC';
PP_AGE: = 12;
PP_SUM: = 600;
END;
AssignFile (f, 'c: /ka/aaa.txt');
Rewrite (f);
Write (f, REC);
Rec.pp_no: = '0002';
Rec.pp_sum: = 58.2;
Write (f, REC);
REC.pp_no: = '0003';
Rec.pp_sum: = 258.242;
Write (f, REC);
Seek (f, 1);
READ (F, REC2);
Seek (f, 1);
Truncate (f); {delete, only 0 pen}
Canvas.TextOut (5, 10, REC2.pp_no);
Canvas.TextOut (5, 30, REC2.pp_name);
Canvas.TextOut (5, 50, Format ('% d', [REC2.pp_age]));
Canvas.TextOut (5,70, Format ('% f', [REC2.pp_sum]);
Closefile (f);
END;
Result PP_NO Deposit 6 Bytes
PP_NAME deposits 11 bytes
PP_AGE deposits 4 bytes (Integer 4 Bytes)
PP_SUM deposit 8 Bytes (double 8 bytes)
The entire RECORD archives at 16 multiple.
EXAMPLE
VAR f: TextFile;
Begin
AssignFile (f, 'newfile. $$$ ");
ReWrite (f); Writeln (f, 'Just Created File with this text in it ...');
Closefile (f);
END;
-------------------------------------------------- ---------------------------
SEEK mobile archive indicator.
-------------------------------------------------- ---------------------------
Unit system
Function Prototype Procedure Seek (VAR F; N: Longint);
Note Seek starts from 0.
EXAMPLE
VAR
F: file of byte;
Size: longint;
String;
Y: integer;
Begin
IF openDialog1.execute the
Begin
AssignFile (f, openDialog1.filename);
RESET (F);
Size: = filesize (f);
S: = 'File Size in bytes:' INTOSTR (SIZE);
Y: = 10;
Canvas.TextOut (5, Y, s);
Y: = y canvas.textheight (s) 5;
S: = 'Seeking Halfway Into File ...';
Canvas.TextOut (5, Y, s);
Y: = y canvas.textheight (s) 5;
Seek (f, Size Div 2);
S: = 'Position is now' INTOSTR (FilePos (f));
Canvas.TextOut (5, Y, s);
Closefile (f);
END;
END;
## FileSize, Seek, Filepos Example
-------------------------------------------------- ---------------------------
TRUNCATE removes all the files after the current archive indicator location.
-------------------------------------------------- ---------------------------
Unit system
Function Prototype Procedure Truncate (VAR F);
example
VAR
f: file of integer;
I, J: Integer;
Begin
AssignFile (f, 'test.int');
Rewrite (f);
For i: = 1 to 6 do
Write (f, i);
Writeln ('File Before Truncation:');
RESET (F);
While Not Eof (f) DO
Begin
READ (F, I);
Writeln (i);
END;
RESET (F);
For i: = 1 to 3 do
Read (f, j); {read ahead 3 records}
Truncate (f); {cut file off here}
Writeln;
Writeln ('File After truncation:');
RESET (F);
While Not Eof (f) DO
Begin
READ (F, I);
Writeln (i);
END;
Closefile (f);
ERASE (f);
END;
-------------------------------------------------- -------------------------- FilePos passed the position of the current file.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function Filepos (VAR f): longint
Explanation F Can't for TEXT FILE
Document: FilePos (f): = 0;
Layer: EOF (f): = true;
Example VAR
F: file of byte;
String;
Begin
S: = 'c: /ka/abc.txt';
AssignFile (f, s);
RESET (F);
Seek (f, 1);
Label1.caption: = 'Current location:' INTOSTR (FilePos (f));
END;
EXAMPLE
VAR
F: file of byte;
Size: longint;
String;
Y: integer;
Begin
IF openDialog1.execute the
Begin
AssignFile (f, openDialog1.filename);
RESET (F);
Size: = filesize (f);
S: = 'File Size in bytes:' INTOSTR (SIZE);
Y: = 10;
Canvas.TextOut (5, Y, s);
Y: = y canvas.textheight (s) 5;
S: = 'Seeking Halfway Into File ...';
Canvas.TextOut (5, Y, s);
Y: = y canvas.textheight (s) 5;
Seek (f, Size Div 2);
S: = 'Position is now' INTOSTR (FilePos (f));
Canvas.TextOut (5, Y, s);
Closefile (f);
END;
END;
## FileSize, Seek, Filepos Example
-------------------------------------------------- ---------------------------
FILSIZE file length.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function FileSize (VAR F): Integer;
Explanation F Can't for TEXT FILE
If f is the record file, then return to the number of replad,
Otherwise it will return the number of BYTE.
## FileSize, Seek, Filepos Example
-------------------------------------------------- ---------------------------
The EOF test file ends.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function EOF (var f): boolean;
Function prototype Function EOF [(VAR f: text)]: boolean;
Example VAR
F1, F2: TEXTFILE; CH: CHAR;
Begin
IF openDialog1.execute the
Begin
AssignFile (F1, OpenDialog1.FileName);
RESET (F1);
if Savedialog1.execute THEN
Begin
AssignFile (F2, OpenDialog1.FileName);
ReWrite (F2);
While Not Eof (F1) DO
Begin
READ (F1, CH);
Write (F2, CH);
END;
Closefile (F2);
END;
Closefile (f1);
END;
END;
EXAMPLE
VAR
F1, F2: TextFile;
CH: char;
Begin
IF OpenDialog1.execute THEN Begin
AssignFile (F1, OpenDialog1.FileName);
RESET (F1);
if Savedialog1.execute Then Begin
AssignFile (F2, Savedialog1.FileName);
ReWrite (F2);
While Not Eof (F1) DO
Begin
READ (F1, CH);
Write (F2, CH);
END;
Closefile (F2);
END;
Closefile (f1);
END;
END;
-------------------------------------------------- ---------------------------
OpenPictureDialog OpenDialog Opens the file.
-------------------------------------------------- ---------------------------
//Savepicturedialog1.defaultext: = graphiceXtension (Tbitmap);
//SavePictureDialog1.filter: = graphicfilter (tbitmap);
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
DONE: BOOLEAN;
Begin
OpenPictureDialog1.defaultExt: = GraphiceXtension (TICON);
OpenPictureDialog1.FileName: = graphicfilemask (ticon);
OpenPictureDialog1.filter: = graphicfilter (ticon);
OpenPictureDialog1.Options: = [Offilemustexist, OfhideReadOnly, OFNOCHANGEDIR];
While Not Done Do
Begin
If OpenPictureDialog1.execute Then
Begin
IF (off (off (off (off (off (OfExtensionDifferent in OpenPictureDialog1.Options) THEN
Begin
Application.icon.LoadFromFile (OpenPictureDialog1.FileName);
DONE: = true;
end
Else
OpenPictureDialog1.Options: = OpenPictureDialog1.Options - OfExtensionDiffERENT
end
Else {User Cancelle
DONE: = true;
END;
END;
## EOF, Read, Write Example
-------------------------------------------------- -------------------------- ERASE deletes the file.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure ERASE (VAR F);
Explain that you must do it first.
Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
F: TextFile;
Begin
OpenDialog1.title: = 'Delete File';
IF openDialog1.execute the
Begin
AssignFile (f, openDialog1.filename);
Try
RESET (F);
IF messagedlg ('Erase' OpenDialog1.FileName
'?', MTConfirmation, [mbyes, mbno], 0) = mryester dam
Begin
Closefile (f);
ERASE (f);
END;
Except
ON EinouTerror DO
Messagedlg ('File I / O Error.', MTERROR, [Mbok], 0);
END;
END;
END;
EXAMPLE
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
F: TextFile;
Begin
OpenDialog1.title: = 'Delete File';
IF OpenDialog1.execute THEN Begin
AssignFile (f, openDialog1.filename);
Try
RESET (F);
IF messagedlg ('Erase' OpenDialog1.FileName '?',
MTConfirmation, [mbyes, mbno], 0) = mryes then
Begin
Closefile (f);
ERASE (f);
END;
Except
ON EinouTerror DO
Messagedlg ('File I / O Error.', MTERROR, [Mbok], 0);
END;
END;
END;
## Erase, OpenDialog.Title, OpenDialog.FileName Example
-------------------------------------------------- ---------------------------
Rename Change the file name.
-------------------------------------------------- ---------------------------
Unit system
Function Prototype Procedure Rename (VAR F; NewName);
Sample Uses Dialogs;
VAR
F: File;
Begin
OpenDialog1.title: = 'choose a file ...';
IF openDialog1.execute the
Begin
Savedialog1.title: = 'rename to ...';
if Savedialog1.execute THEN
Begin
Assignfile (f, OpenDialog1.FileName); Canvas.TextOut (5, 10, 'Renaming'
OpenDialog1.filename 'to'
Savedialog1.filename);
Rename (f, savedialog1.filename);
END;
END;
END;
EXAMPLE
Uses dialogs;
VAR
F: File;
Begin
OpenDialog1.title: = 'choose a file ...';
IF OpenDialog1.execute THEN Begin
Savedialog1.title: = 'rename to ...';
if Savedialog1.execute Then Begin
AssignFile (f, openDialog1.filename);
Canvas.TextOut (5, 10, 'Renaming' OpenDialog1.FileName 'to'
Savedialog1.filename);
Rename (f, savedialog1.filename);
END;
END;
END;
-------------------------------------------------- ---------------------------
GetDir passed back to the directory of the specified disk.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure getDir (d: byte; var s: string);
Description D
0 = Current drive, 1 = A disk machine, 2 = B disk machine ....
** This file does not check the disk machine error.
Example VAR
String;
Begin
Getdir (0, s); {0 = current drive}
Messagedlg ('Current Drive and Directory:' S,
Mtinformation, [Mbok], 0);
END;
-------------------------------------------------- ---------------------------
MKDIR builds a subdirectory.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure MKDIR (S: String);
Sample Uses Dialogs;
Begin
{$ I-}
{Get Directory Name from Tedit Control}
MKDIR (Edit1.Text);
IResult <> 0 THEN
Messagedlg ('Cannot Create Directory', MtWarning,
[mbok], 0)
Else
Messagedlg ('New Directory Created ", Mtinformation,
[MBOK], 0);
END;
-------------------------------------------------- ---------------------------
RMDir deletes an empty subdirectory.
-------------------------------------------------- -------------------------- Unit System
Function prototype Procedure RMDir (S: String);
Sample Uses Dialogs;
Begin
{$ I-}
{Get Directory Name from Tedit Control}
Rmdir (edit1.text);
IResult <> 0 THEN
Messagedlg ('Cannot Remove Directory', MtWarning,
[mbok], 0)
Else
Messagedlg ('Directory Removed', Mtinformation, [Mbok],
0);
END;
-------------------------------------------------- ---------------------------
CHDIR changes current catalog.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Chdir (S: String);
Example Begin
{$ I-}
{Change to Directory Specified in Edit1}
Chdir (edit1.text);
IResult <> 0 THEN
Messagedlg ('Cannot Find Directory', MTWARNING, [Mbok],
0);
END;
==============================================
Memory-Management Routines Memory Management Circular
==============================================
Allocmem configures memory.
-------------------------------------------------- ---------------------------
Unit sysutils
Function prototype Function Allocmem (size: cardinal): Pointer;
Note FreeMem Releases the memory.
-------------------------------------------------- ---------------------------
GetHeapStatus passed back the memory configuration status of the current HEAP area.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function GetHeapStatus: theapstatus;
-------------------------------------------------- -------------------------- GetMemoryManager passed the entry point of the memory configuration of the current HEAP area.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure GetMemoryManager (Var Memmgr:
TMEMORYMANAGER);
EXAMPLE
VAR
GetMemcount: Integer;
FreeMemcount: Integer;
ReallocMemcount: Integer;
Oldmemmgr: TMEMORYMANAGER;
Function NewgetMem (Size: Integer): Pointer;
Begin
INC; GetMemcount;
Result: = OldMemmgr.getMem (size);
END;
Function NewFreeMem (P: Pointer): Integer;
Begin
INC (FreeMemcount);
Result: = OldMemmgr.FreeMem (P);
END;
Function NewReallocmem (P: Pointer; SIZE: Integer): Pointer;
Begin
INC (ReallocMemcount);
Result: = OldMemmgr.Reallocmem (p, size);
END;
Const
NEWMEMMGR: TMEMORYMANAGER = (
GetMem: NewgetMem;
FreeMem: NewFreeMem;
ReallocMem: NewReallocmem;
Procedure setnewmemmgr;
Begin
GetMemoryManager (OldMemmgr);
SetMemoryManager (newMemmgr);
END;
## GetMemoryManager, SetMemoryManager Example
-------------------------------------------------- ---------------------------
Reallocmem Reconfiguring the memory.
-------------------------------------------------- ---------------------------
Unit systems
Function prototype Procedure ReallocMem (VAR P: Pointer; SIZE: Integer);
-------------------------------------------------- ---------------------------
SetMemoryManager Sets the entry point of the memory configuration of the current HEAP area.
-------------------------------------------------- ---------------------------
Unit system
Function Prototype Procedure SetMemoryManager (Const Memmgr)
TMEMORYMANAGER);
Type
THEAPSTATUS = Record
TotaLaddrspace: cardinal; s
TotalunCommitted: cardinal
Totalcommitted: cardinal;
TotaLLOCATED: cardinal;
Totalfree: cardinal
FREESMALL: Cardinal
Freebig: cardinal; unused: cardinal
Overhead: cardinal;
HeapErrorcode: cardinal
END;
Type
PmemoryManager = ^ TMEMORYMANAGER;
TMEMORYMANAGER = Record
GetMem: Function (Size: Integer): Pointer;
FreeMem: Function (P: Pointer): Integer;
Reallocmem: Function (P: Pointer; SIZE: Integer): Pointer;
END;
EXAMPLE
VAR
GetMemcount: Integer;
FreeMemcount: Integer;
ReallocMemcount: Integer;
Oldmemmgr: TMEMORYMANAGER;
Function NewgetMem (Size: Integer): Pointer;
Begin
INC; GetMemcount;
Result: = OldMemmgr.getMem (size);
END;
Function NewFreeMem (P: Pointer): Integer;
Begin
INC (FreeMemcount);
Result: = OldMemmgr.FreeMem (P);
END;
Function NewReallocmem (P: Pointer; SIZE: Integer): Pointer;
Begin
INC (ReallocMemcount);
Result: = OldMemmgr.Reallocmem (p, size);
END;
Const
NEWMEMMGR: TMEMORYMANAGER = (
GetMem: NewgetMem;
FreeMem: NewFreeMem;
ReallocMem: NewReallocmem;
Procedure setnewmemmgr;
Begin
GetMemoryManager (OldMemmgr);
SetMemoryManager (newMemmgr);
END;
## GetMemoryManager, SetMemoryManager Example
=======================================
Miscellaneous Routines Other Circular
=======================================
Exclude deletes an element in a set of elements.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Exclude (var s: set of t; i: t);
Description Delete I elements in S.
-------------------------------------------------- ---------------------------
Fillchar fills in the element.
-------------------------------------------------- -------------------------- Unit System
Function prototype Procedure Fillchar (VAR X; Count: Integer; Value);
Note COUNT in X in Value.
Example Example
VAR
S: array [0..79] of char;
Begin
{Set to all spaces}
Fillchar (S, SIZEOF (s), ORD ('');
Messagedlg (s, mtinformation, [mbok], 0);
END;
-------------------------------------------------- ---------------------------
Hi is returned to the high element number.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function Hi (x): byte;
Example VAR B: BYTE;
Begin
B: = Hi ($ 1234); {$ 12}
END;
-------------------------------------------------- ---------------------------
Include adds an element to a set of elements.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure Include (Var S: set of t; i: t);
Note Add I element to s.
-------------------------------------------------- ---------------------------
The LO returns to the high level number.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function LO (X): byte;
Example VAR B: BYTE;
Begin
B: = LO ($ 1234); {$ 34}
END;
-------------------------------------------------- ---------------------------
Move from the source variable copy n Bytes to the destination variable.
-------------------------------------------------- ---------------------------
Unit system
Function prototype Procedure (Var Source, DEST; Count: Integer);
Example VAR
A: array [1..4] of char;
B: integer;
Begin
Move (A, B, SIZEOF (B));
{SizeOf = Safety!}
END;
-------------------------------------------------- ---------------------------
Paramcount is directly added to the number of incoming variables directly by the executive file. (Arj.exe a Dr.arj D: *. *)
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function paramcount: Integer; Description If the above example passes back 3
EXAMPLE
VAR
I: integer;
ListItem: string;
Begin
For i: = 0 to ibQuery1.Paramcount - 1 DO
Begin
ListItem: = listbox1.items [i];
Case ibquery1.params [i] .DATYPE OF
FTString:
Ibquery1.params [i] .sstring: = ListItem;
FTSMallint:
Ibquery1.Params [i] .ssmallint: = startDef (ListInTitem, 0);
FTINTEGER:
Ibquery1.Params [i] .asinteger: = startDef (ListIthm, 0);
FTWORD:
Ibquery1.params [i] .asword: = startdef (ListInTitem, 0);
FTBOOLEAN:
Begin
if ListItem = 'True' Then
Ibquery1.Params [i] .asboolean: = TRUE
Else
Ibquery1.params [i] .asboolean: = false;
END;
ftfloat:
Ibquery1.params [i] .ASFLOAT: = STRTOFLOAT (ListIt);
Ftcurrency:
Ibquery1.Params [i] .ascurrency: = strOfloat (ListIt);
FTBCD:
Ibquery1.Params [i] .asbcd: = straopurr (ListItem);
FTDATE:
Ibquery1.params [i] .aSdate: = strtodate (ListItem);
FTTIME:
Ibquery1.params [i] .astime: = startIME (ListItem);
ftdatetime:
Ibquery1.params [i] .asdatetime: = strtodatetime (ListItem);
END;
END;
END;
## paramcount, datatype, startdef, asxxx eXample
-------------------------------------------------- ---------------------------
Paramstr
-------------------------------------------------- ---------------------------
Unit system
Function prototype Function Paramstr (INDEX: Integer): String;
Description Paramstr (0); the name and full directory of the execution file.
(C: /zip/arj.exe)
example
VAR
I: word;
Y: integer;
Begin
Y: = 10;
For i: = 1 to Paramcount DO
Begin
Canvas.TextOut (5, Y, Paramstr (i));
Y: = y canvas.textheight (paramstr (i)) 5;
END;
END;
EXAMPLE
Procedure TFORM1.FormCreate (Sender: TOBJECT);
VAR
i: integer;
For i: = 0 to Paramcount -1 DO
Begin
If LowerCase (Paramstr (i)) = 'beep' tellindows.beep (10000, 1000)
Else
IF (LowerCase) = 'exit' Then
Application.Terminate;
END;
END;
## paramcount, paramstr example
-------------------------------------------------- ---------------------------
Random
-------------------------------------------------- ---------------------------
Unit system
Function Prototype Function Random [(Range: Integer);
Description 0 <= x Example VAR I: integer; Begin Randomize; For i: = 1 to 50 do Begin {WRITE to WINDOW AT Random Locations} Canvas.TextOut (Random (Width), Random (Height), 'Boo!'); END; END; -------------------------------------------------- --------------------------- Randomize messy seed. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Randomize; EXAMPLE VAR I: integer; Begin Randomize; For i: = 1 to 50 do begin {WRITE to WINDOW AT Random Locations} Canvas.TextOut (Random (Width), Random (HEIGHT), 'BOO!'); END; END; ## rDomize, Random Example -------------------------------------------------- --------------------------- SIZEOF passes back the number of bit elements of the X variable. -------------------------------------------------- --------------------------- Unit system Function prototype Function SizeOf (x): integer; Example Type CustRec = Record Name: String [30]; Phone: String [14]; END; VAR P: ^ CustRec; Begin GetMem (p, sizeof (custrec)); Canvas.TextOut (10, 10, 'THE SIZE OF THE RECORD IS' INTSTR (SIZEOF (CustRec)); FreeMem (p, sizeof (custrec); READLN; END; -------------------------------------------------- --------------------------- SWAP exchanges a set of variables. -------------------------------------------------- -------------------------- Unit System Function prototype Function Swap (x); Example VAR X: Word; Begin X: = Swap ($ 1234); {$ 3412} END; -------------------------------------------------- --------------------------- Upcase converts a word to uppercase letters. -------------------------------------------------- --------------------------- Unit system Function prototype Function Upcase (CH: char): char; Sample Uses Dialogs; VAR String; i: integer; Begin {Get string from tedit control} s: = edit1.text; For i: = 1 to Length (s) DO s [i]: = Upcase (s [i]); Messagedlg ('Here IT IN All Uppercase:' S, Mtinformation, [MBOK], 0); END; EXAMPLE VAR String; i: integer; Begin {Get string from tedit control} s: = edit1.text; For i: = 1 to Length (s) DO IF i mod 2 = 0 THEN S [i]: = Upcase (s [i]); Edit1.text: = s; END; =================================================== Ordinal routines sequence ================================================================================================================================================================================= DEC reduces variables. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Dec (var x [; n: longint]); Description Dec (x) ==> x: = x-1; DEC (x, n) ==> x: = x-n; Example VAR INTVAR: Integer; Longintvar: longint; Begin INTVAR: = 10; Longintvar: = 10; Dec (intvar); {Intvar: = Intvar - 1} Dec (longintvar, 5); {longintvar: = longintvar - 5} end; -------------------------------------------------- --------------------------- INC increases variables. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure INC (var x [n: longint]); Description INC (X) ==> x: = x-1; INC (X, N) ==> x: = x-N; Example VAR INTVAR: Integer; Longintvar: longint; Begin INC; {INTVAR: = INTVAR 1} INC (longintvar, 5); {longintvar: = longintvar 5} END; -------------------------------------------------- --------------------------- ODD checks if it is odd. -------------------------------------------------- --------------------------- Unit system Function prototype Function ODD (x: longint): boolean; EXAMPLE Begin IF ODD (5) THEN Canvas.TextOut (10, 10, '5 is odd.') Else Canvas.TextOut (10, 10, 'Something IS ODD!'); END; ======================================== Pointer and Address Routines ======================================== Addr is transmitted back to an item. -------------------------------------------------- --------------------------- Unit system Function prototype Function Addr (x): Pointer; EXAMPLE VAR I: integer; NodenumBers: array [0 .. 100] of integer; Begin With TreeView1 Do Begin For i: = 0 to items.count - 1 DO Begin NodenumBers [I]: = CalculateValue (items [i]); Items [i] .data: = addr (nodenumber [i]); END; END; END; -------------------------------------------------- --------------------------- If the Assigned test indicator variable is NIL. -------------------------------------------------- --------------------------- Unit system Function prototype Function Assigned (VAR P): boolean; Description When @ p = nil ==> Back False Example VAR P: POINTER; Begin P: = NIL; IF assigned (p) THEN Writeln ('you won't see'); GetMem (p, 1024); {p valid} FreeMem (p, 1024); {p no longer valid and still not nil} IF assigned (p) THEN Writeln ('you'll see'); end ==================================== String-formatting routines string formatted ================================== FMTSTR is formatted. -------------------------------------------------- --------------------------- FMTSTR (Var Strresult: string; const format: string; const args: array s; -------------------------------------------------- --------------------------- Format Format (const format: string; const args: array of string): String; -------------------------------------------------- --------------------------- Unit sysutils Function prototype Procedure FMTSTR (Var Result: string; const format: string; Const args: array of const); Function Format (Const Format: string; const args: array of CONST: STRING; Description% D: integer % E: Science % F: fixed point implementation % G: Real % N: Real Number (-D, DDD, DDD.DD ...) % M: Money format % P: Point % s: string % x: HEX Example VAR i: integer; J: Double; String; T: string; Begin T: = format ('% D% 8.2F% S', [I, J, S]); ListBox1.Item.Add (T); END; BubbleSeries1.PercentFormat: = '## 0.0 #%'; EXAMPLE Procedure TFORM1.TABLE1AFTERDELETE (DataSet: TDataSet); Begin Statusbar1.simpletext: = format ('there is% d Records in the table ", [dataset.recordcount]); END; S: = format ('1-? ??????? ??????? -% D, 2-? -% D, 3-? -% d', [10, 20, 30]) ; Format ('% *. * F', [9, 2, 12345.6789]); Format ('% 9.2f', [12345.6789]); Format ('% 3D,% D,% 0: D,% 2: -4d,% d', [1, 2, 3, 4]); '1, 2, 1, 3, 4' ## Afterdelete, Format EXAMPLE ======================================== String-handling routines (pascal-style) string ======================================== Ansicomparestr compares the size of both strings. Language Driver installed. -------------------------------------------------- --------------------------- AnsiCompareText (AnsicompareText This item is not case sensitive). -------------------------------------------------- --------------------------- Unit sysutils VAR S1, S2: STRING; I: integer; Begin S1: = 'a ????'; S2: = '?????'; I: = CompareStr (S1, S2); {i = 0,?.?. S1 = s2} IF i = 0 THEN Messagedlg (S1, '=', S2, MTWARNING, [MBOK], 0); END; Function prototype Function AnsiCompareStr (Const S1, S2: String): Integer; Function prototype Function AnsiCompareText (Const S1, S2: String): Integer; -------------------------------------------------- -------------------------- AnsilowerCase transfers the string to lowercase letters. LANGUAGE DRIVER is installed. -------------------------------------------------- --------------------------- ANSIUPPERCASE turns all strings to uppercase letters. LANGUAGE DRIVE is installed -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function AnsilowerCase (const s: string): String; Function prototype Function AnsiUppercase (const s: string): String; -------------------------------------------------- --------------------------- CompareStr compares the size of both strings. -------------------------------------------------- --------------------------- CompareText (COMPARETEXT is not case sensitive). -------------------------------------------------- --------------------------- Unit sysutils Function Prototype Function CompareStr (Const S1, S2: String): Integer; Function Prototype Function Comparext (Const S1, S2: String): Integer; Example VAR String1, string2: string; I: integer; Begin String1: = 'steve'; String2: = 'steve'; I: = comparestr (string1, string2); {i <0} I <0 THEN Messagedlg ('String1 END; VAR String1, string2: string; I: integer; Begin String1: = 'ABC'; String2: = 'aaa'; I: = comparestr (string1, string2); {i <0} I <0 THEN Messagedlg ('String1 END; EXAMLPE Var columntosort: integer; The oncolumnclick event handler sets the global variable to indeicate the column to sort and calls alphasort: Procedure TFORM1.ListView1ColumnClick (Sender: Tobject; Column: TListColumn); Begin COLUMNTOSORT: = column.index; Sender as tcustomlistView .alphas. END; THE LIST VIEW To Sort On The Sore (Sender: Tobject; Item1, Item 2: TlistIn); Data: Integer; Var Compare: Integer; VAR IX: integer; Begin IF columntosort = 0 THEN Compare: = compareText (item1.caption, item2.caption) Else Begin IX: = columntosort - 1; Compare: = compareText (item1.subitems [ity], item2.subitems [ity]); END; END; ## ONCOLUMNCLICK, AlphaSort, OnCompare, CompareText Example -------------------------------------------------- --------------------------- Concat adds a string. -------------------------------------------------- --------------------------- Unit system Function prototype Function Concat (S1 [, S2, ..., SN]: string: string; Description and S: = S1 S2 S3 ...; Example VAR String; Begin S: = concat ('abc', 'DEF'); {'Abcde'} END; VAR String; Begin S: = '?' '????' '???????? ??????' S: = concat ('?', '????', '???????? ??????'); //? ????? ??????? s: = '? ???? ??????? ?????? END; -------------------------------------------------- --------------------------- Copy copies from the mother character string to another string. -------------------------------------------------- --------------------------- Unit system Function prototype Function Copy (S: String; Index, Count: Integer): String; Description S: String. INDEXD: From the first few positions. Count: A total of a few copies. Sample var s: string; Begin S: = 'Abcdef'; S: = COPY (S, 2, 3); {'bcd'} END; ---------------- VAR String; Begin S: = '??????'; S: = COPY (S, 3, 4); // s: = '????' END; --------------- EXAMPLE Procedure TFORM1.COMBOBOX1KEYPRESS (Sender: Tobject; Var Key: char); var Found: boolean; I, SELST: Integer; Tmpstr: String; Begin {FIRST, Process the keyStroke to obtain the current string} {This code requires all items in list to be uppercase} IF key in ['a' .. 'z'] THEN DEC (key, 32); {force Uppercase Only!} With (Sender As Tcombobox) DO Begin SELST: = SELSTART; IF (key = chr (vk_back)) and (selLength <> 0) THEN Tmpstr: = Copy (Text, 1, SELSTART) COPY (Text, Sellength SELSTART 1, 255) Else if key = chr (vk_back) THEN {SELLENGTH = 0} Tmpstr: = COPY (Text, 1, SELSTART-1) Copy (Text, SELSTART 1, 255) Else {key in ['a' .. 'z', etc]} Tmpstr: = Copy (Text, 1, SELSTART) Key Copy (Text, SelLength SELSTART 1, 255); IF tmpstr = 'Then exit; {Update selst to the current insertion point} IF (key = chr (vk_back)) and (selst> 0) THEN DEC (SELST) Else if Key <> chr (vk_back). Inc (selst); Key: = # 0; {INDICATE THAT Key Was Handled} IF selst = 0 THEN Begin TEXT: = '; EXIT; END; {Now TMPSTR IS The Currently Typed String, See IF We can Locate a match} Found: = false; For i: = 1 to items.count do IF Copy (items [i-1], 1, length (tmpstr)) = tmpstr kil Begin Text: = items [i-1]; {Update to the match there is found} ItemIndex: = I-1; Found: = True; Break; END; If Found the untyped end of the string} Begin SELSTART: = SELST; SELLENGTH: = Length (Text) -Selst; end Else Beep; END; END; ----------------------- Procedure tComponiteTendeditor.copy; VAR AFORMAT: WORD; Adata, APALETTE: THANDLE; Begin WITH COMPONENT AS TIMAGE DO Begin Picture.saveToClipboardFormat (AFORMAT, Adata, Apalette); Clipboard.Setashandle (AFORMAT, ADATA); END; END; ## Copy, Chr, SELSTART, SELLENGTH EXAMPLE -------------------------------------------------- --------------------------- Delete deletes several characters in the string. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Delete (var s: string; index, count: integer); Description S: String. INDEXD: From the first few positions to delete. Count: A total of several people. Example VAR String; Begin S: = 'Honest Abe Lincoln'; Delete (s, 8, 4); Canvas.TextOut (10, 10, s); {'honest lincoln'} END; VAR String; Begin S: = '???????, ??????, ??????????!'; Delete (s, 8, 1); // s: = '??????? ??????????????????!' Messagedlg (s, mtwarning, [mbok], 0); END; -------------------------------------------------- --------------------------- Newstr Configures a new string space to the PString metrics in HEAP. -------------------------------------------------- --------------------------- DisposeStr releases a string space PString index in HEAP. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function NewsTr (const s: string): pstring; Function prototype Procedure DisposeStr (P: pstring); Description S: String. Pstring: New string indicator. Example VAR P: pstring; String; Begin S: = 'ask me About blaise'; P: = newsTr (s); DisposeStr (P): END; -------------------------------------------------- --------------------------- INSERT Inserts a sub-string into another string. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Insert (Source: String; varing; index: integer); Description Source: Sub strings. S: The mother character string is inserted. Indexd: Insert from the first few digits. Example VAR String; Begin S: = 'honest lincoln'; INSERT ('Abe', S, 8); {'honest Abe lincoln'} END; VAR String; Begin S: = '??????? ?????? ??????????.'; INSERT ('!', S, 8); {s: = '???????! ?????????????????.'} Messagedlg (s, mtwarning, [mbok], 0); END; -------------------------------------------------- --------------------------- INTTOHEX turns int to HEX. -------------------------------------------------- --------------------------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR i: integer; Begin Label1.caption: = '; For i: = 1 to length (edit1.text) DO Begin Try Label1.caption: = label1.caption INTTOHEX (Edit1.Text [i], 4) ''; Except BEEP; END; END; END; EXAM: Edit2.Text: = (StrtOINT (Edit1.Text), 6); -------------------------------------------------- --------------------------- INTSTR turns int to STR. -------------------------------------------------- --------------------------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Try Label1.caption: = INTTOSTR (STRTOINT (EDIT1.TEXT) * STRTOINT (EDIT2.TEXT)); Except ShowMessage ('You Must Specify Integer Values. Please try again.'); END; END; -------------------------------------------------- --------------------------- StrtOINT converts the STR to INT. -------------------------------------------------- --------------------------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR I: integer; J: integer; Begin I: = strtoint (edit1.text); J: = start (edit2.text); ShowMessage (INTTOSTR (i J)); END; -------------------------------------------------- --------------------------- StrtoinTdef converts the STR to int. When the conversion is incorrect, the value of the default is returned. -------------------------------------------------- -------------------------- Unit sysutils Function prototype Function INTTOHEX (Value: Integer; Digits: integer): String; Function prototype Function INTOSTR (Value: Integer): String; Function prototype Function Strtoint (const s: string): Integer; Function prototype Function StrtoinTdef (Const S: String; Default: Integer): Integer; Description Value: Integer wants to convert. DIGITS: HEX wants to convert to several digits. Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Edit2.text: = INTTOHEX (StrtOINT (Edit1.Text), 6); END; Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Value: integer; Begin Value: = 1234; Edit1.text: = INTTOSTR (Value); END; Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR String; I: integer; Begin S: = '22467'; I: = start (s); INC (I); Edit1.Text: = INTTOSTR (i); END; Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Numberstring: string; Number: integer; Begin NumBerstring: = edit1.text; Number: = STRTOINTDEF (Numberstring, 1000); Edit2.Text: = INTOSTR (NUMBER); END; EXAMPLE VAR I: integer; ListItem: string; Begin For i: = 0 to query1.Paramcount - 1 DO Begin ListItem: = listbox1.items [i]; Case Query1.Params [i] .dattype of FTString: Query1.Params [i] .sstring: = ListIn FTSMallint: Query1.Params [i] .ssmallint: = startDef (ListInTitem, 0); FTINTEGER: Query1.Params [i] .asinteger: = startDef (ListInTitem, 0); FTWORD: Query1.Params [i] .asword: = startdef (ListInTitem, 0); FTBOOLEAN: Begin if ListItem = 'True' Then Query1.Params [i] .asboolean: = true Else Query1.Params [i] .asboolean: = false; END; ftfloat: Query1.Params [i] .asfloat: = struploat (ListIt); Ftcurrency: Query1.Params [i] .ascurrency: = struploat (ListIt); ftbcd: Query1.Params [i] .asbcd: = STRTOCURR (ListItem); FTDATE: Query1.Params [i] .aSdate: = strtodate (ListItem); FTTIME: Query1.Params [i] .astime: = startIME (ListItem); ftdatetime: Query1.Params [i] .asdatetime: = startATETIME (ListItem); END; END; END; ---------------------------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Number: integer; Begin Number: = STRTOINTDEF (Edit1.Text, 1000); Edit2.Text: = INTOSTR (NUMBER); END; ------------------- ## paramcount, datatype, startdef, asxxx eXample -------------------------------------------------- --------------------------- The STR converts the numerical value to a formatted string. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Str (x [: width [: decimals]; var s); Description X: Integer OR implementation of the conversion. Width: Formatting length. (Integer) Decimals: Different points. (Integer) Example Function makeitastring (i: longint): string; {Convert Any Integer Type to A String} VAR String [11]; Begin STR (i, s); Makeitastring: = S; END; Begin Canvas.TextOut (10, 10, makeitastring (-5322)); END; -------------------------------------------------- --------------------------- VAL converts the strings into numbers. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Val (s; var v; var code: integer); Description S: String to convert. V: The integer OR implementation after conversion. Code: code = 0 indicates successful conversion. Sample Uses Dialogs; VAR I, Code: Integer; Begin {Get text from tedit control} Val (Edit1.Text, I, Code); {ERROR DURING CONVERSION TO INTEGER?} IF Code <> 0 THEN Messagedlg ('Error At Position:' INTOSTR (CODE), MTWARNING, [Mbok], 0); Else Canvas.Textout (10, 10, 'Value =' INTTOSTR (i)); readln; END; -------------------------------------------------- --------------------------- Length string length. -------------------------------------------------- --------------------------- Unit system Function prototype Function Length (S: String): Integer; Description S: String to convert. Example VAR String; Begin S: = 'The Black Knight'; Canvas.TextOut (10, 10, 'string length =' INTOSTR (Length (s))); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR i: integer; Begin Label1.caption: = '; For i: = 1 to length (edit1.text) DO Begin Try Label1.caption: = label1.caption INTTOHEX (Edit1.Text [i], 4) ''; Except BEEP; END; END; END; example Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR String; Begin S: = MEMO1.TEXT; Label1.caption: = '' INTOSTR (Length (s)); END; VAR String; I: integer; Begin S: = '? ???? ??????????????'; I: = Length (s); // i: = 22 Messagedlg ('????? ?????? =' INTOSTR (i), MTWARNING, [Mbok], 0); END; ## Length, INTTOHEX EXAMPLE -------------------------------------------------- --------------------------- POS looks for the location of the substring in the maternal string. -------------------------------------------------- --------------------------- Unit system Function prototype Function POS (SUBSTR: STRING; S: STRING): Integer; Description Substr: Sub string. S: Mother Letter. example Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Var s: string; Begin S: = '1234.5'; {Convert Spaces to Zeroes} While Pos ('', s)> 0 do S [POS ('', s)]: = '0'; Label1.caption: = S; Label1.font.size: = 16; END; VAR String; I: integer; Begin S: = '? ???? ??????????????'; I: = POS ('???', s); // i: = 3 END; // Demo 001234.50 // blank character string -------------------------------------------------- --------------------------- LowerCase turns all strings to lowercase letters. -------------------------------------------------- --------------------------- Unit system Function prototype Function LowerCase (const s: string): string; Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Edit2.Text: = LowerCase (Edit1.Text); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Label1.caption: = LowerCase (edit1.text); END; VAR String; Begin S: = LowerCase ('????????. TXT'); // s: = '????????. Txt' END; -------------------------------------------------- --------------------------- Uppercase turns all strings to uppercase letters. -------------------------------------------------- --------------------------- Unit sysutils Function Prototype Function Uppercase (const s: string): string; Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR I: integer; Begin For i: = 0 to listbox1.items.count -1 do Listbox1.items [i]: = Uppercase (ListBox1.Items [i]); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR I: integer; Begin For i: = 0 to listbox1.items.count -1 do Listbox1.items [i]: = Uppercase (ListBox1.Items [i]); END; -------------------------------------------------- --------------------------- Trim is cleared in the blank and control character before and after the string. TRIM (const s: string): string; Sysutils VAR String; L: integer; Begin S: = # 13 '???!' # 13; L: = Length (s); // L: = 10 S: = trim (s); // s: = '???!' L: = l-length (s); // L: = 5 Messagedlg ('??????? ???????? -' INTOSTR (L), MtinFormation, [Mbok], 0); -------------------------------------------------- --------------------------- TrimLEFT clears the blank and control character left on the string. Sysutils VAR String; L: integer; Begin S: = # 13 '???!' # 13; L: = Length (s); // L: = 10 S: = trimleft (s); // s: = '???!' # 13 L: = l-length (s); // L: = 3 Messagedlg ('??????? ???????? -' INTOSTR (L), Mtinformation, [Mbok], 0); END; -------------------------------------------------- --------------------------- Trimright clears the blank and control character on the right side of the strings. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Trim (const s: string): String; Function prototype Function Trimleft (const s: string): String; Function prototype Function Trimright (const s: string): String; VAR String; L: integer; Begin S: = # 13 '???!' # 13; L: = Length (s); // L: = 10 S: = trimright (s); // s: = # 13 '???!' L: = l-length (s); // L: = 2 Messagedlg ('??????? ???????? -' INTOSTR (L), Mtinformation, [Mbok], 0); END; -------------------------------------------------- --------------------------- AdjustLinebreaks all changed to the string of wrap symbols to # 13 # 10 -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function AdjustLineBreaks (const s: string): String; ======================================== String-handling routines (null-terminated) string ================================================ "STRALLOC configuration string space. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Stralloc (size: cardinal): PCHAR; Description Size = string maximum space 1 -------------------------------------------------- --------------------------- Strbufsize is sent back to the size of the STRALLOC configuration space -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function strbufsize (str: pchar): cardinal -------------------------------------------------- --------------------------- The STRCAT string is added. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function StRCAT (DEST, SOURCE: PCHAR): PCHAR; Sample uses sysutils; Const Obj: pchar = 'object'; Pascal: pchar = 'pascal'; VAR S: array [0..15] of char; Begin Strcopy (S, OBJ); Strcat (s, ''); STRCAT (S, PASCAL); Canvas.TextOut (10, 10, StrPas (s)); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Buffer: pchar; Begin GetMem (Buffer, Length) Length (Edit1.Text) 1); Str copy (buffer, pchar (label1.caption); STRCAT (Buffer, Pchar (Edit1.Text)); Label1.caption: = buffer; Edit1.clear; FreeMem (buffer); END; Const P0: PCHAR = '?????? -'; P1: pchar = '??????????'; P2: PCHAR = '????????'; VAR S1, S2: ARRAY [0..20] OF CHAR; Begin Strcopy (S1, P0); STRCOPY (S2, P0); STRCAT (S1, P1); {S1: = '?????? - ??????????'} STRCAT (S2, P2); {S2: = '?????? - ????????'} messagedlg (S1 # 13 S2, Mtinformation, [Mbok], 0); END; ## Strcopy, STRCAT EXAMPLE -------------------------------------------------- --------------------------- Strcomp compares the two string sizes. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strcomp (str1, str2: pchar): integer; Sample uses sysutils; Const S1: PCHAR = 'WACKY'; S2: PCHAR = 'code'; VAR C: integer; Result: String; Begin C: = STRComp (S1, S2); IF C <0 Then Result: = 'Is Less Than' Else IF C> 0 Then Result: = 'Is Greater Than' Else Result: = 'Is Equal to'; Canvas.TextOut (10, 10, StrPas (S1) Result STRPAS (S2)); END; EXAMPLE Uses sysutils; Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Msg: String; Compresult: integer; Begin Msg: = edit1.text; Compresult: = strcomp (pchar (edit1.text), pchar (edit2.text)); IF Compresult <0 THEN MSG: = MSG 'Is Less Than' Else IF Compresult> 0 THEN MSG: = MSG 'Is Greater Than' Else Msg: = MSG 'Is Equal to' Msg: = msg edit2.text; ShowMessage (MSG); END; VAR S1, S2: PCHAR; I: integer; RES: String; Begin S1: = 'company'; S2: = 'company'; I: = STRComp (S1, S2); IF I> 0 THEN RES: = '>' ELSE I <0 THEN RES: = '<' else res: = '='; Messagedlg (S1 RES S2, MTINFORMATION, [Mbok], 0); END; -------------------------------------------------- --------------------------- Strcopy copy string. -------------------------------------------------- -------------------------- Unit sysutils Function prototype Function StRCopy (DEST, SOURCE: PCHAR): PCHAR; Sample uses sysutils; VAR S: array [0..12] of char; Begin Strcopy (S, 'ObjectPascal'); Canvas.TextOut (10, 10, StrPas (s)); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Buffer: pchar; Begin GetMem (Buffer, Length) Length (Edit1.Text) 1); Str copy (buffer, pchar (label1.caption); STRCAT (Buffer, Pchar (Edit1.Text)); Label1.caption: = buffer; Edit1.clear; FreeMem (buffer); END; ## Strcopy, STRCAT EXAMPLE -------------------------------------------------- --------------------------- STRDispose releases the space configured by Stralloc or Strnew. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Procedure Strdispose (str: pchar); Sample uses sysutils; Const S: pchar = 'nevermore'; VAR P: pchar; Begin P: = strnew (s); Canvas.TextOut (10, 10, StrPas (P)); STRDispose (P); END; -------------------------------------------------- --------------------------- STRECOPY copy strings and return the string end address. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strecopy (DEST, SOURCE: PCHAR): PCHAR; Sample uses sysutils; Const Turbo: Pchar = 'Object'; Pascal: pchar = 'pascal'; VAR S: array [0..15] of char; Begin StRecopy (Strecopy (STRECOPY (S, Turbo), ''), PASCAL); Canvas.TextOut (10, 10, StrPas (s)); END; EXAMPLE Uses sysutils; Const Turbo: Pchar = 'Object'; Pascal: pchar = 'pascal'; VAR S: array [0..15] of char; Begin StRecopy (Strecopy (STRECOPY (S, Turbo), ''), PASCAL); Canvas.TextOut (10, 10, string (s)); -------------------------------------------------- --------------------------- The Strend Passing string ends. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strend (str: pchar): PCHAR; Sample uses sysutils; Const S: pchar = 'yankee doodle'; Begin Canvas.TextOut (5, 10, 'THE STRINGTH OF "' STRPAS (s) '"IS' INTOSTR (STREND (S) - S)); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR TextBuffer: pchar; PTR: PCHAR; Begin GetMem (TextBuffer, length (edit1.text) 1); Strcopy (TextBuffer, Pchar (Edit1.Text)); PTR: = streven; Label1.caption: = '; While Ptr> = TextBuffer DO Begin PTR: = PTR? 1; Label1.caption: = label1.caption ptr ^; END; FreeMem (TextBuffer); END; VAR Str: pchar; L: word; Begin ... L: = streven - Str; ... END; -------------------------------------------------- --------------------------- Stricomp compares two strings skewers. (Regardless of case) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Stricomp (str1, str2: pchar): integer; Sample uses sysutils; Const S1: PCHAR = 'WACKY'; S2: PCHAR = 'code'; VAR C: integer; Result: String; Begin C: = stricomp (S1, S2); IF C <0 Then Result: = 'Is Less Than' Else IF C> 0 Then Result: = 'Is Greater Than' Else Result: = 'Is Equal to'; Canvas.TextOut (10, 10, StrPas (S1) Result STRPAS (S2)); END; xample Uses sysutils; Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Msg: String; Compresult: integer; Begin Msg: = edit1.text; Compresult: = stricomp (pchar (edit1.text), pchar (edit2.text)); IF Compresult <0 THEN MSG: = MSG 'Is Less Than' Else IF Compresult> 0 THEN MSG: = MSG 'Is Greater Than' Else Msg: = MSG 'Is Equal to' Msg: = msg edit2.text; ShowMessage (MSG); END; VAR S1, S2: PCHAR; I: integer; RES: String; Begin S1: = 'abc'; S2: = 'ABC'; I: = stricomp (S1, S2); {i: = 0,?.?. S1 = s2} IF I> 0 THEN RES: = '>' ELSE I <0 THEN RES: = '<' else res: = '='; Messagedlg (S1 RES S2, MTINFORMATION, [Mbok], 0); END; -------------------------------------------------- --------------------------- Strlcat string is added. (Designation length) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strlcat (DEST, SOURCE: PCHAR; MAXLEN: Cardinal): PCHAR; Sample uses sysutils; VAR S: array [0..13] of char; Begin Strlcopy (S, 'Object', SIZEOF (S) - 1); Strlcat (S, '', SIZEOF (S) - 1); Strlcat (S, 'Pascal', SizeOf (s) - 1); Canvas.TextOut (10, 10, StrPas (s)); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Firsthalf: pchar; Secondhalf: PCHAR; Halflen: integer; Begin Halflen: = Strlen (pchar (edit1.text)) DIV 2; GetMem (Firsthalf, Halflen 2); GetMem (Secondhalf, Halflen 2); FigSthalf ^: = CHR (0); Secondhalf ^: = CHR (0); Strlcat (Firsthalf, Pchar (Edit1.Text), Halflen; STRCAT (Secondhalf, Pchar (Edit1.Text) Halflen; Application.MessageBox (Firsthalf, 'First Half', MB_OK); Application.MessageBox (Secondhalf, 'Second Half', MB_OK); Freemem (Firsthalf); FreeMem (Secondhalf); END; Const S1: PCHAR = '???'; S2: PCHAR = '?????????'; VAR S: array [0..13] of char; Begin Strlcopy (S, S1, Strlen (S1)); Strlcat (S, S2, 6); {s: = '??????'} Messagedlg (s, mtinformation, [mbok], 0); END; ## Strlen, strlcat example -------------------------------------------------- --------------------------- StrlComp compares the size of the two strings. (Designation length) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strlcomp (str1, str2: pchar; maxlen: cardinal): Integer; Sample uses sysutils; Const S1: PCHAR = 'Enterprise' S2: PCHAR = 'enter' VAR Result: String; Begin IF strlcomp (S1, S2, 5) = 0 THEN Result: = 'Equal' Else Result: = 'DIFFERENT'; Canvas.TextOut (10, 10, 'The first Five Characters Are' Result; END; EXAMPLE Uses sysutils; Const S1: PCHAR = 'Enterprise' S2: PCHAR = 'enter' VAR COMSTR: STRING; Begin IF strlcomp (S1, S2, 5) = 0 THEN COMSTR: = 'Equal' Else COMSTR: = 'DIFFERENT'; Canvas.TextOut (10, 10, 'The First Five Characters Are' COMSTR); END; Const S1: PCHAR = '?????????'; S2: PCHAR = '????????'; VAR I: integer; String; Begin I: = 5; IF strlcomp (S1, S2, I) = 0 THEN S: = '?????' Else S: = '????????'; Messagedlg ('??????' INTOSTOSTR (i) '???????? ?????' s, mtinformation, [mbok], 0); END; -------------------------------------------------- --------------------------- Strlcopy copy string. (Specified long) -------------------------------------------------- -------------------------- Unit sysutils Function prototype Function Strlcopy (DEST, SOURCE: PCHAR; MAXLEN: Cardinal): pchar; Sample uses sysutils; VAR S: array [0..11] of char; Begin Strlcopy (S, 'ObjectPascal', SIZEOF (S) - 1); Canvas.TextOut (10, 10, StrPas (s)); END; EXAMPLE Uses sysutils; Const max_buffer = 10; Procedure TFORM1.BUTTON1CLICK (Sender TOBJECT); VAR Buffer: array [0..max_buffer] of char; Begin Strlcopy (Buffer, Pchar (Edit1.Text), Max_Buffer; Application.MessageBox (Buffer, 'Strlcopy Example', MB_OK); END; VAR S: pchar; Begin Strlcopy (s, '?????????', 5); {s: = '?????'} ... END; -------------------------------------------------- --------------------------- Strlen passed back the string length. (Excluding the stop bit) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strlen (str: pchar): cardinal Sample uses sysutils; Const S: pchar = 'e pluribus uniform; Begin Canvas.TextOut (5, 10, 'THE STRINGTH OF "' STRPAS (s) '"IS' INTOSTR (Strlen (s))); END; EXAMPLE Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Firsthalf: pchar; Secondhalf: PCHAR; Halflen: integer; Begin Halflen: = Strlen (pchar (edit1.text)) DIV 2; GetMem (Firsthalf, Halflen 2); GetMem (Secondhalf, Halflen 2); FigSthalf ^: = CHR (0); Secondhalf ^: = CHR (0); Strlcat (Firsthalf, Pchar (Edit1.Text), Halflen; STRCAT (Secondhalf, Pchar (Edit1.Text) Halflen; Application.MessageBox (Firsthalf, 'First Half', MB_OK); Application.MessageBox (Secondhalf, 'Second Half', MB_OK); Freemem (Firsthalf); FreeMem (Secondhalf); END; Consts: pchar = '????? ????? ????? ????????!'; Begin Messagedlg (S # 13 # 10 '?????????????????? =' INTOSTR (Strlen (S)), Mtinformation, [Mbok], 0); END; ## Strlen, strlcat example -------------------------------------------------- --------------------------- Strlicomp compares two string sizes. (Specify long, regardless of case) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strlicomp (str1, str2: pchar; maxlen: Cardinals: Integer; Sample uses sysutils; Const S1: PCHAR = 'Enterprise' S2: PCHAR = 'enter' VAR Result: String; Begin IF Strlicomp (S1, S2, 5) = 0 THEN Result: = 'Equal' Else Result: = 'DIFFERENT'; Canvas.TextOut (10, 10, 'The first Five Characters Are' Result; END; Examply Uses sysutils; Const S1: PCHAR = 'Enterprise' S2: PCHAR = 'enter' VAR COMSTR: STRING; Begin IF Strlicomp (S1, S2, 5) = 0 THEN COMSTR: = 'Equal' Else COMSTR: = 'DIFFERENT'; Canvas.TextOut (10, 10, 'The First Five Characters Are' COMSTR); END; Const S1: PCHAR = '?????????'; S2: PCHAR = '????????'; VAR String; Begin IF strlicomp (S1, S2, 5) = 0 THEN S: = '?????' else s: = '????????'; Messagedlg (S1 # 13 S2 # 13 '??????' INTOSTR (i) '???????? ????? S, Mtinformation, [Mbok], 0); END; -------------------------------------------------- --------------------------- Strlower turns all strings to lowercase letters. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function strlower (str: pchar): PCHAR; example Uses sysutils; Const S: pchar = 'a funny string' Begin Canvas.TextOut (5, 10, StrPas (Strlower (s)) '' STRPAS (STRUPPER (S))); END; -------------------------------------------------- --------------------------- Strmove Copy n bytes from the source string to the climbing R string. (Excluding the stop bit) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strmove (DEST, SOURCE: PCHAR; Count: Cardinal): pchar; Sample uses sysutils; Function aheapastring (s: pchar): pchar; {Allocate String on Heap} VAR L: cardinal; P: pchar; Begin Strnew: = nil; IF (s <> nil) and (s [0] <> # 0). Begin L: = Strlen (s) 1; GetMem (p, l); Strnew: = Strmove (P, S, L); END; END; Procedure disposedaString (s: pchar); {Dispose String on Heap} Begin IF s <> nil then freemem (s, strlen (s) 1); END; VAR S: pchar; Begin AHEAPASTRING (S); Disposedastring (s); END; VAR S1, S2: PCHAR; Begin S1: = 'Abcdefgh'; Strmove (S2, S1, STRLEN (S1) 1); Strlower (S1); {S1: = 'Abcdefgh'} Strupper (S2); {S2: = 'Abcdefgh'} Messagedlg (S1 # 13 # 10 S2, Mtinformation, [Mbok], 0); END; -------------------------------------------------- --------------------------- Strnew configuration string space. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strnew (str: pchar): PCHAR; EXAMPLE Uses sysutils; Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Temp: pchar; Begin // allocate memory. Temp: = strnew (pchar (edit1.text)); Application.MessageBox (Temp, 'Strnew, Strdispose Example', MB_OK); // deallocate memory.strdispose (TEMP); END; Const S: pchar = '?????????????????; VAR SNEW: PCHAR; Begin SNEW: = STRNEW (S); Messagedlg ('s:' s # 13 'snew:' snew, mtinformation, [mbok], 0); STRDispose (SNEW); END; ## strnew, strdispose example -------------------------------------------------- --------------------------- StrPas turns the null-terminated string to the Pascal-Style string. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function StrPas (str: pchar): String; Sample uses sysutils; Const A: pchar = 'i love the smell of object pascal in the SMELL OF Object Morning. '; VAR String [79]; Begin S: = StrPas (a); Canvas.Textout (10, 10, s); {Note That The Following Also Works} Canvas.TextOut (10, 10, a); END; -------------------------------------------------- --------------------------- Strpcopy Copy the Pascal-Style string to the null-terminated string. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strpcopy (DEST: PCHAR; Source: String): PCHAR; Sample uses sysutils; VAR A: array [0..79] of char; String; Begin S: = 'Honk if you know blaise.'; Strpcopy (a, s); Canvas.TextOut (10, 10, StrPas (a)); END; VAR Source: string; DEST: Array [0..20] of char; Begin Source: = '???????? ??????'; Strpcopy (DEST, SOURCE); Messagedlg (DEST, MTINFORMATION, [Mbok], 0); END; -------------------------------------------------- --------------------------- Strplcopy Copy the Pascal-Style string to the null-terminated string. (Designation length) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strplcopy (dest: pchar; const source: string; maxlen: cardinal): pchar; -------------------------------------------------- --------------------------- The position of the StrPos subster skewers in the maternal string. (First position) -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strpos (str1, str2: pchar): pchar; Description Str1 master string Str2 string EXAMPLE Uses sysutils; Procedure TFORM1.BUTTON1CLICK (Sender TOBJECT); VAR Location: pchar; Begin IF strpos (pchar (edit1.text), Pchar (edit2.text)) <> nil THEN ShowMessage ('Substring Found ") Else ShowMessage ('Substring Not Found'); END; ------------------ Const Substr: PCHAR = 'WWW'; VAR S, r: pchar; Begin S: = 'http://www.atrussk.ru/delphi/'; R: = STRPOS (S, Substr); IF R <> nil damagedlg (r, mtinformation, [mbok], 0) ELSE Messagedlg ('?????????? ?????? URL!', MTerror, [Mbok], 0); END; -------------------------------------------------- --------------------------- The next address of the position of the STRSCAN sub-fifth in the maternal string. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function STRSCAN (Str: pchar; chr: char): pchar; Sample {Return Pointer to Name Part of a full Path name} Uses sysutils; Function namepart (filename: pchar): pchar; VAR P: pchar; Begin P: = STRSCAN (filename, '/'); IF p = nil dam Begin P: = STRSCAN (filename, ':'); IF p = nil the p: = filename; END; Namepart: = P; END; VAR String; Begin S: = STRPAS (Namepart ('c: /test.fil'); Canvas.Textout (10, 10, s); END; Const S: pchar = 'myfile.zzz'; VAR R: pchar; Begin R: = STRSCAN (S, '.'); {R: = '.zzz'} Messagedlg (r, mtinformation, [mbok], 0); END; -------------------------------------------------- --------------------------- The position of the STRSCAN subscriber in the mother character string. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strscan (str: pchar; chr: char): pchar; Sample uses sysutils; Function Haswildcards (filename: pchar): boolean; {Return True if File Name Has Wildcards in it} Begin HaswildCards: = (strscan (filename, '*') <> nil) OR (STRSCAN (filename, '?') <> Nil); END; Const P: pchar = 'c: /test.*'; Begin IF HaswildCards (p) THEN Canvas.TextOut (20, 20, 'the string Has Wildcards') Else Canvas.TextOut (20, 20, 'the string doesn't Have Wildcards') END; Const S: pchar = 'http://www.atrussk.ru'; VAR R: pchar; Begin R: = strscan (s, 'w'); {r: = 'www.atrussk.ru'} Messagedlg (r, mtinformation, [mbok], 0); END; -------------------------------------------------- --------------------------- Strupper will turn the string to uppercase letters. -------------------------------------------------- --------------------------- Unit sysutils Function prototype Function Strupper (str: pchar): PCHAR; Sample uses sysutils; Const S: pchar = 'a funny string' Begin Canvas.TextOut (5, 10, StrPas (Strlower (s)) '' STRPAS (STRUPPER (S))); END; ============================================================================================================================================== TEXT-FILE ROUTINES TEXT-FILE ========================================================= 帖子 开 开 开. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Append (var f: text); Example VAR f: TextFile; Begin IF openDialog1.execute the {BRING UP OPEN FILE DIALOG} Begin AssignFile (f, openDialog1.filename); {Open file selected in dialog} Append (f); {add more text oto end} Writeln (f, 'appended text'); Closefile (f); {Close File, Save Changes} END; END; EXAMPLE VAR f: TextFile; Begin IF openDialog1.execute the Begin {Open a Text File} AssignFile (f, openDialog1.filename); Append (f); Writeln (f, 'I am appending some stuff to the end of the file.'); {INSERT Code Here That Would Require A Flush Before Closing The File} Flush (f); {ENSURES THAT THE TEXT WAS ACTUALLY WRITTEN to FILE} Closefile (f); END; END; ## append, Flush EXAMPLE -------------------------------------------------- --------------------------- The EOLN test file ends. (For text file.) -------------------------------------------------- --------------------------- Unit system Function prototype Function Eoln [(VAR f: text)]: boolean; FLUSH stores the data in buffer into the disk. (For text file) Unit system Function prototype Procedure Flush (var f: text); Example VAR f: TextFile; Begin IF openDialog1.execute the Begin {Open a Text File} AssignFile (f, openDialog1.filename); Append (f); Writeln (f, 'I am appending some stuff to the end of the File. '); Flush (f); {ENSURES THAT THE TEXT WAS ACTUALLY WRITTEN to FILE} {INSERT CODE Here That Would Require A Flush BeforeClosing The File} Closefile (f); END; END; EXAMPLE Begin {TELLS Program to wait for keyboard input} Writeln (eoln); END; -------------------------------------------------- --------------------------- Read read file. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Read (f, v1 [, v2, ..., vn]); Procedure read ([var f: text;] V1 [, v2, ..., vn]); Sample Uses Dialogs; VAR F1, F2: TextFile; CH: char; Begin IF openDialog1.execute the Begin AssignFile (F1, OpenDialog1.FileName); RESET (F1); if Savedialog1.execute THEN Begin AssignFile (F2, OpenDialog1.FileName); ReWrite (F2); While Not Eof (F1) DO Begin READ (F1, CH); Write (F2, CH); END; Closefile (F2); END; Closefile (f1); END; End. -------------------------------------------------- --------------------------- Readln reads. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Readln ([VAR F: text;] V1 [, V2, ..., VN]); Example VAR String; Begin Write ('Enter a line of text:); Readln (s); Writeln ('you type:', s); Writeln ('Hit READLN; END; -------------------------------------------------- --------------------------- SeeKeof test files end. -------------------------------------------------- --------------------------- Unit system Function prototype Function seekeof [(var f: text)]: boolean; Example VAR f: system.TextFile; I, J, Y: Integer; Begin AssignFile (f, 'test.txt'); Rewrite (f); {Create a file with 8 Numbers and some Whitespace At the Ends of the lines} Writeln (f, '1 2 3 4'); Writeln (f, '5 6 7 8'); Reset (f); {read the numbers back. Seekeoln Returns True If There Are No more numbers on the current line; seekeof returns True if there is no more text (Other Than Whitespace) IN The file. Y: = 5; While Not Seekeof (f) DO Begin IF seekeoln (f) THEN Readln; {Go to next line} READ (f, j); Canvas.TextOut (5, y, inteltostr (j)); Y: = y canvas.textheight (INTTOSTR (J)) 5; END; END; -------------------------------------------------- --------------------------- SEEKEOLN test files end. -------------------------------------------------- --------------------------- Unit system Function prototype Function seekeoln [(var f: text)]: boolean; EXAMPLE VAR f: system.TextFile; I, J, Y: Integer; Begin AssignFile (f, 'test.txt'); Rewrite (f); {Create a file with 8 NumBers and some Whitespace at the ends of the lines} Writeln (f, '1 2 3 4'); Writeln (f, '5 6 7 8'); RESET (F); {Read The Numbers Back. Seekeoln Returns True If There no more Numbers on the current line; seekeof returns true if there is no In The File.} Y: = 5; While Not Seekeof (f) DO Begin IF seekeoln (f) THEN Readln; {Go to next line} READ (f, j); Canvas.TextOut (5, y, inteltostr (j)); Y: = y canvas.textheight (INTTOSTR (J)) 5; END; END; ## SeeKeoln, Seekeof Example -------------------------------------------------- --------------------------- SetTextBuf Specifies I / O Buffer to Text File. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure SetTextBuf (var buf [; size: integer]); Sample Uses Dialogs; VAR F, ftwo: system.textfile; CH: char; BUF: Array [1..4095] of char; {4k buffer} Begin IF OpenDialog1.execute Thenbegin AssignFile (f, paramstr (1)); {BIGGER BUFFER for Faster Reads} SetTextBuf (f, buf); RESET (F); {Dump text file in accessher file} AssignFile (ftwo, 'wofuof.dog'); ReWrite (ftwo); While Not Eof (f) DO Begin READ (F, CH); Write (ftwoch); END; System.closefile (f); System.closefile (ftwo); END; END; -------------------------------------------------- --------------------------- Write is written to the file. -------------------------------------------------- --------------------------- Unit system Function prototype WRITE (F, V1, ..., VN); Write ([var f: text;] p1 [, p2, ..., pn]); Procedure TFORM1.BUTTON3CLICK (Sender: TOBJECT); VAR Stream: TBLOBSTREAM; String; Begin With table1 do Begin EDIT; Stream: = CreateBlobStream (FieldByname ('Notes'), BmreadWrite; Try Stream.seek (0, 2); {Seek 0 bytes from the stream's end point} S: = 'this line will be added to the end.'; Stream.write (Pchar (s), Length (s)); Finally Stream.free; END; POST; END; END; -------------------------------------------------- --------------------------- WriteLn is written to the file. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Writeln ([var f: text;] p1 [, p2, ..., pn]); Example VAR String; Begin Write ('Enter a line of text:); Readln (s); Writeln ('you type:', s); Writeln ('Hit READLN; END; ======================================== Transfer Routines Converter ================================================ CHR converts BYTE to the character. -------------------------------------------------- --------------------------- Unit system Function prototype Function CHR (x: Byte): char; Example Begin Canvas.TextOut (10, 10, chr (65)); {The letter 'a'} END; EXAMPLE Procedure TFORM1.COMBOBOX1KEYPRESS (Sender: Tobject; Var Key: char); VAR Found: boolean; I, SELST: Integer; Tmpstr: String; Begin {FIRST, Process the keyStroke to obtain the current string} {This code requires all items in list to be uppercase} IF key in ['a' .. 'z'] THEN DEC (key, 32); {force Uppercase Only!} With (Sender As Tcombobox) DO Begin SELST: = SELSTART; IF (key = chr (vk_back)) and (selLength <> 0) THEN Tmpstr: = Copy (Text, 1, SELSTART) COPY (Text, Sellength SELSTART 1, 255) Else if key = chr (vk_back) THEN {SELLENGTH = 0} Tmpstr: = COPY (Text, 1, SELSTART-1) Copy (Text, SELSTART 1, 255) Else {key in ['a' .. 'z', etc]} Tmpstr: = Copy (Text, 1, SELSTART) Key Copy (Text, SelLength SELSTART 1, 255); IF tmpstr = 'Then exit; {Update selst to the current insertion point} IF (key = chr (vk_back)) and (selst> 0) THEN DEC (SELST) Else if Key <> chr (vk_back). Inc (selst); Key: = # 0; {INDICATE THAT Key Was Handled} IF selst = 0 THEN Begin TEXT: = '; EXIT; END; {Now TMPSTR IS The Currently Typed String, See IF We can Locate a match} Found: = false; For i: = 1 to items.count do IF Copy (items [i-1], 1, length (tmpstr)) = tmpstr kil Begin Text: = items [i-1]; {Update to the match there is found} ItemIndex: = I-1; Found: = True; Break; END; If Found the untyped end of the string} Begin SELSTART: = SELST; SELLENGTH: = Length (Text) -Selst; end Else Beep; END; END; ## Copy, Chr, SELSTART, SELLENGTH EXAMPLE -------------------------------------------------- --------------------------- The maximum of hiGh is transferred back to the foot. -------------------------------------------------- --------------------------- Unit system Function prototype Function High (X); Example [Ordinal Type] Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Low_s: string; HIGH_S: STRING; String; Begin HIGH_S: = 'High =' INTOSTR (High (Word)); Low_s: = 'Low =' INTOSTR (Low (Word)); S: = low_s high_s; Label1.caption: = S; END; S: = Low = 0 high = 65535 [Array Type] Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR P: array [5..21] of double; Low_s: string; HIGH_S: STRING; String; Begin High_s: = 'high =' INTOSTR (high (p)); Low_s: = 'Low =' INTOSTR (Low (P)); S: = low_s high_s; Label1.caption: = S; END; S: = low = 5 high = 21 [String Type] Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR P: string [23]; Low_s: string; HIGH_S: STRING; String; Begin High_s: = 'high =' INTOSTR (high (p)); Low_s: = 'Low =' INTOSTR (Low (P)); S: = low_s high_s; Label1.caption: = S; END; S: = LOW = 0 hight = 23 P: shortstring; S: = LOW = 0 hight = 255 P: string; Long strings are not available, there will be error signals. [Open arch] Function sum (var x: array of double): Double; VAR I: word; S: Double; Begin S: = 0; {Note That Open Array Index Range is always zero-based.} For i: = 0 to high (x) do s: = s x [i]; Sum: = S; END; EXAMPLE Function sum (var x: array of double): Double; VAR I: word; S: REAL; Begin S: = 0; {Note That Open Array Index Range is always zero-based.} For i: = 0 to high (x) do s: = s x [i]; Sum: = S; END; Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR List1: array [0..3] of double; List2: array [5..17] of double; X: Word; S, Tempstr: String; Begin For x: = low (list1) to high (list1) do List1 [x]: = x * 3.4; For x: = low (list2) to high (list2) do List2 [x]: = x * 0.0123; Str (SUM (List1): 4: 2, s); S: = 'sum of list1: s # 13 # 10; S: = S 'SUM of List2:'; Str (SUM (List2): 4: 2, TempStr); S: = S Tempstr; Messagedlg (s, mtinformation, [mbok], 0); END; ## low, high example -------------------------------------------------- --------------------------- The Low is transmitted back to the minimum value. -------------------------------------------------- --------------------------- Unit system Function Prototype Function Low (X); Description Ordinal Type The Lowest Value in The Range of The Type Array Type The Lowest Value With Range of The INDEX TYPE OF THE ARRAY String Type Returns 0 Open Array Returns 0 String Parameter Returns 0 -------------------------------------------------- --------------------------- ORD is transmitted back to the value of the type. -------------------------------------------------- --------------------------- Unit system Function prototype Function ORD (X): Longint; Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Type Colors = (Red, Blue, Green); VAR String; Begin S: = 'Blue Has An Ordinal Value of' INTOSTR (ORD (RED)) # 13 # 10; S: = S 'The Ascii Code for "C" IS' INTOSTR (ORD ('c')) ' Decimal '; Messagedlg (s, mtinformation, [mbok], 0); END; -------------------------------------------------- --------------------------- Round turns the implementation into an integer. (Have a four round) -------------------------------------------------- --------------------------- Unit system Function prototype Function Round (x: extended): longint; Example VAR S, T: string; Begin STR (1.4: 2: 1, t); S: = T 'ROUNDS to' INTOSTR (Round (1.4)) # 13 # 10; STR (1.5: 2: 1, t); S: = S T 'ROUNDS to' INTSTR (Round (1.5)) # 13 # 10; STR (-1.4: 2: 1, t); S: = S T 'ROUNDS to' INTOSTR (Round (-1.4)) # 13 # 10; STR (-1.5: 2: 1, t); S: = S T 'ROUNDS to' INTTOSTR (Round (-1.5)); Messagedlg (s, mtinformation, [mbok], 0); END; -------------------------------------------------- --------------------------- Trunc turns the real number to an integer. (Decimal Directly Abandon) -------------------------------------------------- --------------------------- Unit system Function prototype Function Trunc (x: extended): longint; Untyped file routines VAR S, T: string; Begin STR (1.4: 2: 1, t); S: = T 'Truncs to' INTOSTR (Trunc (1.4)) # 13 # 10; STR (1.5: 2: 1, t); S: = S T 'Truncs to' INTOSTR (Trunc (1.5)) # 13; STR (-1.4: 2: 1, t); S: = S T 'Truncs to' INTSTR (Trunc (-1.4)) # 13 # 10; STR (-1.5: 2: 1, t); S: = S T 'Truncs to' INTSTR (Trunc (-1.5)); Messagedlg (s, mtinformation, [mbok], 0); END; ------------------------- Var f: file of integer; I, J: Integer; Begin AssignFile (f, 'test.int'); Rewrite (f); For i: = 1 to 6 do Write (f, i); Writeln ('File Before Truncation:'); RESET (F); While Not Eof (f) DO Begin READ (F, I); Writeln (i); END; RESET (F); For i: = 1 to 3 do Read (f, j); {read ahead 3 records} Truncate (f); {cut file off here} Writeln; Writeln ('File After truncation:'); RESET (F); While Not Eof (f) DO Begin READ (F, I); Writeln (i); END; Closefile (f); ERASE (f); END; -------------------------------------------------- --------------------------- BlockRead reads the file to the memory block. -------------------------------------------------- --------------------------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Fromf, TOF: File; Numread, Numwritten: Integer; BUF: array [1..2048] of char; Begin If OpenDialog1.execute Then {Opening Dialog} Begin Assignfile (fromf, OpenDialog1.FileName); {} RESET (fromf, 1); {record size = 1} if Savedialog1.execute Then {Display Save Dialog Box} Begin Assignfile (TOF, Savedialog1.FileName); {Open Output File} Rewrite (TOF, 1); {record size = 1} Canvas.TextOut (10, 10, 'Copying' INTOSTR (FileSize (fromf)) 'Bytes ...'); Repeat Blockread (From, BUF, SIZEOF (BUF), NumRead; Blockwrite (TOF, BUF, NUMREAD, NUMWRITTEN); Until (NumRead = 0) or (NumWritten <> NumRead); Closefile (fromf); Closefile (TOF); END; END; END; ## BlockRead, Blockwrite, Savedialog EXAMPLE -------------------------------------------------- --------------------------- BlockWrite writes the memory block into the file. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Blockread (var f: file; var buf; count: integer [; var result: integer]); Function prototype Procedure Blockwrite (var f: file; var buf; count: integer [; VAR RESULT: Integer]); Example VAR Fromf, TOF: File; Numread, Numwritten: Integer; BUF: array [1..2048] of char; Begin IF openDialog1.execute the {Display Open Dialog Box} Begin Assignfile (fromf, OpenDialog1.FileName); RESET (fromf, 1); {record size = 1} if Savedialog1.execute THEN {Display Save Dialog Box} Begin Assignfile (TOF, Savedialog1.FileName); {Open output file} Rewrite (TOF, 1); {record size = 1} Canvas.TextOut (10, 10, 'Copying' INTTOSTR (FileSize (fromf)) 'Bytes ...'); Repeat Blockread (From, BUF, SIZEOF (BUF), NumRead; Blockwrite (TOF, BUF, NUMREAD, NUMWRITTEN); Until (NumRead = 0) or (NumWritten <> Numread; Closefile (fromf); Closefile (TOF); END; END; END; ======================================= Variant Support Routines Ghost Variable Volume ======================================= VararrayCreate creates a Variant Array. -------------------------------------------------- --------------------------- Unit system Function prototype Function VararrayCreate (Const Bounds: Array of Integer) VARTYPE: Integer: Variant; Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR A: Variant; String; Begin A: = VararrayCreate ([0,4], Varvariant); A [0]: = 1; A [1]: = 1234.5678; A [2]: = 'Hello World'; A [3]: = true; A [4]: = Vararrayof ([1, 10, 100, 10000]); S: = a [4] [2]; S: = a [2] '' S; Label1.caption: = S; END; Explanation S: = a [4] [2]; Variant may do without a function to switch. It can only be used alone, if it is incorrect for the following. S: = a [2] '' a [4] [2]; VARTYPE Varempty $ 0000 The Variant Is Unassigned. Varnull $ 0001 The Variant Is Null. Varsmallint $ 0002 16-bit Signed Integer (Type Smallint). Varinteger $ 0003 32-bit Signed Integer. Varsingle $ 0004 SINGLE-PRECISION FLOATING-POINT VALUE "TYPE SINGLE). VARDOUBLE $ 0005 Double-Precision Floating-Point Value (Type Double). Varcurrency $ 0006 Currency floating-point value (Type Currency). Vardate $ 0007 Date and Time Value (Type TdateTime). Varolestr $ 0008 Reference to a Dynamical Allocated UNICODE STRING. Vardispatch $ 0009 Reference to an ole Automation Object (An Idispatch Interface Pointer). Varrror $ 000A Operating System Error Code. Varboolean $ 000B 16-bit Boolean (Type WordBool). Varvariant $ 000c Variant (Used Only with Variant Arrays). Varunknown $ 000D Reference to an unknown ole Object (An IUNKNOWN Interface Pointer). Varbyte $ 0011 8-bit unsigned integer (Type Byte). Varstring $ 0100 Reference to a Dynamically-Allocated Long String "TYPE ANSISTRING. VARTYPEMASK $ 0FFF Bit Mask for Extracting Type Code. This Constant Is a Mask That Can Be Combined with the VTYPE FIELD USING A bit-wise and .. Vararray $ 2000 Bit Indicating Variant Array. This Constant Is A Mask That Can Be Combined with the VTYPE Field Using a bit-wise and to determine if the variant Contains a single value or an array of values. Varbyref $ 4000 this constant can be and'd with variant.vtype To DETERMINE IF The Variant Contains a Pointer To The indeicated data instead of containing the dataitself. Example VAR V1, V2, V3, V4, V5: VARIANT I: integer; D: double; String; Begin V1: = 1; {integer value} V2: = 1234.5678; {Real value} V3: = 'Hello World'; {String Value} V4: = '1000'; {String Value} V5: = V1 V2 V4; {Real value 2235.5678} I: = v1; {i = 1} D: = v2; {d = 1234.5678} S: = v3; {s = 'hello world'} I: = v4; {i = 1000} S: = v5; {s = '2235.5678'} END; -------------------------------------------------- --------------------------- Vararrayof builds a simple one-dimensional Variant Array -------------------------------------------------- --------------------------- Unit system Function prototype Function Vararrayof (Const Values): Variant; Example VAR A: Variant; Begin A: = Vararrayof ([1, 10, 'Hello, 10000]); S: = a [1] '' INTOSTR (a [2]); Label1.caption: = S; END; -------------------------------------------------- --------------------------- Vararrayredim reacts the high-dimensional part of the Variant array. -------------------------------------------------- --------------------------- Unit system -------------------------------------------------- --------------------------- Function prototype Procedure Vararrayredim (VAR A: Variant; Highbound: Integer); -------------------------------------------------- --------------------------- VararrayDimcount passed the dimension of the Variant array. -------------------------------------------------- --------------------------- Unit system Function prototype Function Vararraydimcount (Const A: Variant): Integer; -------------------------------------------------- --------------------------- VararrayHighbound is followed by one-dimensional foot in the Variant array. -------------------------------------------------- -------------------------- Unit System Function prototype Function VararrayHighbound (const A: variant; dim: integer): Integer; -------------------------------------------------- --------------------------- VararraylowBound is followed by a one-dimensional low note in the Variant array. -------------------------------------------------- --------------------------- Unit system Function prototype Function VararraylowBound (const A: variant; Dim: integer): Integer; Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR A: Variant; Count: integer; HIGHBOUND: Integer; Lowbound: integer; i: integer; String; Begin A: = VararrayCreate ([0, 5, 1, 3], Varvariant); Count: = VararrayDimcount (a); S: = # 13 'dimension:' INTOSTR (count) # 13; For i: = 1 to count do Begin Highbound: = VararrayHighBound (A, I); LowBound: = VararraylowBound (A, i); S: = S 'Highbound:' INTOSTR (Highbound) # 13; S: = S 'Lowbound:' INTOSTR (Lowbound) # 13; END; ShowMessage (s); END; -------------------------------------------------- --------------------------- VararrayLock specifies a Variant array ==> to an array variable. -------------------------------------------------- --------------------------- VaRRAYUNLOCK releases the above specified. -------------------------------------------------- --------------------------- Unit system Function prototype Function Vararraylock (Var A: Variant): Pointer; Function prototype Procedure Vararrayunlock (VAR A: VARIANT); Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Const HIGHVAL = 12; Type TDATA = array [0..highval, 0..highval] of integer; VAR A: Variant; I, J: Integer; Data: ^ TDATA; Begin A: = VararrayCreate ([0, HIGHVAL, 0, HIGHVAL], VARINTEGER); For i: = 0 to HighVal DO For j: = 0 to HighVal DO A [i, j]: = i * j; Data: = VARARRAYLOCK (A); For i: = 0 to HighVal DO For j: = 0 to HighVal DO Grid1.cells [i 1, j 1]: = INTOSTR (data ^ [i, j]); Vararrayunlock (a); END; -------------------------------------------------- --------------------------- VarisArray passed back to whether Variant is an array. -------------------------------------------------- --------------------------- Unit system Function prototype Function VarisArray (const v: variant): boolean; VariSempty is returned if Variant has not been registered. (Empty) Unit system Function prototype Function VariSempty (Const v: Variant): Boolean Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR A: Variant; String; Begin A: = VararrayCreate ([0, 5, 0, 7], Varvariant); IF varisempty (a) THEN S: = 'True' Else S: = 'false'; Label1.caption: = S; END; -------------------------------------------------- --------------------------- ** s: = false, A is established. -------------------------------------------------- --------------------------- Varisnull returns Variant whether it is NULL. -------------------------------------------------- --------------------------- Unit system Function prototype Function Varisnull (const v: variant): boolean; -------------------------------------------------- --------------------------- VaraSType turns Variant to another type of Variant. -------------------------------------------------- --------------------------- Varcast -------------------------------------------------- --------------------------- Unit system Function prototype Function VaraSType (const v: variant; variant; VARTYPE: INTEGER): Variant; Function prototype Procedure Varcast (var dest); const source: Variant; VARTYPE: INTEGER; Note VARTYPE cannot be VARARRAY or Varbyref. -------------------------------------------------- --------------------------- VARTYPE is sent back to Variant. -------------------------------------------------- -------------------------- Unit System Function prototype Function Vartype (const v: variant): Integer; -------------------------------------------------- --------------------------- VARCLEAR clears Variant and becoming the unassigned state. -------------------------------------------------- --------------------------- Unit system Function prototype Procedure Varclear (var variant); -------------------------------------------------- --------------------------- Varopy copies a variant. -------------------------------------------------- --------------------------- Unit system Function Prototype Procedure Varopy (Var Dest: Variant; Const Source: Variant); Description With Dest: = Source; effect. -------------------------------------------------- --------------------------- VarfromDateTime turned DateTime to Variant. -------------------------------------------------- --------------------------- VARTODATETIME turns Variant to DateTime. -------------------------------------------------- --------------------------- Unit system Function prototype Function VarfromDateTime (datetime: tdatetime): Variant; Function prototype Function VartodateTime (const v: variant): tdatetime; ============================== function =============================== Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT); VAR Bitmap: tbitmap; Begin Bitmap: = Tbitmap.create; Try Bitmap.LoadFromfile ('g: /33.bmp'); Form1.canvas.brush.bitmap: = Bitmap; Form1.canvas.FillRect (RECT (0, 0, 18, 15)); Finally Form1.canvas.brush.bitmap: = NIL; Bitmap.free; END; END; ## Canvas, Brush, Bitmap, FillRect Example ======================================== TEXTOUT ======================================== Procedure TFORM1.FormCreate (Sender: TOBJECT); VAR HEADERSECTION: THEADERSECTION; I: integer; Begin For i: = 0 to 4 do Begin Headersection: = HeaderControl1.sections.add; Headersection.text: = 'Text Section' INTOSTR (i); Headersection.minwidth: = length (headersection.text) * font.size; // Owner Draw Every Other Section IF (i mod 2 = 0) THEN Headersection.Style: = HSOWNERDRAW Else HeadersECTION.Style: = hStext; END; END; Procedure TFORM1.HeaderControl1Drawsection (HeaderControl: TheaderControl; Section: theadersection; const: trect; press: boolean; Begin With headerControl.canvas do Begin // highlight pressed sections IF Pressed Then Font.color: = CLRED Else Font.color: = CLBLUE; TextOut (Rect.Top 2, 'Owner Drawn Text'); END; END; ## Headersection, OnDrawSection, Sections, Canvas, TextOut Example -------------------------------------------------- ------------ Trunc EXAMPLE -------------------------------------------------- --------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR S, T: string; Begin STR (1.4: 2: 1, t); S: = T 'Truncs to' INTOSTR (Trunc (1.4)) # 13 # 10; STR (1.5: 2: 1, t); S: = S T 'Truncs to' INTOSTR (Trunc (1.5)) # 13 # 10; STR (-1.4: 2: 1, T); S: = S T 'Truncs to' INTSTR (Trunc (-1.4)) # 13 # 10; STR (-1.5: 2: 1, t); S: = S T 'Truncs to' INTSTR (Trunc (-1.5)); Messagedlg (s, mtinformation, [mbok], 0); END; Unable -------------------- WrapText -------------------- Sysutils Type tsyscharset = set of char VAR S, R: String; Begin S: = '123456_123456_123456'; R: = WrapText (s, # 13 # 10, ['1', '4'], 4); Messagedlg (r, mtinformation, [mbok], 0); END; ======================================================================================================================================================= Widechartostrvar (Source: PWIDECHAR; VAR DEST: STRING); ------------------------- SYSTEM ----------------- ========================= WideChartostring (Source: PWIDECHAR): STRING; ------------------------- SYSTEM ============================== Widecharlentostrvar (Source: PWIDECHAR; Sourcelen: Integer; var dest: String); ------------------------------ SYSTEM =============================== Widecharlentostring (Source: PWIDECHAR; Sourcelen: Integer): String ----------------------- SYSTEM ===================================== AnsiCompareFileName (Const S1, S2: String): Integer; sysutils ==================================== Ansiextractquotedstr (var s: pchar; quote: char): string; Sysutils VAR S1: PCHAR; S2: STRING; Begin S1: = '/ ??. ??????????????.56/'; S2: = ANSIEXTRACTQUOTEDSTR (S1, '/'); // s2: = '??. ??????????' Messagedlg (S2, Mtinformation, [Mbok], 0); END; -------------------------------------------------- ------------ ANSILASTCHAR (Const S: String): PCHAR; Sysutils -------------------------------------------------- ------------ ANSILOWERCASEFILENAME (const S: string): String; Sysutils -------------------------------------------------- ------------ ANSIPOS (Const Substr, S: String): Integer Sysutils VAR Substr, S: String; I: integer; Begin S: = '???????? ??????; Substr: = '???'; I: = ansipos (Substr, s); // i: = 3 ... END; -------------------------------------------------- ------------ ANSIQUOTEDSTR (Const S: String; Quote: char): String; Sysutils VAR String; Begin S: = '1997-1998 ??.'; S: = ANSIQUOTEDSTR (S, '-'); // s: = '-1997--1998 ?? .-' Messagedlg (s, mtinformation, [mbok], 0); END; -------------------------------------------------- ------------ ANSISAMESTR (Const S1, S2: String): Boolean; Sysutils -------------------------------------------------- ------------ ANSISAMETEXT (Const S1, S2: String): boolean; Sysutils -------------------------------------------------- -------- ANSISTRCOMP (S1, S2: PCHAR): INTEGER Sysutils -------------------------------------------------- ------------ Ansistricomp (S1, S2: PCHAR): Integer; Sysutils -------------------------------------------------- ------------ ANSISTRLASTCHAR (P: PCHAR): PCHAR; Sysutils -------------------------------------------------- ------------ AnsistrolComp (S1, S2: PCHAR; MAXLEN: Cardinal): Integer; Sysutils VAR P1, P2: PCHAR; Len: integer; Begin P1: = '?????? ??????????????????????????.'; P2: = '?????? ??????????????????????????!; LEN: = Length (P1) -1; IF ANSISTRLICOMP (P1, P2, LEN) = 0 Then Messagedlg (p1 # 13 p2 # 13 '??????? ??????????????' INTOSTR (LEN ) '?????????, ?????', mtinformation, [mbok], 0); END; -------------------------------------------------- ------------ Ansistrlicomp (S1, S2: PCHAR; MAXLEN: Cardinal): Integer; Sysutils VAR P1, P2: PCHAR; Len: integer; Begin Len: = 7; P1: = '?????? 1'; P2: = '?????? 2'; IF ANSISTRLICOMP (P1, P2, LEN) = 0 Then Messagedlg (p1 # 13 p2 # 13 '??????? ??????????????' INTOSTR (LEN ) '?????????, ?????', mtinformation, [mbok], 0); END; -------------------------------------------------- ------------ ANSISTRLOWER (S1, S2: PCHAR): PCHAR; Sysutils -------------------------------------------------- ------------ ANSISTRPOS (S, Substr: Pchar): PCHAR Sysutils VAR S1, S2: PCHAR; Begin S1: = '????? ???? -? ????? ????!'; S2: = ANSISTRPOS (S1, '?????'); // s2: = '????? ????!' Messagedlg (S2, Mtinformation, [Mbok], 0); END; -------------------------------------------------- -------- Ansistrrscan (s: pchar; chr: char): pchar; Sysutils VAR P1, P2: PCHAR; Begin P1: = 'c: / windows / temp'; P2: = ANSISTRRSCAN (P1, '/'); {P2: = '/ TEMP'} Messagedlg (p2, mtinformation, [mbok], 0); END; -------------------------------------------------- ------------ ANSISTRSCAN (S: Pchar; Chr: char): PCHAR; Sysutils VAR P1, P2: PCHAR; Begin P1: = 'http://www.atrussk.ru/delphi'; P2: = ANSISTRSCAN (P1, '/'); {p2: = '//www.atrussk.ru/delphi'} Messagedlg (p2, mtinformation, [mbok], 0); END; -------------------------------------------------- ------------ Ansistrupper (s: pchar): PCHAR Sysutils -------------------------------------------------- ------------ ANSIUPPERCASEFILENAME (Const S: String): String; Sysutils -------------------------------------------------- ------------ ByTTocharindex (Const S: String; Index: Integer): Integer; Sysutils -------------------------------------------------- ------------ Bytetocharlen (const S: String; Maxlen: Integer): Integer; Sysutils -------------------------------------------------- ------------ ByType (Const S: String; INDEX: Integer): TMBCSBYTYPE; Sysutils MBSINGLEBYTE - Mbleadbyte - Mbtrailbyte - -------------------------------------------------- ------------ ChartobyteIndex (Const S: String; Index: Integer): Integer; Sysutils -------------------------------------------------- ------------ Chartobytelen (Const S: String; Maxlen: Integer): Integer; Sysutils -------------------------------------------------- ------------ CHR (X: BYTE): CHAR; Sysutils Messagedlg ('ascii - ?????????????????????????? chr (77), mtinformation, [mbok], 0); -------------------------------------------------- ------------ FormatMaskText (const Editmask: string; const value: string): string; Mask -------------------------------------------------- ------------ GetformatSetting; Sysutils -------------------------------------------------- ------------ Isdelimiter (Const Delimiters, S: String; Index: Integer): Boolean; Sysutils VAR String; Begin S: = '?????????????????????????!'; IF Isdelimiter ('!, -', s, 8) THEN Messagedlg ('???????!', MTWARNING, [Mbok], 0) Else Messagedlg ('??????????!', MTWARNING, [Mbok], 0); END; -------------------------------------------------- ------------ ISPATHDELIMITER (Const S: String; Index: Integer): Boolean; Sysutils IF IspathDelimiter (S, Length (s)) THEN S: = COPY (S, 1, Length (s) -1); -------------------------------------------------- ------------ LastDelimiter (Const Delimiters, S: String): Integer; Sysutils VAR I: integer; Begin I: = LastDelimiter ('! ;; ", ???????, ?????????????????); // i: = 16 END; -------------------------------------------------- ------------ LINESTART (BUFFER, BUFPOS: PCHAR): PCHAR Classes - -------------------------------------------------- -------- Quotedstr (const S: string): string; Sysutils -------------------------------------------------- ------------ SETLENGTH (VAR S; Length: Integer); SYSTEM -------------------------------------------------- ------------ SetString (var s: string; buffer: pchar; length: integer); SYSTEM -------------------------------------------------- ------------ Str (x [: width [: decimals]; var s); SYSTEM VAR String; I: real; Begin I: = -52.123456789; STR (i: 6: 2, s); {s: = '-52.12'} Messagedlg (s, mtinformation, [mbok], 0); -------------------------------------------------- ------------ Strbufsize (s: pchar): cardinal; Sysutils -------------------------------------------------- ------------ Strbytetype (s: pchar; index: cardinal): TMBCSBYTYPE; Sysutils -------------------------------------------------- ------------ StringOfchar (CH: CHAR; Count: integer): String; SYSTEM S: = StringOfchar ('.', 3); // s: = '...' -------------------------------------------------- ------------ StringReplace (Const S, Oldsubstr, NewsUbstr: String; Flags: TreplaceFlags): String; Sysutils TYPE TREPLACEFLAGS = Set of (RFREPLACEALL, RFIGNORECASE); VAR String; Flags: TreplaceFlags; Begin Flags: = [RFREPLACEALL, RFIGNORECASE]; S: = '???? - ????? ?????'; S: = STRINGREPLACE (s, '??', '??', flags); // s: = '???? - ????? ?????'} Messagedlg (s, mtinformation, [mbok], 0); END; -------------------------------------------------- ------------ StringTowideChar (Const Source: String; DEST: PWIDECHAR; DESTSIZE: INTEGER): PWIDECHAR SYSTEM -------------------------------------------------- ------------ UNIQUESTRING (VAR S: String); SYSTEM -------------------------------------------------- ------------ =============================== message =============================== -------------------------------------------------- ------------- SHOWMESSAGE message -------------------------------------------------- ------------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Buffer: array [0..255] of char; Filetofind: String; Begin GetWindowsDirectory (Buffer, SIZEOF (BUFFER); FileTofind: = filesearch (Edit1.Text, getCurrentDir ';' buffer); IF filetofind = 'THEN ShowMessage ('couldn't Find' Edit1.Text '.') Else ShowMessage ('Found' FileTOfind '); END; ## FileSearch, ShowMessage EXAMPLE -------------------------------------------------- ------------ Findcomponent Examples (1) Type LogPal = record LPAL: TLOGPALETTE; Dummy: array [0..255] of tpaletteentry; END; Procedure TFORM1.SAVEASBMPCLICK (Sender: TOBJECT); VAR Source: tcomponent; Syspal: LogPal; TEMPCANVAS: Tcanvas; SourceRect, DESTRECT: TRECT; Image2save: TIMAGE; NOTUSED: hwnd; Begin Source: = FindComponent (Edit1.Text); IF (Not Source Is Tcontrol) or (NOT Source Is TwinControl) and (Source As Tcontrol) .parent = nil) Then Begin BEEP; ShowMessage (edit1.text 'is not a valid control.'); EXIT; END; Tempcanvas: = tcanvas.create; Try With source as tcontrol do Tempcanvas.Handle: = getDeviceContext (Notused); Image2save: = TIMAGE.CREATE (Self); Try WITH image2SAVE DO Begin Height: = (Source as tcontrol) .height; Width: = (Source as tcontrol) .width; DESTRECT: = RECT (0, 0, Width, Height); IF Source Is TwinControl Then SourceRect: = DESTRECT; Else SourceRect: = (Source as tcontrol) .BoundSRect; Canvas.copyRect (DestRect, Tempcanvas, SourceRect); Syspal.lpal.Palversion: = $ 300; Syspal.lpal.palNumentries: = 256; GetSystemPaletteentries (Tempcanvas.Handle, 0, 256, Syspal.palpalent); Picture.bitmap.palette: = CreatePalette (syspal.lpal); END; if Savedialog1.execute THEN Image2save.picture.savetofile (savedialog1.filename); Finally Image2save.free; END; Finally Tempcanvas.free; END; END; Examples (2) Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR i: integer; Const Nameprefix = 'myEdit'; Begin For i: = 1 to 20 do begin Tedit.create (self) .name: = NamePRefix INTOSTR (i); With TEDIT (Findcomponent (NamePrefix INTOSTR (i))) Begin LEFT: = 10; TOP: = i * 20; Parent: = Self; END; END; END; ============================================================================================================================================================================================================= ======= Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR A: Variant; Begin A: = VararrayCreate ([0, 4], Varvariant); A [0]: = 1; A [1]: = 1234.5678; A [2]: = 'Hello World'; A [3]: = TRUE; A [4]: = Vararrayof ([1, 10, 100, 1000]); Edit1.text: = (a [2]); {Hello World} Edit2.text: = (a [4] [2]); {100} END; Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT); VAR String; Begin S: = 'Honest Abe Lincoln'; Delete (s, 8, 4); Canvas.TextOut (10, 130, s); {'honest lincoln'} END; Procedure TFORM1.BUTTON3CLICK (Sender: TOBJECT); Var s: string; Begin S: = 'Abcdef'; S: = COPY (S, 2, 3); Edit1.text: = s; {'bcd'} END; Procedure TFORM1.BUTTON4CLICK (Sender: TOBJECT); VAR String; Begin S: = Concat ('abc', 'DEF'); edit1.text: = s; {'abcde'} END; Procedure TFORM1.BUTTON5CLICK (Sender: TOBJECT); VAR String; Begin S: = 'honest lincoln'; INSERT ('Abe', S, 8); Edit1.text: = s; {'honest Abe lincoln'} END; Procedure TFORM1.BUTTON6CLICK (Sender: TOBJECT); VAR String; Begin S: = 'The Black Knight'; Canvas.Textout (10, 130, 'string length =' INTOSTR (Length (s))); {string length = 16} Edit1.text: = s; {THE black knight} END; Procedure TFORM1.BUTTON7CLICK (Sender: TOBJECT); Var s: string; Begin S: = '123.5'; {Convert Spaces to Zeroes} While Pos ('', s)> 0 do S [POS ('', s)]: = '0'; Edit1.text: = s; {000123.5} END; ============================================================================================================================================================================================================= ========================= Mathematical function (Arithmetic Routines) Unit: system ============================================================================================================================================================================================================= ========================= The absolute value of the ABS is back. Function ABS (X); The inverse function value of the arctan passed back to the correct function. "Xiction arctan (x: real): real; COS pass back strings function Function Cos (x: real): real; (x in an arc). EXP is sent back to the natural index value. Function Cos (X: REAL): REAL; The decimal part of the number of FRACs. Function FRAC (X: REAL): REAL; INT transmits the integer part of the number. Function Int (X: REAL): REAL; LN is sent back to the natural logar. Function LN (X: REAL): REAL The value of the PI back the circular rate π. Function PI: REAL; SIN passed back the string function value. Function SIN (X: REAL): REAL; SQR is transmitted back to the number of the number. Function SQR (X: REAL): (REAL); SQRT is transmitted back to the square root of the number. Function SQRT (X: REAL): REAL; ============================================================================================================================================================================================================= ========================= Console routines ============================================================================================================================================================================================================= ========================= Unit: WinCRT Function Name Function Description Function Syntax ============================================================================================================================================================================================================= ========================================================================================================================================================================================================================================================================================= Procedure AssignCRT (var f: text); Clreol Clear the cursor position to all the characters of the line. Procedure clreol; CLRSCR Cleans the screen and reset the cursor to the upper left corner. Procedure CLRSCR; Cursorto mobile cursor to a given seat. Procedure Cursorto (X, Y: Integer); DONEWINCRT ends the console window. Procedure donewincrt; Gotoxy mobile cursor to a given seat. Procedure gotoxy (x, y: byte); INITWINCRT establishes a console window. Procedure initwincrt; KeyPRESSED judges whether or not there is a button. Function Keypressed: Boolean; Readbuf is read from the console view window. Function Readbuf (Buffer: Pchar; Count: Word): Readkey reads button nine. Function Readkey: char; Scrollto rolling control table window window to the display position. Procedure ScrollTo (X, Y: Integer); The TRACKCURSOR rolling control desktop window is visible to the cursor. Procedure trackcursor; WHEREX is back to the X coordinate of the target. Function wherex: Byte; Wherey passed back to the y mark. Function wherey: Byte; WriteBuf is written to a block of blocks to the console window. Procedure Writebuf WriteChar writes a character to the console window. Procedure Writechar (CH: CHAR); ================================================================================★ Date and time function (Date and time routines) Unit: SYSUTILS ================================================= Date is overview today. Function date: TDATETIME; DateTimetostr transfers the time format into a string. Function dateTimetostr (datetime: tdatetime): String; DateTimetostring converts the time format into a string. Procedure DateTimetostring (var Result: string; const format: string; datetime: tdatetime); DateTostr transfers the date format into a string. Function datetostr (date: tdatetime): String; Dayofweek passed back today. Function Dayofweek (date: tdatetime): Integer; Date specified by DecodeDate decomposition is year, month, day. Procedure decodate (date: tdatetime; var yeear, month, day: word); The date specified by Decodetime decomposition is time, minute, second. Procedure Decodetime (Time: Tdatetime; Var Hour, min, sec, msec: word); EncodeDate is transmitted back to the date format combined with the year, month, and Japan. Function Encodedate (Year: Word): TDATETIME; ENCODetime is sent back to the time format combined with a second. Function EncoDetime (Hour, min, sec, msec: word): tdatetime; FormatDateTime is backatically date with the specified format. Function Formator (const format: string; datetime: tdatetime): String; NOW is back to the current date time. Function now: TDATETIME; Strtodate converts the strings into a date format. Function Strtodate (const s: string): TDATETIME; STRTODATETIME converts strings to date time format Function StrtodateTime (const s: string): TDATETIME Strtotime converts the strings into time format. Function Strtotime (const S: string): tdatetime; Time passed back now. Function Time: TDATETIME; Timetostr will turn time to string. Function Timetostr (Time: tdatetime): String; ========================================= Dynamic Allocation Routines Unit: system ======================================================= Dispose releases a dynamic variable. Procedure Dispose (VAR P: POINTER); Free releases an object copy. PROCEDURE FREE FreeMem Releases a dynamic variable of a given size. Procedure FreeMem (VAR P: Pointer; SIZE: WORD); GetMem establishes a dynamic variable specified for the size and is passed by the Pointer Number. Procedure getmem (var P: Pointer; SIZE: WORD); NEW establishes a new dynamic variable and pointing the Pointer parameter to it. Procedure New (VAR P: POINTER); Function New ( Maxavail passes back the continuous maximum configurable space. Function maxavail: longint; MEMAVAIL is sent back to all configurable spaces. Function Memavail: longint; ========================================= Archive management function Unit: SYSUTILS ========================================= ChangefileExt changes the extension of the file. Function ChangeFileExt (const filename, extension: string): string; DateTimetOfileDate converts Delphi's date format to DOS date format. FunctionDateTimetOfileDate (datetime: tdatetime): longint; Deletefile deletes a file. Function deletefile (const filename: string): boolean; DiskFree Removes the available space of the disk. Function Diskfree (drive: byte): longint; DiskSize passed back to the size of the specified disk. Function Disksize (drive: byte): longint ExpandFileName passed back a complete path and file name string. Function ExpandFileName (const filename: string): String; ExtractFileExt Removes the extension of the file. Function ExtractFileExt (const filename string): string; ExtractFileName Retrieves the file name. Function ExtractFileName (const filename: string): String; ExtractFilePath Retrieves the path to the file. Function ExtractFilePath (const filename: string): String; Fileage Retroiled files for the file function fileage (const filename: string): longint FileCreate establishes a file with a specified file. Function FileCreate (Const filename: string): integer; FILECLOSE closes the specified file. ProcedureFileClose (Handle: Integer); FileDateTodateTime turns the date format of DOS to Delphi. Function FileDateTodateTime (FileDate: longint): TDATETIME; FileExists discriminates if the file exists. Function FileExists (const filename: string): boolean; Filegetttr Replies file properties. Function Filegetttr (const filename: string): Integer; Filegetdate Remove the date and time of the file. Function Filegetdate (Handle: Integer): Longint; FileRead reads information from the specified file. Function FileRead (Handle: Integer; Count: longint): Longint FileSearch searches for specified files in the catalog column. Function FileSearch (constname, dirlist: string): string; Fileseek changes the location of the archive cursor. Function Fileseek (Handle: Integer; ORIGIN: Integer; FILESETATTR Sets the file properties. Function FileSetattr (Const filename: string; attr: integer): integer; FileSetDate Sets the date and time of the file. Procedure FileSetdate (Handle: Integer; agent; FileOpen opens the file. Function FileOpen (const filename: string; mode: word): integer; FileWrite write information to the file. Function FileWrite (Handle: Integer; COUNT: LongInt): Longint FindClose terminates the first / next action. Procedure Findclose (VAR Searchrec: TsearchRec); Findfirst finds the first informative file and set its properties. Function Findfirst (const path: string; attr: word; var f: tsearchrec): integer; Findnext passes back the next compliant file. Function FindNext (VAR F: TSEARCHREC): Integer; Renamefile changes the file name. Function renamefile (const6ame: string): boolean; ========================================= Floating-point conversion function (Floating-Point Conversion Routines) Unit: SYSUTILS ========================================= FLOATTODECIMAL divides floating point values into numbers and integer parts. Procedure floattodecimal (Value: Extended; Precision, Decimals: integer); FLOATTOSTRF converts floating point numbers into a string description in accordance with the specified format. Function floattostrf (value: extended; Format: tfloatformat; precision, digits: integer: string; FLOATTOSTR converts floating point numbers into a string description. Function floattostr (value: extended): String; FloAtTotext will be transferred in accordance with the format of the floating point value, divided into decimal and integer part. Function floattotext (buffer: pchar; value: extended; format: tfloatformat; precision, digits: integer: integer; FLOATTEXTFMT Release the floating point to the format into a string. Function floattotextfmt (buffer: pchar; value: extended; Format: Pchar): integer Formatfloat passed the floating point value in accordance with the format format. Function formatfloat (constformat: string; value: extended): String; StrtOFLOAT converts the string to a floating point value. Function Strtofloat (Const S: String): Extended; TextTOFLOAT converts a NULL end string into floating point values Function TEXTTOFLOAT (BUFFER: PCHAR; VARUE: Extended): boolean; ========================================= Process control function (Flow-Control Routines) Unit: system ========================================= Break terminates the ring. Returning in For, While and Repeat. Procedure Break; Continue continues to ring. Returning in For, While and Repeat. PROCEDURE CONTINUE; EXIT leaves the current block. PROCEDURE EXIT; Halt stop program is executed and returned to the job system. Procedure Halt [(EXITCODE: WORD)]; RUNERROR stop program execution. Procedure Runerror [(ERRORCODE: BYTE)]; ========================================= Output function (I / O Routines) Unit: system ========================================= AssignFile specifies a file to file variable. Procedure assignfile (var f, string); Closefile Close the file. Procedure Closefile (VAR F); EOF judges whether or not it has arrived at the end of the file. TYPED or UNYPED Files: FunctionEOF (VAR f): Booleantext Files: Function Eof [(VAR f: text)]: boolean ERASE clears the file content. Procedure ERASE (VAR F); FilePos passed back the current file cursor position. Function Filepos (VAR f): longint; FileSize's Size Function FileSize (VAR F): Longint; GetDir passed back the work directory of the specified disk. Procedure getdir (d: byte; var s: string); IRessult is transmitted back to the status of the last I / O execution. Function iiResult: integer; MKDIR creates a subscription. Procedure mkdir (s: string); Rename changes the file name of the external file. Procedure Rename (VAR F; NewName); RESET turns on an existing file. Procedure RESET (VAR F [: File; RecSize: Word]); REWRITE is established and turned on a new file. Procedure Rewrite (var f: file [; recsize: word]); Rmdir deletes an empty directory. Procedure RMDir (S: String); SEEK mobile archive cursor. Procedure seek (var f; n: longint); TRUNCATE The contents of the file after the current location. Procedure Truncate (VAR F); ========================================= Memory-management function memory Memory-Management Routines Unit: SYSUTILS =========================================================================================================================================== ao . Function Allocmem (Size: Cardinal): Pointer; Reallocmem removes a block from the accumulation. Function Reallocmem (P: Pointer; CURSIZE, NEWSIZE: Cardinal): Pointer; ========================================= Miscellaneous Routines Unit: system, sysutils ========================================= AddExitproc joins a program to the executive period library. Procedure AddexitProc (Proc: tprocedure); Exclude removes an element from a collection. Procedure Exclude (Var S: set of t; i: t); Fillchar fills in a specified number to a variable with a vol. Procedure Fillchar (VAR X; Count: Word; Value); Hi's high tunnel group. Function hi (x): byte; INCLUDE contains elements to the collection. Procedure Include (Var S: set of t; i: t); LO transmission back to the low tuple of the number. Function Lo (x): byte; Move Copy the number of bit groups of counts from the Source to DEST. Procedure Move (Varsource, Dest; Count: Word); Paramcount passes the number of number of commands. Function paramcount: Word; Paramstr is sent back to a specified command number. Function Paramstr (Index): String; Random passes back a random mess. Function Random [(Range: Word)]; Randomize initialized chaos generator. Procedure randomize; SIZEOF pass back the number of 数 元 元. Function sizeof (x): Word; SWAP exchanges the high level tuning and low tunnel groups. Function swap (x); TYPEOF changes the indicator of the virtual method table to the object type. Function TypeOf (x): Pointer Upcase converts the character to uppercase. Function Upcase (CH: CHAR): CHAR; ======================================================================================================================================================================================================================================================================== Unit: system ========================================= Dec is decremented by a variable. Procedure dec (VAR X [N: Longint]); INC increments a variable procedure inc; The ODD discriminates are odd. Function ODD (x: longint): boolean; PRED back to the predecessor of the number. Function PRED (x); SUCC back the successor of the number. Function SUCC (X); ========================================= Indicators and Address Routines Unit: system ========================================= Addr is transmitted back to the address of the specified object. Function addr (x): Pointer; Assigned determines whether a function or program is NIL Function Assigned (VAR P): boolean; CSEG is transmitted back to the contents of the CS segment section. Function CSEG: WORD; DSEG passes back the contents of the DS data segment specification. Function DSEGT: WORD; The offset site of the OFS transmission back. Function OFS (X): Word; PTR combines the specified segment and offset address to an indicator. Function PTR (SEG, OFS: WORD): Pointer; Seg's segment address of the number of times. Function seg (x): Word; The SPTR is transmitted back to the SP stacker. Function sptr: Word; SSEG is returned to the content of the SS stack section. Function SSEG: WORD; ========================================= String format function (String-formatting routines) unit: sysutils ========================================= FMTSTR combines the number of in accordance with the format of Format to the Result string back. Procedure FMTSTR (Var Resut: string; const format: string; const args: array of; Format combines the column to combine the format of Format to the Pascal format string back. FONCTION FORMAT (const format: string; const args: array of const): String; Formatbuf formats the number of queues listed. Formatbuf (var buffer; buflen: cardinal; fmtlen: cardinal; const args: array of string: cardinal; Function Formatbuf (var buffer; buflen: word; const format; fmtlen: word; const args: array of const): Word; Strfmt formats the number listed. Function strfmt (buffer, format: pchar; const args: array of const): pchar; Sysutils Strlfmt formats the number of 叁 and points the result to the buffer metrics. Function strlfmt (Buffer: pchar; mxlen: Word; Format: Pchar; Const args: array of const): PCHAR; Sysutils ========================================= String-handling routines: pASCAL-STYLE Unit: systutils ========================================= Ansicomparestr compares two strings. Function AnsiCompareStr (Const S1, S2: String): Integer; Sysutils VAR String; Mas: array [0..99] of string; I, J: Integer; Begin ... For i: = 1 to 98 do For j: = i 1 to 99 do IF Ansicomparestr (MAS [I], MAS [J])> 0 THEN Begin S: = MAS [I]; MAS [I]: = MAS [J]; MAS [J]: = S; END; END; VAR S1, S2: STRING; I: integer; Begin S1: = '? ???? ??????????????; S2: = '? ???? ???????? ??????; I: = CompareStr (S1, S2); {i> 0,?.?. S1> s2} IF i <> 0 THEN Messagedlg ('?????? ????????!', MTWARNING, [Mbok], 0); END; AnsicompareText compares two strings and no casement. AnsicompareText (Const S1, S2: String): Integer; Sysutils AnsiCompareStr ('a', 'a') <0 CompareStr ('a', 'a')> 0 Function AnsiCompareText (Const S1, S2: String): Integer; AnsilowerCase turns a string content to lowercase. Function AnsilowerCase (Const S: String): String; Sysutils VAR String; Begin S: = 'myfile.txt'; S: = AnsilowerCase (s); // s: = 'myfile.txt' Messagedlg (s, mtinformation, [mbok], 0); END; ANSIUPPERCASE converts the string content to uppercase. Function ANSIUPPERCASE (Const S: String): String; Sysutils VAR String; Begin S: = 'c: / windows'; S: = ANSIUPPERCASE (s); {s: = 'c: / windows'} Messagedlg (s, mtinformation, [mbok], 0); END; AppendStr will connect the given string to the DEST string. Procedure appendstr (var DEST: STRING; Const S: String); AssignStr Configuring a memory space to give a string. Procedure appendstr (var P: pstring; const s: string); CompareStr compares two strings. Function CompareStr (Const S1, S2: String): Integer; CompareText compares two strings and no casement. Function CompareText (Const S1, S2: String): Integer; Concat links the column string. Function Concat (S1 [S2, ..., Sn]: string; COPY Retrieve part of the string content of the string. Function Copy (S: String; Index, Count: Integer): String; Delete deletes the subtronom in the given string. Procedure delete (var s: string; index, count: integer); DisposeStr Releases the space occupied by the string. Procedure DisposeStr (P: pstring); FMTLOADSTR is loaded into a string from the program of resource string table. FMTLOADSTR (Ident: Integer; Const args: string; sysutils Function FMTLOADSTR (Ident: Word; Const Args: Array Of Const): String; INSERT inserts a sub-string in one string Procedure Insert (Source: String; Var S: String; Index: Integer); Insert (Source: String; Var S: String; Index: integer); SYSTEM VAR String; Begin S: = '??????? ?????? ??????????.'; INSERT ('!', S, 8); {s: = '???????! ?????????????????.'} Messagedlg (s, mtwarning, [mbok], 0); END; INTTOHEX turns an integer into hexadecimal. Function INTTOHEX (Value: longint; Digits: Integer): String; INTSTR converts the digital to the word format. Function INTOSTR (Value: longint): String; IsValidIdent discriminates whether the string content is the correct identification word. Function isvalidIdent (const ident: string): boolean; The length of the LENGTH is returned. Function Length (s: string): Integer; Loadstr is loaded into a string resource from the application's executable file. Function Loadstr (Ident: Word): String; Sysutils LowerCase converts strings to lowercase. Function LowerCase (const s: string): string; Newstr From the accumulation of a string space. Function newsTr (const s: string): pstring; The position of the POS transmission back the subrinder in the string. Function POS (SUBSTR: STRING; S: String): The STR will turn the value into a string. Procedure Str (x [: width [: decimals]; var s); Strtoin turns a string into an integer value. Function start (const S: string): longint; StrtoinTdef will turn strings to numerical or preset values. Function startdef (Const S: String; Default: longint): longint; Uppercase converts strings to uppercase. Function Uppercase (const s: string): String; Sysutils VAR String; Begin S: = Uppercase ('???????? "); {s: =' ???????? intel '} END; VAL converts the string content to a numeric description. Procedure Val (S; VAR V; VAR Code: integer); System {$ R } {$ r-} VAR I, Code: Integer; Begin Val (edit1.text, i, code); {???????????????????????? edit1.text? ???????? ?????} If code <> 0 THEN {?????????????? ????????????? Messagedlg ('?????? ????????? ???????:' INTOSTR (CODE), MTWARNING, [MBOK], 0) Else {??????? ??????? ?????} Canvas.TextOut (20, 20, INTOSTR (SQR (i))); END; ========================================= String-handling routines: null-terminated) Unit: SYSUTILS ========================================= Stralloc Configures a buffer for a maximum length of Size-1 to the Null end string Function Stralloc (SIZE: WORD): PCHAR; StrbufSize is transmitted back to the maximum number of characters that can be stored in the string buffer configured by Stralloc. Strbufsize (s: pchar): cardinal; Sysutils Function strbufsize (str: pchar): WRD; STRCAT links two strings and passes back the string. Function Strcat (DEST, SOURCE: PCAR): PCHAR; Strcomp is compared to two strings. Function strcomp (str1, str2: pchar): integer; Strcopy Copy Source String to Dest. Function strcopy (DEST, SOURCE: PCHAR): PCHAR STRDispose releases back a string space. Function strdispose (STR: PCHAR); Strcopy copies the Source string to the DEST and pass it back to the indicator ending the string. Function Strecopy (DEST, SURCE: PCHAR): PCHAR; STREND back to an indicator pointing the end of the string Function Strend (str: pchar): PCHAR; Strlcat links the Source string to the DEST string and passes back the link. Function strlcat (dest, Source: Pcar; Maxlen: Word): Pchar; Stricomp compared two word series with no casement difference Function Stricomp (str1, str2: pchar): integer; StrlComp compares two strings to the maximum length specified Function strlcomp (str1, str2: pchar; maxlen: word): integer; Strlcopy copys from a word string to another string Function strlcopy (DEST, SOURCE: PCHAR; MAXLEN: Cardinal): Pchar; Strlen is transmitted back to the length of the string. Function Strlen (str: pchar): cardinal Strlicomp compares two strings to the specified maximum length model. Function strlicomp (str1, str2: pchar; maxlen: word): integer; strlower converts strings to lowercase. Function strlower (str: pchar): PCHAR; Strmove copies the count of the count, from the Source to the DEST string. Function Strmove (DEST, SOURCE: PCHAR; Count: cardinal): Pchar Strnew is a string from the accumulation. Function strnew (str: pchar): pchar; StrPas turns into a NULL end word into a PASCAL format string. Function strpas (str: pchar): String; Strpcopy copies a Pascal format string to a NULL end string. Function Strpcopy (DEST: PCHAR; Source: String): PCHAR; STRPLCOPY copys Maxlen's finger-in-element, string from the Pascal format to NULL end strings. Function strplcopy (DEST: PCHAR; COST SOURCE: STRING; MAXLEN: WORD): PCHAR; The STRPOS backup indicator points to the position of the Str2 string in STR1. Function Strpos (str1, str2: pchar): pchar; The STRSCAN back a indicator pointing to the first position of the CHR-element in the STR string. Function strscan (str: pchar; chr: char): pchar; The STRSCAN back a indicator pointing to the location of the CHR-element in the STR substring. Function STRSCAN (STR: PCHAR; Chr: char): pchar; Strupper converts the strings to uppercase. Function Strupper (str: pchar): PCHAR; ========================================= Text-file routines Unit: system ========================================= Append opens an existing archive for an increase. Procedure append (var f: text); EOLN discriminates if a text file is at the end. Function Eoln [(VAR f: text)]: boolean; FLUSH Clears the buffer of the text output file. Procedure flush (var f: text); Read from the file to the list of variables. Typed Files: Procedure Read (f, v1 [, v2, ..., vn]); Text Files: Procedure read ([var f: text;] V1 [, v2, ..., vn]); Readln reads information from the file to the listed variables and jumps to the next line. Procedure readln ([var f: text;] V1 [, v2, ..., vn]); SEEKEOF discriminates if it has arrived at the end. Function seekeof [(var f: text)]: boolean; seekeoln discriminates if a file is at the end. Function seekeoln [(VAR f: text)]: boolean; SetTextBuf Specifies an I / O buffer to a text file. Procedure setTextBuf (var buf [; size: word]); Write writes information within the variable to the file. Text Files: Procedure Write ([var f: text;] p1 [, p2, ..., pn]); Typed Files: Procedure Write (f, v1 [v2, ... vn]); Writeln executes the Write program and outputs a jump line to the file. PROCEDURE WRITELN ([VAR F: text;] P1 [, P2, ..., PN]); ========================================= Transfer routines Unit: system ========================================= CHR is sent back to the character corresponding to the ASCII code. Function chr (x: byte): char; Delphi source task (http://home.kimo.com.tw/bruce0211/) typing finishing 15 The highest value of the high password number in the range. Function high (x); Low pass the minimum number in the range. Function Low (x); ORD is transmitted back to a sequential value corresponding to the order. Function ORD (X): Longint; Round returns a real value to the integer value. Function Round (X: REAL): Longint; Trunc will return a real value to the integer value. Function Trunc (x: real): longint; ========================================= Unestable file function (united "united-file routines) Unit: system ========================================= BlockRead reads one or several records to the BUF variable from the file. Procedure Blockread (var f: file; var buf; count: word [; var result: word]); BlockWrite writes one or several records from a variable. Procedure BlockWrite (var buf; count: word [; var result: word]); ============================================================================================================================================================================================================= ==== WinAPI control and message function ---------------- AdjustWindowRect AdjustWindowRectex Given a window styling, calculate the size of the window required to get the rectangle of the target customer area ============================================================================================================================================================================================================= ==== VB declaration Declare Function AdjustWindowRect Lib "User32" Alias "AdjustWindowRect" (LPRECT AS RECT, BYVAL BMENU As long) As long Declare Function AdjustWindowRectex lib "user32" Alias "AdjustWindowRectex" (LPRECT AS RECTECTEX "(LPRECT AS RECT, BYVAL BMENU As Long, BYVAL DWESSTYLE AS Long) AS Long Description Under the premise of given a window styles, the size of the window required to obtain the rectangle of the target client area is calculated. return value Long, if the execution is successful, return a non-zero value; if it fails, the zero value is returned. Set GetLastError 叁 Types and description LPRECT RECT, the originally included customer area. The function is set to the target window. DWStyle long, window styles Bmenu Long, such as the window, set to true (non-zero) DWESSTYLE LONG, extended window styles (only available for AdjustWindowRectex) annotation Before calling this function, get a form of a form with getWindowlong. If the menu occupies a space above two rows, the function cannot correctly calculate the size. If the program uses multi-line titles, you should use GetSystemMetrics. ============================================================================================================================================================================================================= ==== AnyPopup Decontent whether there is any pop-up window in the screen ----------------------------------------- VB declaration Declare function annpopup lib "user32" alias "Anypopup" () AS Long Description Decontent whether there is any pop-up window in the screen return value LONG, if there is a pop-up menu, return TRUE (non-zero) annotation For this function, the pop-up menu contains all visible tolerance top-level windows, regardless of pop-up or overlapping ============================================================================================================================================================================================================= === ArrangeiconicWindows arranges a minimal window of a father window VB declaration Declare Function ArrangeiconicWindows lib "user32" Alias "ArrangeiconicWindows" (Byval Hwnd As Long) AS Long Description Arrange the minimal sessage window of a parent window (use in VB: used to arrange icons at desktop, with getDesktopWindow Function gets a handle of desktop window return value Long, the height of the icon row; if it fails, zero is returned. Set GetLastError 叁 Types and description HWND Long, the handle of the father window annotation This function can also be used to include a custom control of the iconized sub-window. ============================================================================================================================================================================================================= ===== AttachthReadInput connection thread input function BeGindeferWindowPOS launches the process of building a range of new windows BringWindowtotop takes the specified window to the top of the window Cascadewindows arranges window in a laminated manner ChildWindowFromPoint Returns the handle of the first child of the specified point in the parent window CLIENTTOSCREEN Judgment Window Screen Coordinates in a Customer Coordinate Closewindow minimizes the designated window CopyRect Rectangular Content Copy DEFERWINDOWPOS This function specifies a new window stun position for a specific window. DestroyWindow Clears the specified window and all of its sub-windows DrawanImatedRects depicts a series of dynamic rectangles All mouse and keyboard input are allowed or disabled in the enableWindow specified EnddeferWindowPOS simultaneously updates the location and status of all the windows specified when DeferWindowPos calls EnumChildWindows is a designed parent window 囗 囗 子 子 EnumthReadwindows enumerates the window with the specified task EnumWindows enumeration all the parents in the list EqualRect determines whether the two rectangular structures are the same FindWindow looks for the first top-level window that meets the specified condition in the list FindWindowEx looks for the first sub-window that matches the specified condition in the list list ============================== FlashWindow Blinking Displays the specified window ----------------------------- Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Form2.show; Form1.bringtofront; Timer1.interval: = getCareTBlinkTime; Timer1.enabled: = not timer1.enable; END; Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT); Begin FlashWindow (Form2.Handle, True); END; =============================== GetActiveWindow gets the handle of the activity window GetCapture gets a handle of a window, this window is located in the current input thread, and has a mouse capture (mouse activity is received by it) GetClassInfo acquires a copy of the WNDCLASS structure (or WNDCLASSEX structure), which contains information related to the specified class. GetClasslong gets a long variable entry for the window. GetClassName acquires a class name for the designated window. GetClassword gets an integer variable for the window. GetClientRect Returns the size of the specified window rectangle GetDesktopWindow gets a window (desktop window) handle on behalf of the entire screen Getfocus gets a handle of a window with input focus GetForegroundWindow gets the handle of the front desktop GetLastactivePopup gets the handle of the pop-ups that have been activated in a given father window GetLastError acquires an extended error message with this function for the previously called API function. GetParent judgment the parent window of the designated window GetTopWindow searches for the list of internal windows, finds the handle of one window that belongs to the designated window GetUpdaterect gets a rectangle, which describes that part of the designated window that needs to be updated. ================================================= getwindow Get a handle of a window, which has a specific relationship with a source window. ------------------------------------------------ Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT); VAR s: array [0..29999] of char; H: integer; Begin H: = getWindow (Handle, GW_OWNER); // getwindow takes a handle of a window, which has a specific relationship with a source window. GetWindowText (H, S, 300); // getWindowText takes a form header (CAPTION) text, or the contents of the control Edit1.text: = INTTOSTR (h); Label1.caption: = S; END; ================================================= GetWindowContexthelpid gets helps the help scene ID associated with the window GetWindowl acquired information from the structure of the specified window GetWindowPlacement Gets the status and location information of the specified window GetWindowRect Gets the range of the entire window, the border of the window, the title bar, the scroll bar, and the menu, etc. are in this rectangle. ================================================= GetWindowText Take a form of a form of a form, or the content of a control ---------------------------- Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT); VAR s: array [0..29999] of char; H: integer; Begin H: = getWindow (Handle, GW_OWNER); // getwindow takes a handle of a window, which has a specific relationship with a source window. GetWindowText (H, S, 300); // getWindowText takes a form header (CAPTION) text, or the contents of the control Edit1.text: = INTTOSTR (h); Label1.caption: = S; END; ============================== GetWindowTextLength Investigation Window Title text or control content GetWindowWord gets information about the specified window Inflatrect increases or decreases the size of a rectangle INTERSECTRTRT This function is loaded into a rectangle in LPDestRect, which is the intersection of LPSRC1RECT and LPSRC2RECT. InvalidateRect Blocks all or part of the area of the window. Ischild judges whether a window is a child or a member of a piece of 囗 Isiconic determines if the window is minimized IsRectempty determines if a rectangle is empty IsWindow judges whether a window hose is valid IsWindowenableD determines if the window is active IsWindowunicode determines whether a window is a Unicode window. This means that the window will receive Unicode text for all text-based messages. IswindowVisible judgment is visible Iszoomed to determine if the window is maximized LockWindowUpdate locks the specified window, disable it from updating MapWindowPoints converts a window of the cache coordinate to another window 囗 Customer area coordinate system MoveWindow changes the location and size of the specified window OFFSTRECT allows rectangular movement by applying a specified offset OpenICON restores a minimized program and activates it PtinRect Judging whether the specified point is within the rectangle RedrawWindow Heavy or part of the window ReleaseCapture releases mouse to capture the current application ScreenToClient judges a customer area coordinate of a specified point on the screen ScrollWindow scroll all or part of the customer area ScrollWindowEx is based on additional options, all or part of the roll of the window. SetActiveWindow activates the specified window SetCapture Capture the mouse to the specified window SetClasslong Set a long variable entry for the window SetClassword Set an entry for the window SetFOCUSAPI Sets the input focus to the specified window. If necessary, activate the window SetForegroundWindow set the window to the front desk window of the system SetParent specifies a new father of a window SetRect Setting the contents of the specified rectangle SetRectempty sets the rectangle to an empty rectangle SetWindowContexthelpid Sets help scene (context) ID for the specified window SetWindowl Settings Information for the Specified Window in the Window SetWindowPlacement Settings Window Status and Location Information SetWindowPos specifies a new location and status for the window SetwindowText Setting the contents of the title text or control of the window SetWindowWord Settings Information for the Specified Window in the Window structure ShowowNedPopups Show or hide all pop-ups of all popsters in the specified window SHOWWINDOW Control Window ShowWindowasync is similar to ShowWindow SubtractRect loading rectangular lprcdst, which is the result of subtract LPRCSRC2 in rectangular LPRCSRC1 TileWindows is arranged in tiled sequence UnionRECT loads an LPDESTRECT target rectangle, which is the result of lpsrc1rec1Rect and LPSRC2RECT. UpdateWindow enforces immediately updated window All or some of the customer area of the ValidateRect verification window WindowFromPoint returns the handle of the window that contains the specified point. Ignore the mask, hidden and transparent window ========================================== ============ Hardware and system functions ---------------- ActivateKeyboardLayout Activate a new keyboard layout. The keyboard layout defines the position and meaning of the button on a physical keyboard. ----------------------------- VB declaration Declare function activateKeyboardLayout lib "user32" alias "ActivateKeyboardLayout" (Byval HKL AS Long) As long Description Activate a new keyboard layout. The keyboard layout defines the position and meaning of the button on a physical keyboard. return value Long, if the execution is successful, returns the handle of the previous keyboard layout; zero means failure. Set GetLastError 叁 Types and description HKL Long, specify a handle of a keyboard layout. This layout is loaded with the LoadKeyboardLayout or getKeyboardLayoutList function. You can also activate the next loaded layout by HKL_NEXT constant; or use HKL_PREV loads the previous layout Flags Long, move the specified keyboard to the beginning of the internal keyboard layout list ============================================================================================================================================================================================================= === BEEP is used to generate simple sounds Chartooem converts a string from ansi character set to OEM character set Clipcursor limits the pointer to the designated area ConvertDefaultLocale converts a special place identifier into a real place ID CreateCaret Creates an insert (cursor) based on the specified information, and selects it as the default insertion of the specified window. DestroyCaret Clear (destroy) an insert Enumcalendarinfo enumerates calendar information available in the specified "place" environment EnumdateFormats lists the long, short date format available in the designated "local" settings. EnumsystemCodePages Enumerates the code page installed or supported in your system EnumsystemLocales enumeration system installed or supported "local" settings EnumTimeFormats enumerates a specified place to apply time format EXITWINDOWSEX exits Windows and restarts with a specific option ExpandenVironmentStrings Expand the environment string FreeENVIRONMENTSTRINGS translation specified environmental string block Getacp Judging the ANSI code page currently in force GetasyncKeyState determines the status of the virtual key when the function is called GetCareTblinkTime judges the blinking frequency of the insert spectrum GetCareTPOS to determine the current location of the insert GetClipCursor acquires a rectangle for describing the cutting area currently specified by the mouse pointer GetCommandline gets a pointer to the current command line buffer GetComputername acquired the name of this computer GetCPinfo gets information about the specified code page GetCurrencyFormat Formats a number according to the currency format for the specified "place" setting GetCursor Gets the handle of the currently selected mouse pointer GetCursorpos gets the current location of the mouse pointer GetDateFormat formats a system date for the specified "local" format. GetDoubleClickTime Judging the interval between the two-clicked mouse click GetENVIRONMENTSTRINGS assigns and returns a handle for a memory block set by the current environment string GetENVIRONMENTVARIABLE obtains a value of an environment variable GetInputState determines whether there is any mouse or keyboard event that is presented (waiting) GetkbcodePage is replaced by getoemcp, both of which are identical GetKeyboardLayout gets a handle to describe the keyboard layout of the specified application GetKeyboardLayoutList gets a list of all keyboard layouts that apply system applications GetKeyboardLayoutName gets the name of the current active keyboard layout GetKeyboardState gets the current state of each virtual key on the keyboard. GetKeyboardType understands information related to the keyboard being used GetKeyNameText judges the key name under the premise of give the scan code GetKeyState determines the status of the specified virtual key when the processed button is entered for the processed button. GetLastError acquires an extended error message with this function for the previously called API function. GetLocaleInfo acquires information related to the designated "place" GetLocalTime gets local dates and time GetNumberformat formats a number in a specific format for the specified "place" Getoemcp Judging Windows Code Page in OEM and ANSI Character Sets GetQueuesttus determines the type of message that is in the application message queue in the application message queue GetSysColor judges the color of the specified window display GetSystemDefaultLangid acquires the default language ID of the system GetSystemDefaultlcid gets the current default system "place" GetSystemInfo acquires information related to the underlying hardware platform GetSystemMetrics returns information related to the Windows environment GetSystemPowerStatus gets information about the current system power status GetSystemTime gets current system time, this time is "synergistic world time" (ie UTC, also known as GMT) format GetSystemTimeAdjustment synchronizes the internal system clock with an external clock signal source GetThreadlocale gets the local ID of the current thread GetTickCount is used to get the length of time (milliseconds) experience since Windows startup. GetTimeFormat formats a system time in a specific format for the currently specified "place" GetTimeZoneInformation acquires information related to system time zone settings GetUserDefaultLangId acquires the default language ID for the current user GetUserDefaultlcid gets the default "place" setting for the current user GetUsername gets the current user's name Getversion judges the current Run Windows and DOS version GetversionEx acquires version information related to platform and operating system Hidecaret hides inserted in the specified window (cursor) IsValidCodePage determines if a code page is valid IsValidLocale determines if the local identifier is valid KeyBD_EVENT This function simulates keyboard action LoadKeyboardLayout loads a keyboard layout MapVirtualKey performs different scan code and character conversion according to the specified mapping type MapVirtualKeyex performs different scan code and character conversion according to the specified mapping type MessageBeep play a system sound. The allocation scheme of the system sound is determined in the control panel. Mouse_Event Simulates a mouse event OemKeyscan judges a scan code and SHIFT key status of an ASCII character in the OEM character set. OEMTOCHAR converts a string of the OEM character set to ansi character set SetCareTBLINKTIME Specifies the flashing frequency of the insert (cursor) SetCareTPOS Specifies the location of the insert SetComputername Setting up new computer name SetCursor sets the specified mouse pointer to the current pointer SetCursorpos Set the position of the pointer SetDoubleClickTime Settings Two mouse clicks can make the system think that the interval between the double-click event SetENVIRONMENTVARIABLE sets an environment variable to the specified value SetKeyboardState Set the status of each virtual key on the keyboard SetLocaleInfo changes the user "local" setting information SetLocalTime Sets the current place Setsyscolors Settings Specifying Windows Show Colors SetSystemCursor changes any standard system pointer SetSystemTime Sets the current system time SetSystemTimeAdJustment Timed Add a calibration value to synchronize the internal system clock with an external clock signal source SetthreadLocale sets places for current threads SetTimeZoneInformation Set System Time Zone Information Showcaret displays insert (cursor) in the specified window Showcursor controls the visibility of the mouse pointer SwapmouseButton decides whether to switch the function of the mouse SystemParametersInfo gets and sets the number of Windows system numbers SystemTimeTotzspecificLocalTime converts system time to local time Toascii converts a virtual key to a ASCII character based on the current scan code and keyboard information Tounicode converts a virtual key to Unicode characters according to the current scan code and keyboard information. UnloadKeyboardLayout Uninstalls the specified keyboard layout VKKEYSCAN is a ASCII character for Windows characters, judges the status of virtual keys and SHIFT keys Finish ============================================================================================================================================================================================================= ==== Menu function --------------- Appendmenu Add a menu item in the specified menu ---------------------------------------- VB declaration Declare function appendmenu lib "user32" alias "appendmenua" (Byval WFLAGS As long, Byval WidnewItem As Any) AS LONG Description Add a menu item in the specified menu return value LONG, non-zero means success, zero means failure. Set GetLastError 叁 Types and description HMENU Long, menu handle WFLAGS long, the menu constant flag definition table in the modifyMenu function, which lists all constants allowed WidnewItem Long, specify the new command ID of the menu entry. If the MF_POPUP field is specified in the WFLAGS number, this should be a handle pointing to a pop-up menu. LPNewItem String (corresponding VB declaration) If the MF_String flag is specified in the WFLAGS number, this represents the string set in the menu. If the MF_bitmap flag is set, this represents a long type variable, which contains a bitmap sector. If you set MF_OWNERDRAW, this value will be included. DrawItemStruct and MeasureItemStruct structure, when the entry needs to be redrawn by Windows Send out annotation Declare function appendmenu & lib "user32" alias "appendmenua" (Byval WFLAGS As Long, Byval WidnewItem As String) ============================================================================================================================================== CheckMenuItem checks or revokes the check-specified menu entry CheckmenuradioInItem specifies a menu entry being subselected as "radio" project CreateMenu creates a new menu CreatePopupMenu Creates an empty pop-up menu DeleteMenu Removes the specified menu entry DestroyMenu Delete the specified menu DrawMenubar sends a menu for the specified window EnableMenuItem allows or prohibits designated menu entry GetMenu gets the handle of a menu in the window GetMenuCheckMarkDimensions returns a size of a menu check GetMenuContexthelpid acquires a menu help scene ID Which entry in the GetMenudefaultItem determination menu is the default entry GetMenuItemcount returns the number of entries (menu items) in the menu GetMenuItemID Returns menu ID in the entry at the specified location in the menu GetMenuItemInfo acquires specific information related to a menu entry GetMenuItem loading screen coordinate information on a specified menu entry in a rectangle GetMenustate acquires information related to the status of the specified menu entry GetMenustring gets the string of the specified menu entry GetSubmenu acquires a handle of a pop-up menu, which is located in the menu GetSystemMenu gets the handle of the system menu of the specified window HiliteMenuItem controls the top-level menu entry to highlight the display status InsertMenu inserts a menu entry at the specified location of the menu and moves other entries down as needed. InsertMenuItem inserts a new menu entry IsMenu judges whether or not the specified handle is a handle of a menu LoadMenu loads a menu from the specified module or application instance LoadMenuindirect loads a menu MenuItemFromPoint determines which menu entry contains a specified point on the screen ModifyMenu change the menu entry RemoveMenu Removes the specified menu entry SetMenu Settings Window Menu SetMenuContexthelpid sets a menu help scene ID SetMenudefaultItem will set a menu bar as the default entry SetMenuItemBitmaps Set a specific bitmap to use it in the specified menu entry, replace the standard check symbol () SetMenuItemInfo sets the specified information for a menu entry TRACKPOPUPMENU displays a pop-up menu anywhere on the screen TRACKPOPUPMENUEX is similar to TRACKPOPUPMENU, but it provides additional features Finish Here are a few types of definitions about menu functions Menuiteminfo This structure contains information on menu entry TPMPARAMS This structure is used for TrackPopUpMenuex functions to support additional features. ============================================================================================================================================================================================================= ==== Draw function ------------ Abortpath Abandon all paths in the specified device scenario. Also canceled the creation of any path currently ongoing -------------------------------------------------- --------------------- VB declaration Declare Function Abortpath LIB "GDI32" Alias "Abortpath" (Byval HDC As Long) AS Long Description Abandon all paths in the specified device scenario. Also canceled the creation of any path currently ongoing return value LONG, non-zero means success, zero means failure. Set GetLastError Types and description HDC Long, equipment scene ======================================= Anglearc draws a line with a connection arc ----------------------------- VB declaration Declare function Anglearc LIB "GDI32" Alias "Anglearc" (Byval HDC As Long, Byval ESTAR DWRADIUS AS Long, Byval Estartangle As Double, Byval Esweepangle As Double) As long Description Use a connection arc painting, return value Long, non-zero syndrome success, zero failed 叁 Types and description HDC Long, the device scenario in which X, Y long, a circular center point coordinate of the arc Dwradius long, round radius Estartangle Double, the angle when the line is connected to the circle (in units of degrees) Esweepangle Double, the range of arc occupies in the circle (in units of degrees) annotation Note that Estartangle and EsWeepangle parameters are specified in units of degrees, and should be single precision (Single ), Not double precision. The corresponding function declaration is: Declare Function Anglearc & LIB "GDI32" (Byval HDC As Long, Byval X As Long, Byval Y, byval Estartangle As Single, Byval EswePangle As Single). My understanding: The function declared in this article is copied to the VB's API text viewer. The declaration from me came from my entry, and I don't know who is wrong. Description of the number table, press the data type in the declaration replication in the VB's API text viewer. Please pay attention ============================================================================================================================================================================================================= === ARC draws a arc BeginPath launches a path branch Canceldc Cancels the long-term drawing operation in another thread Chord draws a string Closeenhmetafile closes the specified enhanced chamber file device scene and returns a newly created element file. Closefigure is depicted to a path, close the currently open graphics Closemetafile closes the specified primitive file device scene and returns a handle to the newly created element file. Copyenhmetafile makes a copy of the specified enhanced element file (copy) CopyMetafile creates a copy of the designated (standard) element file Createbrushindirect creates a brush on a logbrush data structure CreateDibPatternbrush creates a brush with a bitmap that is not related to the device to specify a brush style (pattern) CREATEENHMETAFILE Create a enhanced element file device scene CreateHatchbrush creates a brush with shadow patterns CreateMetafile creates a chair file device scene CreatePatternbrush creates a brush createpen with a specified style, width and color with a specified style, width, and color with a specified style, width, and color CreatepenIndirect creates a brush according to the specified Logpen structure CreateSolidbrush creates a brush with solid color Deletenhmetafile deletes the specified enhanced element file DeleteMetAfile deletes the specified element file DeleteObject deletes GDI objects, all system resources that are used, are released Drawedge depicts a rectangular border with a specified style Drawscape Call Code (ESCAPE) function sends data directly to the display device driver DrawfocusRect draws a focus rectangle DrawFraMecontrol depicts a standard control DrawState is a variety of effects for an image or drawing operation. Ellipse depicts an ellipse, surrounded by the designated rectangle Endpath stops defining a path ENUMENHMETAFILE lists a separate element file record for an enhanced element file Enummetafile enumerates a separate chamber file record for a standard Windows element file. Enumbobjects enumerates a brush and brush that can be used with the specified device scene ExtCreatepen creates an extension brush (decorative or geometry) Extfloodfill fills a zone with the currently selected brush in the specified device scenario FillPath close any open graphics in the path and populates the current brush FillRect fills a rectangle with the specified brush FLATTENPATH converts all the curves in a path into line segments FLOODFILL pops a zone in the specified device scene with the currently selected brush Framerect with a specified brush a border around a rectangle GDICOMMENT adds a comment information for the specified enhanced element file device scenario GDIFLUSH performs any unresolved drawing operations GDIGETBATCHLIMIT judge how many GDI drawings are in the queue GDisetBatchLimit specifies how many GDI draws commands can enter the queue GetarcDirection When drawing a circular arc, judge the currently used drawing direction GetBkcolor gets the designated device scene current background color GetBKMode For the specified device scenario, get the current background fill mode Getbrushorgex judges the starting point of the currently selected brush in the specified device scene GetCurrentObject Gets the currently selected object of the specified type GetCurrentPositionEx gets the current brush position in the specified device scenario GetENHMetAfile acquires the element file handle of a enhanced element file included in the disk file GetenhmetafileBits copies the specified enhancement element file to a memory buffer GetenhmetafileDescription returns a description of a enhanced element file GetenhmetafileHeader gets the element file header of the enhanced element file GetENHMETAFILEPALETTEENTERTRIES acquires all or part of the palette of the enhanced element file GetMetAfile acquires the meta file handle of the element file contained in a disk file GetMetAfileBitsex copies the specified primitive to a memory buffer GetMiterLimit gets the slope limit of device scenes (MITER) settings GetnearestColor acquires a solid color closest to the specified color based on the display capabilities of the device GetObjectAPI acquires a structure for specified objects GetObjectType determines the type of GDI object referenced by the specified handle GetPath acquires a series of data defined for the current path GetPixel acquires a pixel RGB value in the specified device scenario GetPolyfillMode gets polygon padding mode for the specified device scenario. Getrop2 For the specified device scene, getStockOckOckOckObject gets an inherent object (stock) for the specified device scenario. Getsyscolorbrush got a brush for any standard system color GetWinMetafileBits converts a enhanced element file into a standard Windows element file by popping data for standard primitive files in a buffer. InvertRect reverses the rectangle specified in a device scene by reversing the value of each pixel Linedda enumerate all points in the specified line segment Lineto is used in a line with the current brush, and is connected from the current location to a specified point. ============================================================================================================================================================================================================= ==== Strtoint STRTOINT64 StrtoinTdef STRTOINT64DEF INTSTR Strlen STREND Strcopy Strmove STRECOPY Strlcopy Strpcopy STRPLCOPY Strcat Strlcat Strcomp Stricomp Strlcomp Strlicomp Strscan STRSCAN Strpos Strupper Strlower StrPas Stralloc Strbufsize Strnew Strdispose