== System application articles == a. Delphi has a lot of common controls, such as Delphi5, and this year's Delphi6 is 1.5 times the Delphi5. Such a multi-control is not all displayed on the resolution of 1024 * 768, and every time you have to press the two small buttons to display more panels, it is very inconvenient! However, by adding the following registry key value, the component panel can be automatically expanded: [HKEY_CURRENT_USER / SOFTRAS] "AutoPalettelect" = "1" (Note: X.0 means your Delphi The version number; if there is no EXTRAS primary key, new, the same below)
B. Every time you create a new form, then set your font, size ... is really trouble! Then add the following key value, let the system automatically set: [HKEY_CURRENT_USER / SOFTWARE / BORLAND / DELPHI / X.0 / FORMDESIGN] "DefaultFont" = "Song, 9, _" (Note: _ Expression space, You can also replace it with bold (bold), etc.)
C. Customize your work environment and make it more suitable for yourself. · Set the toolbar. Right-click the toolbar of Delphi, select Customize, then select the needed button to drag it to the tool, do not drag out. I usually use: the Open, Open Project, Save, Save All, Undo, Redo; Debug toolbar under the Standard toolbar, Save Current Desktop, SAVE CURRENT DESKTOP, SET Debug under the Desktop toolbar Desktop; Component Palette toolbar. · Set the window layout. In order to be able to follow the efficient writing programs, it is important to arrange each window. The common window has: Object Inspector, Project Manager (View | Project Manager), Watch List (RUN | Add Watch ...), specific parking position is shown in Figure 1.
After setting various forms, press the Save Current Desktop button on the Desktop toolbar. • Set the display color. Let the color of the code more in line with your habits, which is conducive to writing the clear thinking. Tools | Editor Options Opens Editor Properties, select the Color tab, set the code color. Just explain several common: Whitespace: blank, ie background; comment: comment; reserved word: reserved word; string: string; number: number; Execution Point: The current line being executed (ie, F7) The row arrived); Enabled Break: breakpoint; error line: Error occurred;
D. Mastering some shortcuts in Delphi programming, you can greatly improve efficiency, you will not let you feel bored because of too many boring settings, now I don't have to use these shortcuts, I will not adapt to this program! I will introduce a few shortcuts I often use: ESC: Select the container of the currently selected component (usually Panel, GroupBox or Form, etc.); Ctrl arrow keys: Move the selected component; Ctrl Shift arrow keys: Move the selected component (similar to the effect when SHIFT is used in Fireworks); SHIFT arrow keys: Adjust the size of the selected components, one pixel; SHIFT selection component: Hold down the Shift key to use The mouse click the component, you can select multiple components at the same time; Ctrl mouse left mouse: Use another function (such as a custom process), press and hold the CTRL at this call to change the time when the mouse is moved A similar hyperlink format, the mouse click directly to the implementation of the call called. This feature I have used up, let me find a module very convenient! Ctrl Shift C: Declare a method in an object, then put the cursor to it, press Ctrl Shift C to create a basic framework for his implementation, such as tform1 = class (tform) Private {private declarations} PROCED {public declarations}} PROCEDURE MINE; END; put the cursor to Procedure Mine, press Ctrl Shift C, the following segment will be automatically inserted into the unit: Procedure TFORM1.MINE; BeGund;
== Form operation ===
In a program with multiple forms, Delphi is created by default all when the program is started (just hide, only a main form), which, the form that is temporarily unnecessarily started to occupy many memory space. So we need to transfer those that temporarily don't start from "AUTO-CREATE FORMS" to "AUTO-CREATE FORMS" under the Forms tab of menu Project | Options .... In this way, the creation and release of these forms requires a code to be implemented. A. Two comparisons for creating a form method. For these non-automatic created forms, we must create it before Show, create it. Such as form2.creat (self) and form2.create (application), what is the difference between them? In fact, the difference is not big, but if Owner is a window or control, it will be released when its Owner is released. The key difference is who managed the resource of the form. Create with the first method, the resource of the form is managed by the programmer; created with the second method, the resource of the form is managed by Application.
B. Several forms of forms of forms. Since it is in order to save memory, then use the form that is "moving out" memory. Here I lists several big similar methods: (1) procedure tform1.button1click (sender: TOBJECT); begin ... if Form2 = nil thenform2: = tForm2.create (Application); form2.showmodal; .. .... End; Procedure TFORM2.CLOSE (Sender: Tobject; VAR Action: tclosection); Begin ModalResult: = mrnone; action: = cafree; Form2: = nil; end; (2) Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT Begin if not assigned (Form2) Then Begin Application.createform (TFORM2, FORM2); Try Form2.ShowModal; Final2.ShowModal; FORM2: = NIL; End; end else form2.showmodal; end; (3) Procedure TFORM2 .Button1Click (Sender: TOBJECT); Begin Form2.Close; Form2.Release;
== Control usage ==
A. The famous RXLIB control package is written by three Russian masters, very outstanding! However, there are too many content, it is not easy to use it. I will take RXRICHEDIT to say a few points. Many people ask how to install RXLIB, it seems to be a bit complicated, huh, huh, so I am also in the way: Run RXINST.EXE to install RXLIB first to / program files / borland / delphi5 (or 6) / RX folder, then open Delphi, choose File / Open ..., turn RXCTL5.DPK, RXDB5.DPK, RXBDE5.DPK, press Compile, continue to open: dclRx5.dpk, dclrxdb5.dpk and dclrxbd5.dpk, press Compile After pressing install :-) allowobjects properties. Win98 is defameted to true, and there is no problem in the right-click menu, but the shortcut menu will appear twice when set to false; if Win2000 is set to true, the right-click menu cannot be popped up, while False shows normal. So, for the system compatibility, you need to judge the current OS version: procedure tformmain.formcreate (sender: TOBJECT); VAR OSVI: OsversionInfo; ... begin osvi.dwosveionsInfosize: = sizeof (OsversionInfo); getVersionex (OSVI) Case Osvi.dwplatformID of 1: RxRichEdit1.allowobjects: = true; 2: rxrichedit1.allowobjects: = false; end; ....... End; but I don't know why this property will have such a problem, but also hope Pointer. • OnurlClick event. RxRicHEdit has automatically transferred web address to hyperlink format, but the specific behavior still wants to write code itself, otherwise these addresses have an empty shell: procedure tformmain.rxrichedit1urlclick (Sender: Tobject; const URLText: String; button: TMOUSEBUTTON; begin if button = mbleft the shellexecute (Handle, NIL, PCHAR (URLTEXT), NIL, NIL, SW_SHOW); End; C. Display the prompt text of each control on the status line. This available Application's OnHint event, but because Application is an inability object, you can use the following method: ... public procedure displayHint (sender: TOBJECT); // Declare a method for display the prompt text;. .... procedure tform1.displayHint (sender: TOBJECT); // Implement part Begin Statusbar1.SIMpletext: = getlonghint (application.hint);
Procedure TForm1.FormCreate (Sender: TOBJECT); Begin Application.OnHint: = DISPLAYHINT; END; The text and prompt shown in the status bar (that is, the auto-appearing yellow small frame). What should I do if the prompt text in the status bar is more detailed? In fact, as long as the Hint property of the control is written in this: MyHint | It's just a myhint!, You can display the content before "|" to display in the hint box, "|" The following content is displayed in the status bar. . D. Some points in ListView use. The following is an example of two columns of ListView. {→ add one line:} with listview1 do beg, listitem: = items.add; listitem.caption: = 'first column content'; listitem.subitems.add ('second column content'); end; {→ Empty ListView1: ListView1.Items.clear; {→ get the line number of the row currently selected in the line and delete the current line:} for i: = 0 to listview1.items.count-1 do if listview1.items [i] .selected the / /i=listview1.selected.index begin listview1.items.delete (i); // Delete the currently selected line end; {Of course, ListView has an OnsectItem event, which can determine which line selected, assign it with a global variable. → Read a list of a row:} edit1.text: = listview1.items [i] .caption; // read the first column of the first column edit2.text: = listview1.items [i] .subitems.strings [0 ]; // read the second column of the first line Edit3.Text: = listview1.tems [i] .subitems.strings [1]; // Read the third column of the first line {Take the secondary push, you can read the whole column . → Move the focus:} for i: = 0 to listview1.items.count-1 do if (listview1.items [i] .selected) and (i> 0) THEN Begin ListView1.setfocus; listview1.items.Item [i-1] .selected: = true; end; {Already in Delphi6, listView has more ItemIndex properties, so as long as} listView1.setfocus; listview1.itemindex: = 3; {can set the focus. }
== Others ==
☆ In order to optimize the software, it will make it strive to use a dynamic array when used in arrays. In the statement, such as: ARRAY OF STRING, then before using an array, setLength (A, 3) sets the array length of 3, namely A [0], A [1], A [2], this is okay. . When you need to expand an array length, once: Seclength (A, 5), then A [3] and A [4], and the front A [0], A [1], A [2] The value will not be emptied; also, if SECLENGTH (A, 3), only A [0] is left, A [1] and A [2] are automatically cleared. Note: The dynamic array starts from "0", so high (a) = 0 after SetLength (A, 1)! ! Finally, this is no longer used, and the program has not to be exited, so in order to save memory: A: = NIL to release this array, this truly "green environmental protection":) ☆ "How to get the current program Running path "This problem can often be seen in the forum. Indeed, this function is usable from time to time. In fact, there are several functions to achieve this effect: → getCurrentDirectory (): WinAPI functions, specific usage as follows: var mycurrentdir: array [0..144] of char; // Store the current absolute path Begin getCurrentDirectory (Sizeof (mycurrentdir), MyCurrentDir); // get the current absolute path, the resulting form as: C: / WINDOWS / SYSTEM MyCurrentDir: = MyCurrentDir '/ MySoftName.exe'; end; → GetCurrentDir (): GetCurrentDirectory Delphi package after a function usage Simple: mycurrentdir: = getcurrentdir. The final format is like: c: / windows / system is also a function that can directly get the path: extractfilepath (paramstr (0)), extractFilepath (Application.exename), etc.
☆ Shutdown, restart, etc. This is also a question that is often asked, I am also in this way: shutdown: EXITWINDOWSEX (EWX_SHUTDOWN, 32); Restart: EXITWINDOWSEX (EWX_REBOOT, 32); Logout: EXITWINDOWSEX (EWX_Logoff, 32); turn off Power: EXITWINDOWSEX (EWX_Poweroff, 32);
☆ In Delphi, how do you handle "single single quotes" in the program (such as ShowMessage) in addition to # 39 '' 'And' '' '' will have compilation errors. In fact, four single quotes indicate a single quotes, that is, '' '', the second and third indications this is a "'", the first and fourth is indicating this is a character. Oh, very interesting :)
☆ Chinese problem in ShowMessage. The buttons in ShowMessage are e-text, people are very uncomfortable. In fact, through our DIY, you can also make them in Chinese. First, save the current project, then select Project | Languages | Add ..., the Add Language dialog box, select the project you want to Chinese (you can customize folders), Next; choose the last item "Chinese (China) ", Next; next; then appears Translation Manager dialog, select" Chinese (China) | Resource Scripts | Projet1_DRC (This specific to your project file name) ", then right In the list, find the "const_smsgdlogok" item, change its "Chinese (China)", "OK" (original OK), and exit after saving. This, run again, haha, is it a Chinese button! However, this type of information dialog this type is very simple, and some process information can be displayed to the developer during system debugging. But because it is too simple, I recommend not use such dialogs in the official version of the software. Moreover, it is best to use MessageBox instead of SHOWMESSAGE to reduce the size of the software, for example, the same DLL file, using the MersSagebox compiled DLL file size 58K, while ShowMessage has become 301K! ! Above these experience may not be used, but the so-called "book is used to hate less"! No need to say nonsense, everyone drums, hehe :) There is a deficiency, please advise you for your predecessors!