Delphi programming highlights: small skill, small method

xiaoxiao2021-04-03  214

◇ [Delphi] network neighbor copy file

Uses shellapi;

Copyfile (Pchar ('newfile.txt'), pchar ('// computername / direction / targer.txt'), false);

◇ [Delphi] produces mouse drag effect

Implemented by mousemove events, Dragover events, enddrag events, such as Label on Panel:

Var Xpanel, YPANEL, XLabel, YLabel: Integer

Panel's Mousemove event: xpanel: = x; ypanel: = y;

PANEL's Dragover Event: xPanel: = X; YPANEL: = Y;

Mousemove event: xLabel: = x; ylabel: = y;

Label's enddrag event: label.Left: = xPanel-xlabel; label.top: = YPANEL-YLABEL

◇ [Delphi] gets a 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, achievements such as: C: / Windows

◇ [Delphi] Pictures on Form or other container

VAR X, Y: Array [0..50] of integer;

CANVAS.PEN.COLOR: = CLRED;

Canvas.pen.stylele:=psdash;

Form1.canvas.moveto (Trunc (x [i]), trunc (y [i]));

Form1.canvas.lineto (Trunc (x [j]), trunc (y [j]));

◇ [Delphi] string list

VAR TIPS: TSTRINGLIST;

Tips: = TSTRINGLIST.CREATE;

Tips.LoadFromfile ('filename.txt');

Edit1.Text: = TIPS [0];

Tips.add ('Last Line Additional String');

Tips.insert (1, 'INSERT STRING AT NO 2 LINE');

Tips.savetofile ('newfile.txt');

Tips.free;

◇ [Delphi] Simple clipboard operation

Richedit1.selectall;

Richedit1.copytoclipboard;

Richedit1.cuttoclipboard;

Edit1.PastefromClipboard;

◇ [Delphi] About file, directory operation

CHDIR ('c: / abcdir'); go to the directory

Mkdir ('DIRNAME'); establish a directory

RMDir ('DIRNAME'); Delete Directory

Getcurrentdir; // Take the current directory name, no '/'

Getdir (0, s); // Take the work directory name S: = 'c: / abcdir';

Deletfile ('abc.txt'); // Delete file

Renamefile ('ild.txt'); // Denname

EXTRACTFILENAME (fileListbox1.filename); // Take a file name

ExtractFileExt (fileListBox1.filename); // Take a file suffix ◇ [Delphi] Processing file properties

Attr: = filegetattr (fileListbox1.filename);

IF (attr and fareadonly = fareadonly kiln ... // read only

IF (attr and fasysfile) = fasysfile dam // system

IF (attr and faarch) = faarchive the ... // archive

IF (attr and fahidden) = fahidden dam ... // Hide

◇ [DELPHI] Execute the procedure file

Winexec // call executable

Winexec ('Command.com / c copy *. * c: /', sw_normal);

Winexec ('start abc.txt');

Shellexecute or ShellexecuteEx // Startup 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] gets the process name of the system running

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] embedding on compilation

ASM END;

Eax, ECX, EBP, EBX can be modified arbitrarily modified; ESI, EDI, ESP, EBP, EBX can not be modified.

◇ [Delphi] About Type Conversion Functions

FLOATTOSTR / / floating point string

FLOATTOSTRF / / floating point string with format

INTTOHEX / / integer turn 16

Timetostr

Datetostr

DateTimetostr

FMTSTR / / Output strings in specified format

Formator ('YYYY-MM-DD, HH-MM-SS', DATE);

◇ [Delphi] string process and functions

INSERT (OBJ, TARGET, POS); // String Target is inserted in POS. If the insertion result is greater than the maximum length of Target, multiple characters will be cut off. Such as POS is 255, it will generate an error. For example, st: = 'brian', INSERT ('OK', ST, 2) will make ST to 'Brokian'.

Delete (ST, POS, NUM); // From the POS (integer) position in the ST string, the number of substrings of NUM (integer) characters are started. For example, st: = 'brian', the delete (ST, 3, 2) will become BRN. Str (Value, ST); // Convert value value (integer or real) into a string in ST. For example, when A = 2.5E4, the STR (A: 10, ST) will make the value of the ST '25000'.

VAL (ST, VAR, CODE); // converts string expressions to a corresponding integer or real value, stored in VAR. St must be a string representing a value and complies with the rules of the numerical constant. During the conversion process, if an error is not detected, the variable code is set to 0, otherwise it is positioned as the first error character. For example, st: = 25.4e3, X is a real variable, the VAL (ST, X, CODE) will make the X value of 25400, the Code value is 0.

Copy (st.pos.num); // Returns a substring containing Num (integer) characters at a position POS (integer) in the ST string. If the POS is greater than the length of the ST string, it will return an empty string. If POS is outside 255, it will cause an error. For example, st: = 'brian', then COPY (ST, 2, 2) returns 'ri'.

Concat (ST1, ST2, ST3 ..., STN); // Connect all the strings indicated by all the variables, and returns the connected value. If the length 255 of the result will generate an operation error. For example, St1: = 'brian', ST2: = '', ST3: = 'WILFRED', then CONCAT (ST1, ST2, ST3) returns 'Brian Wilfred'.

Length (ST); // Returns the length of the string expression ST. For example, St: = 'brian', the longth (ST) returns 5.

POS (OBJ, TARGET); // Returns the first appearance of the string OBJ at the target string Target, if the target does not match the string, the return value of the POS function is 0. For example, Target: = 'Brian Wilfred', the return value of POS ('WIL', TARGET) is 7, and the return value of POS ('Hubet', Target) is 0.

◇ [Delphi] About Processing 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] About 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: (112) - B (123) A-Z: (65) - A (90)

0-9: (48) - (57)

◇ [Delphi] preliminary judgment program native language

DOS Tip of Delphi Software: This Program Must Be Run Under Win32.

VC software DOS Tips: This Program Cannot Be Run in Dos Mode.

◇ [Delphi] Operation Cookie

Response.cookies ("name"). Domain: = '

http://www.086net.com ';

With response.cookies.add do

Begin

Name: = 'Username';

Value: = 'Username';

end

◇ [Delphi] Added to the document menu connection

Uses shellapi, shlobj;

ShaddtoreCentDocs (Shard_Path, Pchar (FilePath)); // Increase connection

ShaddtoreCentDocs (Shard_Path, NIL); // Clear

◇ [Miscellaneous] Backup Intelligent ABC Input French Word Library

Windows / System / User.Rem

Windows / System / TMMR.Rem

◇ [Delphi] Judging the mouse button

IF getasynckeystate (vk_lbutton) <> 0 THEN ... / / left button

IF getasynckeystate (vk_mbutton) <> 0 THEN ... / / middle key

IF getasynckeystate (vk_rbutton) <> 0 the ... // Right button

◇ [Delphi] Set the maximum display of the form

ONFORMCREATE event

Self.width: = screen.width;

Self.height: = screen.height;

◇ [Delphi] button accepts news

Treatment in the oncreate event: 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] hidden shared folder

Sharing Effect: Access, but not visible (in resource management, network neighbors)

Take a shared name: Direction $

Access: // computer / Dirction /

Article from: Original reference admission address: http://www.zhangjian.net/trackback.asp?tbid=108

转载请注明原文地址:https://www.9cbs.com/read-131556.html

New Post(0)