Delphi programming skills collection

Source: Internet
Author: User
Tags random seed
◇ [DELPHI] copying files by network neighbors
Uses shellapi;
Copyfile(pchar('newfile.txt '), pchar (' // computername/ction/targer.txt '), false );

◇ [DELPHI] results in mouse dragging
Implemented through the MouseMove event, DragOver event, and EndDrag event, such as the LABEL on the PANEL:
Var xpanel, ypanel, xlabel, ylabel: integer;
PANEL MouseMove event: xpanel: = x; ypanel: = y;
DragOver event of PANEL: xpanel: = x; ypanel: = y;
LABEL MouseMove event: xlabel: = x; ylabel: = y;
LABEL EndDrag event: label. left: = xpanel-xlabel; label. top: = ypanel-ylabel;

◇ [DELPHI] obtain the WINDOWS directory
Uses shellapi;
Var windir: array [0 .. 255] of char;
Getwindowsdirectory (windir, sizeof (windir ));
Or read from the Registry, Location:
HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion
SystemRoot key, for example, C: \ WINDOWS

◇ [DELPHI] draw lines on FORM or other containers
Var x, y: array [0 .. 50] of integer;
Canvas. pen. color: = clred;
Canvas. pen. style: = psDash;
Form1.canvas. moveto (trunc (x [I]), trunc (y [I]);
Form1.canvas. lineto (trunc (x [j]), trunc (y [j]);

◇ [DELPHI] string list usage
Var tips: tstringlist;
Tips: = tstringlist. create;
Tips.loadfromfile('filename.txt ');
Edit1.text: = tips [0];
Tips. add ('Last line addition string ');
Tips. insert (1, 'insert string at NO 2 line ');
Tips.savetofile('newfile.txt ');
Tips. free;

◇ [DELPHI] Simple clipboard operations
Richedit1.selectall;
Richedit1.copytoclipboard;
Richedit1.cuttoclipboard;
Edit1.pastefromclipboard;

◇ [DELPHI] file and directory operations
Chdir ('C: \ abcdir'); go to the directory
Mkdir ('dirname'); create a directory
Rmdir ('dirname'); Delete the Directory
Getcurrentdir; // get the name of the current directory, '\'
Getdir (0, S); // get the working directory name s: = 'C: \ abcdir ';
Deletfile('abc.txt '); // delete an object
Renamefile('old.txt', 'new.txt '); // rename the file
Extractfilename (filelistbox1.filename); // obtain the file name
Extractfileext (filelistbox1.filename); // obtain the file suffix

◇ [Delphi] processing file attributes
ATTR: = filegetattr (filelistbox1.filename );
If (ATTR and fareadonly) = fareadonly then... // read-only
If (ATTR and fasysfile) = fasysfile then... // System
If (ATTR and faarchive) = faarchive then... // Archive
If (ATTR and fahidden) = fahidden then... // hide

◇ [Delphi] execute files outside the program
Winexec // call the executable file
Winexec ('COMMAND. com/C copy *. * c: \ ', sw_normal );
Winexec ('start abc.txt ');
ShellExecute or shellexecuteex // start the File Association Program
Function executefile (const filename, Params, defaultdir: string; showcmd: integer): thandle;
Executefile ('C: \ ABC \ a.txt ', 'x. abc', 'c: \ ABC \', 0 );
Executefile ('HTTP: // tingweb.yeah.net ', '','', 0 );
Executefile ('mailto: tingweb@wx88.net ', '','', 0 );

◇ [Delphi] obtain the system running process name
VaR hcurrentwindow: hwnd; sztext: array [0 .. 254] of char;
Begin
Hcurrentwindow: = getwindow (handle, gw_hwndfrist );
While hcurrentwindow <> 0 do
Begin
If getwindowtext (hcurrnetwindow, @ sztext, 255)> 0 then listbox1.items. Add (strpas (@ sztext ));
Hcurrentwindow: = getwindow (hcurrentwindow, gw_hwndnext );
End;
End;

◇ [Delphi] Assembly embedding
ASM end;
You can modify eax, ECx, and EDX at will. You cannot modify ESI, EDI, ESP, EBP, and EBX.

◇ [Delphi] About type conversion functions
Floattostr // float to string
FloatToStrF // formatted floating point to string
IntToHex // convert integer to hexadecimal
TimeToStr
DateToStr
DateTimeToStr
FmtStr // output string in specified format
FormatDateTime ('yyyy-MM-DD, hh-mm-ss', DATE );

◇ [DELPHI] string process and Function
Insert (obj, target, pos); // the position where the target string is inserted in the pos. If the insert result is greater than the maximum length of target, the extra characters will be truncated. If Pos is not 255, an error occurs. For example, if st: = 'Brian ', Insert (' OK ', st, 2) will change st to 'brokian '.
Delete (st, pos, Num); // Delete the substring whose number is Num (integer) characters from the pos (integer) position in the st string. For example, if st: = 'Brian ', Delete (st, 3, 2) is changed to Brn.
Str (value, st); // converts a value (integer or real) into a string and places it in the st. For example, if a = 2.5E4, str (a: 10, st) will set the value of st to '123 '.
Val (st, var, code); // converts the string expression st to an integer or a real value, which is stored in var. St must be a string that represents a value and complies with the numerical constant rules. If no error is detected during conversion, the variable code is set to 0; otherwise, it is set to the first error character. For example, if st: = 25.4E3 and x is a real variable, val (st, x, code) will set X to 25400 and code to 0.
Copy (st. pos. num); // returns a substring that starts at the position pos (integer) in the st string and contains num (integer) characters. If the pos value is longer than the length of the st string, an empty string is returned. If the pos value is not greater than 255, a running error occurs. For example, if st: = 'Brian ', Copy (st, 2, 2) returns 'ri '.
Concat (st1, st2, st3 ......, Stn); // connect the strings represented by all independent variables in the given order and return the connected values. If the result length is 255, a running error occurs. For example, if st1: = 'Brian ', st2: = '', st3: = 'wilfred', Concat (st1, st2, st3) returns 'Brian Wilfred '.
Length (st); // returns the Length of the string expression st. For example, if st: = 'Brian ', the return value of Length (st) is 5.
Pos (obj, target); // returns the position of the string obj In the first appearance of the target string. If the target does not have a matched string, the return value of the Pos function is 0. For example, if target: = 'Brian Wilfred ', the return value of Pos ('wil', target) is 7, and the return value of Pos ('hurbet ', target) is 0.

◇ [DELPHI] About processing the Registry
Uses Registry;
Var reg: Tregistry;
Reg: = Tregistry. create;
Reg. rootkey: = 'HKEY _ Current_User ';
Reg. openkey ('control Panel \ Desktop ', false );
Reg. WriteString ('title Wallpaper ', '0 ');
Reg. writeString ('wallpaper ', filelistbox1.filename );
Reg. closereg;
Reg. free;

◇ [DELPHI] keyboard constant name
VK_BACK/VK_TAB/VK_RETURN/VK_SHIFT/VK_CONTROL/VK_MENU/VK_PAUSE/VK_ESCAPE
/VK_SPACE/VK_LEFT/VK_RIGHT/VK_UP/VK_DOWN
F1--F12: $70 (112) -- $ 7B (123)
A-Z: $41 (65) -- $ 5A (90)
0-9: $30 (48) -- $39 (57)
◇ [DELPHI] preliminary judgment of the program's mother tongue
DOS prompt of DELPHI software: This Program Must Be Run Under Win32.
DOS prompt of VC ++: This Program Cannot Be Run In DOS Mode.

◇ [DELPHI] Cookie operations
Response. cookies ("name"). domain: = 'HTTP: // www.086net.com ';
With response. cookies. add do
Begin
Name: = 'username ';
Value: = 'username ';
End

◇ [DELPHI] add to Document menu connection
Uses shellapi, shlOBJ;
Shaddtorecentdocs (shard_path, pchar (filepath); // Add a connection
Shaddtorecentdocs (shard_path, nil); // clear

◇ [Miscellaneous] intelligent ABC input dictionary for backup
WINDOWS \ SYSTEM \ User. Rem
WINDOWS \ SYSTEM \ tmmr. Rem

◇ [Delphi] Determining the mouse buttons
If getasynckeystate (vk_lbutton) <> 0 then... // left click
If getasynckeystate (vk_mbutton) <> 0 then... // middle
If getasynckeystate (vk_rbutton) <> 0 then... // right-click

◇ [Delphi] set the maximum display of the form
Onformcreate event
Self. Width: = screen. width;
Self. Height: = screen. height;

◇ [Delphi] press the button to receive messages
Oncreate event processing: application. onmessage: = myonmessage;
Procedure tform1.myonmessage (var msg: tmsg; var handle: Boolean );
Begin
If MSG. Message = 256 then... // any key
If MSG. Message = 112 then... // F1
If msg. message = 113 then... // F2
End;

◇ [Miscellaneous] Hide Shared Folders
Shared effect: accessible, but invisible (in resource management and network neighbors)
Share Name: direction $
Access: // computer/dirction/

◇ [Java Script] common effects of Java Script web pages
Page closed in 60 seconds
<Script language = "java script"> <! --
Settimeout ('window. close (); ', 60000)
--> </Script>
Close Window
<A href = "/" onclick = "javascript: window. close (); return false;"> close
Regular conversion URL
<Meta http-equiv = "refresh" content = "40; url = http://www.086net.com">
Set as Homepage
<A onclick = "this. style. behavior = 'url (# default # homepage) '; this. sethomepage ('HTTP: // 086net.com '); "href =" # "> set as Homepage
Add to favorites
<A href = "javascript: window. external. addfavorite ('HTTP: // 086net.com ',' [unknown dock] ')"> Add to favorites
Add Channel
<A href = "javascript: window. External. addchannel ('HTTP: // 086net.com ')"> Add to channel

◇ [Delphi] text editing
Checkbox1.checked: = Not checkbox1.checked;
If checkbox1.checked then richedit1.font. Style: = richedit1.font. Style + [fsbold] else richedit1.font. Style: = richedit1.font. Style-[fsbold] // bold
If checkbox1.checked then richedit1.font. Style: = richedit1.font. Style + [fsitalic] else richedit1.font. Style: = richedit1.font. Style-[fsitalic] // Italic
If checkbox1.checked then richedit1.font. Style: = richedit1.font. Style + [fsunderline] else richedit1.font. Style: = richedit1.font. Style-[fsunderline] // underline
Memo1.alignment: = taleftjustify; // left
Memo1.alignment: = tarightjustify; // right
Memo1.alignment: = tacenter; // center

◇ [Delphi] randomly generate text colors
Randomize; // Random Seed
Memo1.font. color: = rgb (random (255), random (255), random (255 ));

◇ [DELPHI] DELPHI5 UPDATE Patch serial number
1000003185
90X25fx0

◇ [DELPHI] illegal character filtering for file names
For I: = 1 to length (s) do
If s [I] in ['\','/',':','*','? ',' <','> ',' | '] Then

◇ [DELPHI] definition and description of conversion functions
Datetimetofiledate (datetime: Tdatetime): longint; convert the datetime value in Tdatetime format to the datetime value in DOS format
Datetimetostr (datetime: Tdatetime): string; convert the Tdatatime format variable to a string. If the datetime parameter does not contain the date value, return the string date displayed as 00/00/00, if the datetime parameter does not contain a time value, the time part of the returned string is displayed as 00:00:00 AM.
Datetimetostring (var result string;
Const format: string;
Datetime: Tdatetime); according to the given format String Conversion time and date value, result is the result string, format is the conversion format String, datetime is the date Time Value
Datetostr (date: Tdatetime) converts the date parameter to the corresponding string using the format string defined by the shortdateformat global variable
Floattodecimal (var result: Tfloatrec; value:
Extended; precision, decimals:
Integer); converts a floating point to a decimal representation.
Floattostr (value: extended): string converts a floating point value to a string format. This conversion uses the common numeric format, and the valid digits of the conversion are 15 digits.
Floattotext (buffer: pchar; value: extended;
Format: Tfloatformat; precision,
Digits: integer): integer. The floating point value is converted into a decimal representation using the given format, precision, and decimal number. The conversion result is stored in the buffer parameter, the Return Value of the function is the number of characters stored in the buffer, and the buffer is a string buffer with non-zero results.
Floattotextfmt (buffer: pchar; value: extended;
Format: pchar): integer converts a floating point value to a decimal representation in the given format. The conversion result is stored in the buffer parameter, and the return value of the function is the number of characters stored in the buffer.
Inttohex (value: longint; digits: integer ):
String; converts a given value to a hexadecimal string. The digits parameter indicates the number of digits contained in the conversion result string.
Inttostr (value: longint): string converts an integer to a decimal string.
Strtodate (const S: string): Tdatetime converts a string to a date value. S must contain a string in a valid date format.
Strtodatetime (const S: string): Tdatetime converts string S to the datetime format. S must be in MM/DD/yy hh: MM: SS [AM | PM] format, the date and time delimiters are related to the time constant settings in the system period. If the AM or PM information is not specified, the 24-hour format is used.
Strtofloat (const S: string): extended; converts a given string to a floating point. The string has the following format:
[+ |-] Nnn... [.] Nnn... [<+ |-> <E | e> <+ |-> nnnn]
Strtoint (const S: string): longint converts a numeric string to an integer. The string can be in decimal or hexadecimal format. If the string is not a legal numeric string, an ECONVERTERROR exception occurs.
Strtointdef (const S: string; default:
Longint): longint; converts string S to a number. If the string S cannot be converted to a number, the strtointdef function returns the default value.
Strtotime (const S: string): Tdatetime converts string S to a TDATETIME value. S has the format of HH: MM: SS [AM | PM, the actual format is related to the global variables related to the system time.
Timetostr (time: Tdatetime): string; converts the TIME parameter to a string. The format of the Conversion Result string is related to the system time-related constant settings.

◇ [DELPHI] the program does not appear ALT + CTRL + DEL
After implementation, add the Declaration:
Function RegisterServiceProcess (dwProcessID, dwType: Integer): Integer; stdcall; external 'kernel32. DLL ';
RegisterServiceProcess (GetCurrentProcessID, 1); // hide
RegisterServiceProcess (GetCurrentProcessID, 0); // display
Invisible with ALT + DEL + CTRL

◇ [DELPHI] the program does not appear in the taskbar
Uses windows
Var
ExtendedStyle: Integer;
Begin
Application. Initialize;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.