Delphi one sentence help end

zhaozj2021-02-16  57

1. Generate a random password (should be useful)

Function createpass: string;

Const

MAX_LEN = 10;

VAR

i: integer;

String;

Begin

Randomize;

S: = 'AbcdefghijklmnopqrStuvwxyz' 'AbcdefghijklmnopqrStuvwxyz' '0123456789';

Result: = '';

For i: = 0 to max_len-1 do

Begin

Result: = Result S [Random (Length (S) -1) 1];

END;

END;

2. Decimal digital conversion into a Rome number

Function Dectoroman (IDECIMAL: LongInt): String;

Const

Aromans: array [1..13] of string = ('i', 'iv', 'v', 'ix', 'x', 'XL', 'L', 'XC',

'C', 'cd', 'd', 'cm', 'm');

Arabics: array [1..13] of integer = (1, 4, 5, 9, 10, 40, 50, 90, 100, 400,

500, 900, 1000);

VAR

i: integer;

Begin

Result: = '';

For i: = 13 downto 1 do

While (Idecimal> = Arabics [i]) DO

Begin

Idecimal: = Idecimal - Aarabics [i];

Result: = Result Aromans [i];

END;

END;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

SHOWMESSAGE (Dectoroman (5));

END;

3. Format integer display

Use the formatfloat function to solve your many problems. For example, format 1200000 to 1,200,000 output

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

VAR

i: integer;

String;

Begin

I: = 1200000;

s: = formatfloat ('#, 0', i);

ShowMessage (s);

END;

4. Judging whether the serial port has received the data using the ClearcomMerror function, the Cbinque in the Tcomstat structure can help achieve judgment.

5. RGB Color Convert to TColor Class

Function RGBTOCOLOR (R, G, B: byte): tcolor;

Begin

Result: = b shl 16 or

G shl 8 or

R;

END;

6. Convert TCOLOR to RGB value

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

VAR

Color: Tcolor;

R, g, b: integer;

Begin

Color: = CLBLACK;

R: = Color and $ ff;

G: = (Color and $ FF00) SHR 8;

B: = (Color and $ FF0000) SHR 16; ShowMessage (INTTOSTR (R));

ShowMessage (INTTOSTR (G));

ShowMessage (INTTOSTR (B));

END;

7. Browse Computer Dialog

Uses shlobj;

Function BrowseForComputer (Const Winrandle: Thandle; Const Title: String): String;

VAR

Browseinfo: TBROWSEINFO;

Idroot: PitemidList;

PATH: Array [0..max_path] of char;

Begin

ShgetspecialFolderLocation (WinHandle, CSIDL_NETWORK, Idroot);

ZeromeMory (@BrowseInfo, SIZEOF (TBROWSEINFO);

ZeromeMory (@Path, Max_Path);

Browseinfo.hwndowner: = WinHandle;

Browseinfo.pidlroot: = idRoot

Browseinfo.lpsztitle: = pchar (title);

Browseinfo.pszdisplayName: = @Path;

Browseinfo.ulflags: = Bif_BrowseForComputer;

SHBROWSEFORFOLDER (BrowseInfo);

END;

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

New Post(0)