Some primary small notes in Delphi

xiaoxiao2021-03-05  28

Coolbar embeds Toolbar, but Toolbar's button offssenger: Set the BorderStyle of Coolbar's Coolband to Single.

In addition, if you want to display the main menu to Toolbar, just set the toolbar's Menu as the main menu name, and set the autoMerge of the main menu to true.

------------------------------------

Listbox reads the list of lists from the file

ListBox1.Items.LoadFromFile (applfilepath (application.exename) 'aaa.txt');

ListBox1.Items.add (edit1.text); // Added a project

Listbox1.items.savetofile (Application.exename) 'AAA.TXT');

Delete item ListBox1.Items.delete (ListBox1.ItemIndex);

------------------------------------

Judging whether the form has been opened

IF frmpriceinput <> nil dam ..

Note: Sometimes the form has been closed, but not fully released, it is best to add frmprintinput = nil in the close event in the form.

------------------------------------

Turn off MDI sub-window

Add the following code during the onClose event processing of the child window

Action: = CAFREE;

Delphi is specified for an Form's closed behavior, namely:

Canone - Prohibiting Form is closed

Cahide - form is not closed, but is hidden. The hidden Form can still be accessed by the program.

Cafree - Form is closed and the resources are released.

Caminimize - Form is minimized instead of being closed, which is the default shutdown behavior of the MDI sub-window.

------------------------------------

System configuration file * .ini operation

Head to reference inIfiles

1, declared variables

InIfile: tinifile;

2, specify the path

InIfile: = TiniFile.create (applfilepath (application.exename) 'option.ini');

3, read variables, pay attention to the variables, readstring, readinteger ..., etc.

TitleBmpfile: = INIFILE.ReadString ('TitleImage', 'filename', '); //inifile.readstring (' Group Name ", 'Variable', 'Default'

InIfile.Readinteger

InIfile.ReadBool

4, write or modify variables

INIFILE.WRITESTRING ('Title', 'Volume 1', 'Value');

5, release after delivery

InIfile.Free;

------------------------------------

Dynamically read image

Image1.picture.loadfromfile (titlebmpfile);

------------------------------------

FastReport custom functions

1. Define functions on ordinary engineering forms

2, write in the userfunction of the FRREPORT control

IF AnsicompareText ('my_strtormb', name) = 0 thenval: = my_strtormb (frParser.calc (p1));

// my_strtormb is a function name

// If you define multiple functions, you will come more if you can.

This function can be called in the report design view.

------------------------------------

Array is defined

SBH: array [0..9999999, 0..1] of string;

------------------------------------

TreeView usage

// First define item orders and nodes

N: integer;

Node: ttreenode;

Node: = tree1.selected;

IF (node ​​= nil) or (node.stateIndex = -1) THEN EXIT; / / can generally be customly reactive columns STATEINDEX

N: = node.stateIndex;

------------------------------------

Fields [] Returns the field by index, choose the type of return!

FieldByname () returns the field by name, you have to choose the type of returned!

FieldValues ​​[] returns the value of the field by name, the type of automation!

------------------------------------

Call external program method

With Shellexecute, add shellapi in the USES segment, such as:

Shellexecute (Handle, 'Open', 'C: /myApp/myapp.exe', '- s', '', sw_shownormal);

The first parameter is a parent window handle;

The second parameter is open mode (both Open, Print);

The third parameter is the full path of the execution file;

The fourth parameter is the execution file parameter;

The fifth parameter begins to start the initial directory of the execution file;

The sixth parameter is for execution of the file operation (sw_hide, sw_maximize, sw_minimize,

SW_RESTORE, SW_SHOW, SW_SHOWDEFAULT, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED,

SW_SHOWMINNOACTIVE, SW_SHOWNA, SW_SHOWNOACTIVATE, SW_SHOWNORMAL

------------------------------------

Determine if the file exists

IF not fileexists ('db2.mdb.bak') Then ...

------------------------------------

Judgment button

If key = # 13 dam// If the carriage is returned. . .

------------------------------------

drop out

Close window close;

Close program: Application.Terminate;

Exit the event exit;

------------------------------------

Detect whether the software is running

IF getLastError = error_already_exists the ...

------------------------------------

Defining function is written like this

Function isreadOnly (B: Boolean; Colors: tcolor): boolean;

------------------------------------

FastReport prints directly

FRREPORT1.PREPAREREPORT; / / Initializing frReport1.PrintPreparedReport ('1', 1, true, frall); // Print

Preview FRREPORT1.SHOWREPORT;

------------------------------------

Find a browser and enter a site. (Or call Windows programs)

Enter site shellexecute (Handle, Pchar ('Open'), Pchar ('

http://www.devexpress.com/downloads/index.asp '), NIL, NIL, SW_SHOWMAXIMIZED;

Send Mail Shellexecute (Handle, 'Open', Pchar ('Mailto:' Edtemail.Text '? Subject ='), NIL, NIL, SW_SHOW);

------------------------------------

Open file dialog

If OpenPictureDialog.execute THEN

------------------------------------

Call the help file

Application.helpfile: = '../../help/ebars.hlp';

------------------------------------

Open window

TFORM1.CREATE (Self) .ShowModal;

------------------------------------

Take the path to the current execution program

FPATH: = extractFilePath (Application.exename);

or

Filename: = ExtractFilePath (paramstr (0)) '/ MDB / electronic address book. MDB'

------------------------------------

Current path

GetCurrentdir

------------------------------------

Determine the current mouse in a location (tag)

Case Tcomponent (Sender) .tag of

0: Begin

...

LbbarbackGroud.caption: = scustomImage;

END;

1: Begin

...

LbbarbackGroud.caption: = scustomImage;

END;

2: Begin

...

LbbarbackGroud.caption: = scustomImage;

END;

------------------------------------

Database Connectivity

1. Create an Adoconnection control, named conn

2. Create an adodataset control, named DS

Then you can connect and execute the SQL query with the following statement (this example is the Access database, with a password).

Conn.connectionstring: = 'provider = microsoft.jet.OLEDb.4.0; data source =' getcurrentdir '/ data / pn.mdb; persist security info = false; Jet OLEDB: Database Password = 80513';

CONN.CONNECTED: = TRUE;

DS.Active: = false;

Ds.comMandtext: = 'SELECT Visit Date, Visit Time, Visit Customer, Visit Location, Talk Content from KHBF Order by Visit Date Desc'; Ds.Active: = TRUE;

------------------------------------

AdodataSet1.State's usage

IF adodataset1.state in [dsedit, dsinsert] THEN

AdoDataSet1.post;

------------------------------------

Differences between AdoQuery.open and AdoQuery.execsql

For storage, such as insert can only use execsql

------------------------------------

------------------------------------

------------------------------------

------------------------------------

Enter the cursor to another input box

If key = # 13 THEN

CMB_Name.Setfocus;

------------------------------------

Play sound

Playsound ('c: /windows/media/start.wav' ,0 ,snd_async);

------------------------------------

List box Listbox Add Item

CMB_Name.Items.Add (adotable1.fieldvalues ​​['account']);

------------------------------------

ListView usage

Listview.selected: = listview.Items [0];

Listview.selected.focused: = true;

Listview.selected.makevisible (false);

Listview.selected.index

Listview.Items.count

ListView.items.delete (3) // Delete the third item

ListView.Items.add.caption: = 'dddddddd'; // Add a project

Listview.items.beginupdate;

ListView.Items.Endupdate

Listview.canvas.font.color: = CLGRAYTEXT;

If listview.selected <> nil.. . . . .

/ / Add project to listView

First define

Var ITM: TLISTITEM;

then

Listview.Items.clear;

ITM: = listview.Items.add;

Itm.imageIndex: = 5;

itm.caption: = msg.subject;

Itm.subitems.add ('aaaaa');

Itm.subitems.Add ('ffffff');

Itm.subitems.Add ('ffdfdfdf');

Itm.Subitems.Add ('oooo');

------------------------------------

Method for static calling DLL

Parameter

Procedure Createsmsms (TEXT: PCHAR); STDCALL; External 'SMSLIB.DLL'

Have no parameters

PROCEDURE CREATESMS; STDCALL; External 'SMSLIB.DLL';

------------------------------------ Determine, cancel the dialog

IF Application.MessageBox ('Really exit?', 'Tip', MB_OKCANCEL) = iDOK TEN

Application.Terminate; // Terminate is the termination program

ShowMessage ('Please select the class' to modify "); // This is a simple display prompt box

MessageBox (self.handle, 'price input is not legal!', 'prompt', MB_OK or MB_ICONASTERISK);

------------------------------------

Steps to call the form

Quickly reference the unit of the form, then create a form, and finally displayed.

example 1:

Use uxsgl;

Application.createform (TFMXSGL, FMXSGL);

FMXSGL.ShowModal;

Example 2:

FRM_LENDDETAIL: = TFRM_LENDDETAIL.CREATE (Self);

Try

FRM_LENDDETAIL.SHOWMODAL;

Finally

FRM_LENDDETAIL.FREE;

END;

------------------------------------

Database query

Set up the data source first, then add a TadoQuery

AdoQuery1.sql.clear;

AdoQuery1.close;

AdoQuery1.sql.add ('select * from tkcb order by ckcb_kh');

AdoQuery1.open;

AAA = AdoQuery1.fieldVALUES ['CKCB_KC']; // Remove the value of the current record a certain field

AdoQuery1.next; // Next record

AdoQuery1.close; // Close Query

------------------------------------

Judgment keyboard input character-chr (13) is a carriage return

IF key = chr (13) THEN

Bitbtn1.setfocus;

------------------------------------

Time format

Lbltime.caption: = formatdatetime ('YYYYMMDD HH: NN: SS', NOW);

------------------------------------

Add addition to table data

DMD is the data module TBL_ZGDB is a table name

With dmd.tbl_zgdb do begin

Append;

FieldValues ​​['Hyzh']: = EDT_HYZH.TEXT;

FieldValues ​​['XM']: = EDT_XM.TEXT;

FieldValues ​​['XB']: = EDT_XB.TEXT;

FieldValues ​​['DW']: = EDT_DW.TEXT;

FieldValues ​​['zzmm']: = zzmm;

FieldValues ​​['Csny']: = Trim (EDT_CSNY.TEXT);

FieldValues ​​['gzsj']: = edt_gzsj.text;

FieldValues ​​['DBLB']: = DBLB;

FieldValues ​​['ZCLB']: = ZCLB;

FieldValues ​​['XL']: = XL;

FieldValues ​​['BZ']: = EDT_BZ.TEXT; POST;

CLOSE;

END;

------------------------------------

List box option value

Edit1.Text: = listbox1.items.strings [listbox1.itemindex];

------------------------------------

Delphi keyboard button

Usage: if Key = chr (vk_return) Then ...

Constant name hexadecimal value decimal value correspondence button

VK_LBUTTON 01 1 left mouse

VK_RBUTTON 02 2 Mouse Right

VK-CANCEL 03 3 Contol-Break Execution

VK_MBUTTON 04 4 Middle key (three button mouse)

VK_BACK 08 8 Backspace

VK_TAB 09 9 Tab

VK_CLEAR 0C 12 CLEAR button

VK_RETURN 0D 13 ENTER

VK_SHIFT 10 16 Shift Key

VK_CONTROL 11 17 CTRL

VK_MENU 12 18 Alt key

VK_PAUSE 13 19 PAUSE button

VK_Capital 14 20 Caps LOCK

VK_ESCAPE 1B 27 ESE button

VK_SPACE 20 32 SpaceBar

VK_PRIOR 21 33 Page Up

VK_NEXT 22 34 Page DOMW

VK_END 23 35 END button

VK_HOME 24 36 HOME button

VK_LEFT 25 37 LEFT Arrow button (←)

VK_UP 26 38 UP Arrow button (↑)

VK_RIGHT 27 39 Right Arrow button (→)

VK_DOWN 28 40 DOWN Arrow button (↓)

VK_SELECT 29 41 SELECT

VK_EXECUTE 2B 43 EXECUTE button

VK_SNAPSHOT 2C 44 Print Screen

VK_INSERT 2D 45 INS button

VK_DELETE 2E 46 DEL key

VK_HELP 2F 47 Help

VK_0 30 48 0

VK_1 31 49 1

VK_2 32 50 2

VK_3 33 51 3 key

VK_4 34 52 4

VK_5 35 53 5

VK_6 36 54 6 key

VK_7 37 55 7

VK_8 38 56 8 key

VK_9 39 57 9

VK_A 41 65 A

VK_B 42 66 B

VK_C 43 67 C button

VK_D 44 68 D key

VK_E 45 69 E key

VK_F 46 70 F

VK_G 47 71 G key

VK_H 48 72 H

VK_I 49 73 I key

VK_J 4A 74 J key

VK_K 4B 75 K

VK_L 4C 76 L

VK_M 4D 77 M key

VK_N 4E 78 N key

VK_O 4F 79 O key

VK_P 50 80 p

VK_Q 51 81 Q key

VK_R 52 82 R key

VK_S 53 83 S key

VK_T 54 84 T key

VK_U 55 85 U key

VK_V 56 86 V key

VK_W 57 87 W key

VK_X 58 88 X

VK_Y 59 89 Y key

VK_BZ 5A 90 Z button

VK_NUMPAD0 60 96 Number 2 Key

VK_NUMPAD1 61 97 Number 1 button

VK_NUMPAD2 62 98 Number 2

VK_NUMPAD3 63 99 Number 2

VK_NUMPAD4 64 100 Number 2

VK_NUMPAD5 65 101 Number 5

VK_NUMPAD6 66 102 Number 2

VK_NUMPAD7 67 103 Number 7 key vk_numpad8 68 104 Number key 8 key

VK_NUMPAD9 69 105 Number Key 9 Key

VK_MULTIPLY 6A 106 *

VK_ADD 6B 107 button

VK_SEPARATOR 6C 108 Separator

VK_SUBTRACT 6D 109 - button

VK_DECIMAL 6E 110. Key

VK_DIVIDE 6F 111 key

VK_F1 70 112 F1 key

VK_F2 71 113 F2 key

VK_F3 72 114 F3 key

VK_F4 73 115 F4 key

VK_F5 74 116 F5

VK_F6 75 117 F6 key

VK_F7 76 118 F7 key

VK_F8 77 119 F8 key

VK_F9 78 120 F9 key

VK_F10 79 121 F10

VK_F11 7A 122 F11 Key

VK_F12 7B 123 F12 key

VK_NUMLOCK 90 144 NUM LOCK button

VK_SCROLL 91 145 SCROLL LOCK button

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

New Post(0)