Transfer from: 9CBS
-------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ) Take a small number of int (x) Removal LN (X) Natural logarithmic sin (x) transmission back sinusoidal function value SQR (X) x * xsqrt (x) square root other PRED (X) PRED ('d') = ' C ', PRED (TRUE) = 1; SUCC (X) SUCC (' Y ') =' Z ', SUCC (PRED (X)) = XORD (X) See Qi in the character set, such as ORD (' A ') = 65chr (x) CHR (65) =' a'round (x) rounded Trunc (x) trunc (4.8) = 4, trunc ('- 3.6') = - 3Upcase (x) Upcase ('a') = 'A'Hi (I) Hi ($ 2A30) = 2ALO (i) LO ($ 2A30) = $ 30random (n) Generates a random integer SizeOf (Name) between [0, N) to find a type or variable Swap (num) SWAP ($ 3621) in memory ($ 3621) = $ 2136 =============================== Arithmetic Routines Mathematical Operation ================================ bs 绝 绝 绝 - ----------- -------------------------------------------- Unit system function prototype Function ABS (X); Description X is an integer or real number. Example Var r: real; i: integer; begin r: = ABS (-2.3); {2.3} i: = ABS (-157); {157} END; -------------------------------------------------- -------- Arctan triangle function ------------------------------------- ------------------- Example Cosvar r: Extended; Begin R: = COS (PI); End; ------------------------------------------------------------------------------------------------------ ------------------------------------------------- --------------------------- Example Var r: extended; s: 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) The three are not a function, but the right operation is obtained. Example Var r: Extended; Begin R: = Arctan (Pi); END; Example Var r: Extended ; S: 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 Letter Number FUNCTION INT (X: Real): Real; Description X is real. Example Var r: real; begin r: = int (123.456); {123.0} r: = int (-123.0}); {-123.0} END; ----------------------------------------- Pi is the pi of mathematics --- -------------------------------------- Unit system function prototype Function PI: Extended; Is a function, but we will use it as a preset variable! Pi = 3.1415926535897932385 --------------------------- --------------------------------------------------------------------------- ---------- 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; --------------------------------------- SQRT X's square root --- -------------------------------------- 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 logaries ----- ------------------------------------- Example Var E: REAL; S: 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; function prototype Function Exp (x: real): real; example var E: real; s: string; begin E: = Exp (1.0); STR (ln (e): 3: 2, s); S: = 'ln (e) =' s; Canvas.Textout (10, 10, s); EN D; ----------------------------------------- Date and Time Routines Date and Time functions ---------------------------------------- Date Retrieving the current date Unit sysutils function prototype Function Date: tdatetime; example procedure tform1.button1click (sender: TOBJECT); begin label1.caption: = 'Today is' datetostr (date); end; ------------ ------------------------------- DateTimetostr Date Time Convert into an internal stereotype (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: = DATETITOSTR (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 s: 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 exams below .formatdatetime. ------ -------------------------------------------------- The DateTostr Date is converted into an internal stereotype. (1996/12/20) -------------------------------- ------------------------ Unit sysutils function prototype Function DateTostr (date: tdatetime): String; Sample Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Label1.caption: = 'Today Is' DateTostr (Date); end; # Date, DateTostr Example -------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- -Unit sysutils function prototype Function Dayofweek (Date: TdateTime): Integer; Note The return value is an integer, 1 ~ 7. Sunday is 1. Example procedure tform1.button1click (sender: TOBJECT); var adtere: 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)];
# Stradate, Dayofweek Example --------------------------------------------- ---------- Decodedate changes the date variable to the TDATETIME type, and turn to Word type. -------------------------------------------------------------------------- -------------------------------- Example procedure tform1.button1click (sender: TOBJECT); VAR Present: tdatetime; Year, Month, Day, Hour, min, sec, msec: word; begin present: = now; decodate (present, year, month, day); label1.caption: = 'Today' $ INTOSTR (DAY) 'of Month ' INTSTOSTR (MONTH) ' of year ' INTOSTR (YEAR); Decodetime (Present, Hour, min, sec, msec); label2.caption: =' Time is minute ' INTOSTR (min) of Hour ' INTOSTR (Hour); end; # decodate, decodetime example ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------ Decodetime to turn the TDATETIME type time variable, turn 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); Example Procedure TFORM1.BUTTON1CLICK (Sen DER: TOBJECT); VAR Present: Tdatetime; Year, Month, Day, Hour, min, sec, msec: word; begin present: = now; decodate (present, year, month, day); label1.caption: = 'TODAY Is Day ' INTOSTR (DAY) ' of MONTH ' INTOSTR (MONTH) ' of year ' INTOSTOSTR (YEAR); Decodetime (Present, Hour, min, sec, msec); label2.caption: =' Time Is Minute ' INTOSTR (MIN) ' of Hour ' INTOSTR (HOUR); END; --------------------------------------------------------------------------------------------------------------------------------- -------------------------- Encodedate changes the date of the Word type,
Go to TDATETIME type. -------------------------------------------- ------------ Example Procedure TFORM1.BUTTON1CLICK (Sender: Tobject); var mydate: tdatetime; begin mydate: = encodedate Edit3.text); label1.caption: = DATETOSTR (MyDate); end; -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------- Encodetime to turn the Word type time variable, turn to TDATETIME type. -------------- ------------------------------------------ Unit sysutils function prototype Function EncodeDate (Year, Month, Day: Word): TDateTime; function prototype function EncodeTime (Hour, Min, Sec, MSec: Word): TDateTime; example 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's format to a string. --------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- Unit sysutils function prototype Function FormatDatetime (const format: string; datetime: tdatetime): string;
**** Similar to DateTimetString.Format format C-fixed shortdateformat format. (1996/12/20 09:20:15 pm) .D dates, not completed in front. (1-31) DD date, before complement 0. (01-31) DDD Week. (Sunday) .dddd Chinese version 2.01, the same .ddddd Date. (1996/12/20) DDDDDD date. (December 20, 1996) M month, not completed 0. (1 -12) MM, previously added 0. (01-12) MMM Chinese display. (December) MMMM Chinese version 2.01, the same .yy year. (0000-9999) H hours. (0-23) HH hours. (00-23) n minutes. (0-59) NN minute. (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, larger 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: = 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. --------------- ---------------------------------------- Unit sysutils function prototype Function now: TDATETIME Sample procedure tform1.button1click (sender: TOBJECT); begin label1.caption: = DateTimetostr (now); end; # now, datetimetostr esample ---- -------------------------------------------------- --STRTODATE turns the 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: = strandate (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; # strtodate, dayofweek eXample ---- -------------------------------------------------- --STRTODATETIME Time to turn the string to the TDATETIME type. ----------------------------------- --------------------- Unit sysutils function prototype Function Strtodatetime (const s: string): tdatetime; example procedure tForm1.button1click (sender: TOBJECT); VAR AdatendTime: TDATETIME: = strandTime (edit1.text); table1.fieldByname ('timestamp'). Asdatetime: = adatendTime; end; ------------------- ---------------------------------- Strtotime Time to turn the string into the TDATETIME type. --- -------------------------------------------------- --- Unit SysUtils function prototype function strToTime (const S: string): TDateTime; example procedure TForm1.Button1Click (Sender: TObject); var aTime: TDateTime; begin aTime: = strToTime (Edit1.Text); if aTime <0.50 then ShowMessage ('Good Morning') Else ShowMessage ('Good Afternoon'); End; ------------------------ ------------------------------- Time passed the 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 capen {Note This Could Have Been Done with the following line of code: Caption: = Timetostr (TIME);
# Time, Timetostr Example --------------------------------------------------------------- ----------- Timetostr Time Convert into an internal stereotype. (09:20:15 pm) ---------------------- -------------------------------- Unit sysutils function prototype Function Timetostr (Time: tdatetime): String; getMem Procedure Configure the memory space of the memory program NEW to configure the memory space of the native P. ---------------------------- ----------------------------- Dispose releases the memory configured by New .---------- -------------------------------------------- Unit system function prototype procedure New (var P: Pointer); function prototype procedure Dispose (var P: Pointer); sample 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 ...'; Dispose (p); {now you don't. ..} End; --------------------------------------------- - --------- GetMEM Configuration Remarks The memory space, the size can be set yourself. ------------------------ ------------------------------- 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); Finally FreeMem (buffer); end; 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; 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; fin or closefile (f); end; end; ====================== =============== file-management routines file management Circular =========================== ========= ----------------------------------------- --------------- ChangefileExt Change Archive --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------- Unit sysutils function prototype Function ChangefileExt (const filename, extension: string): string; example procedure tForm1.button1click (Sender: TOBJECT); VAR S: STRING; P1: String; P2: String; Begin P1: = 'abc.txt'; p2: = '. Ini'; s: = ChangefileExt (P1, P2); Label1.caption : = S; END; Results 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 s: string; icon: ticon; begin openDialog1.default: =' .ico '; OpenDialog1 .Filter: = 'icons (* .ico) | * .ico'; OpenDialog1.Options: =
[OfOverwritePrompt, ofFileMustExist, ofHideReadOnly]; if OpenDialog1.Execute then 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 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------ SYSUTILS Function Prototype Function ExpandFileName (const filename: String): String; Description Set the current directory to c: / windows file name is abc.txt result is C: /Windows/abc.txt **** This function is not to ask for ABC The path of .txt. Sample procedure tform1.button1click (sender: Tobject); var s: string; begin s: = expandFileName ('abc.txt'); label1.caption: = s; end; example Procedure TFO RM1.Button1Click (sender: Tobject) Begin ListBox1.Items.Add (EDIT1.TEXT)); END; ------------------------- ----------------------------------------- DirectoryExists directory exists ----- -------------------------------------------------- ----------- UnitFileCtrluses 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; ---------------------------------- ---------------------- Forcedirector Directory -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------ Unit FileCtrl function prototype Function Forcedirector (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'ENED; -------------------------------------------------- ----- ExpanduncFileName is the same as above (just get the path on the Internet) --------------------------------- -------------------- Unit sysutils function prototype Function ExpanduncFileName (const filename: string): String; ExtractFileDir Analysis string Path Unit sysutils Function Prototype Function ExtractFileDir Const filename: string: String; Description Set the s string is c: /windows/abc.txt result is the result of the C: / Windows **** function is to analyze its path to analyze its path Sample Procedure TFORM1.BUTTON1CLICK (Sender: Tobject); var s: 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: / '--------------------------------------- ------------------------------------------------------------------------------------------------------------------------------ ------------------------------ Unit Sy SUTILS function prototype Function ExtractFileDrive (const filename: String): String; **** functionally, only back the disk machine name. Seminyes Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); var s: string; p1: string; begin P1: = 'c: /windows/abc.txt'; s: = extractfileDrive (p1); label1.caption: = s; end; s: = 'c:' p1: = 'abc.txt' s == ' -------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ Unit sysutils function prototype Function ExtractFileExt (const filename: string): String;
Sample Procedure TFORM1.BUTTON1CLICK (Sender: Tobject); var s: 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 (only Playing the name of the file) -------------------------------------------- --------- Unit sysutils function prototype Function ExtractFileName (const filename: string): string; sample procedure tform1.button1click (sender: TOBJECT); var s: 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); Backu pName: = 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 begrain 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 -------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------- Unit sysutils function prototype Function ExtractFilePath (const filename: string): string; Description Set the s string is C: / Windows / ABC .txt results as c: / windows example procedure tform1.button1click (sender: Tobject); var s: string; p1: string; begin p1: = 'c: /Windows/abc.txt'; s: = extractfilepath (p1 ); Label1.caption: = s; end; example begin with session do beg, configmode: = cmsession; Try AddStandardalias ('Tempdb', ExtractFilePath (paramstr (0)), 'paradox'); Finally Configmode: = Cmall; End; End; ## configmode, addstandardalias, extractfilepath example ------------------- ------------------------------------- FileSearch Looking for the correct path in the disk machine - -------------------------------------------------- ---- Unit Sysutils Function Prototype Function FileSearch (const name, dirlist: string): string; example var s: string; begin s: = filesearch ('abc.txt', 'c: / window /'); label1. CAPTION: = S; END; Description Recovered 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 '.') Else ShowMessage ('Found' FileTofind ') ; End; ## filesearch, ShowMessage Example ----------------------------------------- --------------- Fileage Retrieves the date and time (DOS style). --------------------- --------------------------------- Unit sysutils function prototype Function Fileage (const filename: string): Integer; The description is the date of modification of the archive content of the archive. Example procedure tform1.button1click (sender: TOBJECT); var s: 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 TDATETIME. -------------------------------------------------- ----- Unit sysutils Function Prototype Function FileDatetodatetime (Filedate: Integer): TDATETIME; ------------------- -------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------ SYSUTILS Function Prototype Function DateTimetOfileDate (DateTime: Tdatetime): Integer; FilegetDate Replies Date and Time (DOS Site) .unit System: Integer (Handle: Integer): Integer; Description is the archive of the archive Examples of modified date procedure TForm1.Button1Click (Sender: TObject); var FileHandle:. Integer; S: 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 style). ------- -------------------------------------------------- ------------------ - Unit sysutils function prototype Function FileSetdate (Handle: Integer; age: integer; Integer; Note The return value is 0 means success .--- -------------------------------------------------- ------------------------ Deletefile Delete Archive --------------------- -------------------------------------------------- ---- Unit sysutils function prototype Function deletefile (const filename: String): boolean; example one deletefile ('delete.me'); example IF fileexists (filename) Then IF Messagedlg ('do you real want to delete' ExtractFileName (filename) '?'), []) = IDYES THEN Deletefile (filename); ## fileexists, deletefile example ---------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ------------------- Unit sysutils function prototype Function Renamefile (const6ame, newname: 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; -------------------------------------------------- ----------------------- DiskFree disk ------------------- --------- -------------------------------------------------- -Unit sysutils function prototype Function Diskfree (drive: Byte): Integer; sample var s: string; begin s: = INTOSTR (Diskfree (0) Div 1024) 'KBytes Free.'; Label1.caption: = S; end; Description DRIVE 0 = Current drive, 1 = A disk machine, 2 = B disk machine ... The transmission value is -1, indicating that the disk machine detection error is indicated. Example var s: string; amtfree: int64 Total: int64; Begin Amtfree: = DiskFree (0); Total: = disksize (0); s: = INTSTOSTR (AMTFREE DIV TOTAL) 'Percent of the space on drive 0 is free:' (Amtfree Div 1024) 'Kbytes free.'; Canvas.textout (10, 10, s); end;