Quick design of Delphi (programming section)

zhaozj2021-02-16  69

All code involved in this article is in WinNT 4, and Delphi4 C / S is correct.

Since Delphi uses a real fully object-to-object method, the world's fastest compiler and leading database technology, especially her completely compatible with Windows API, excellent code automatically generates ... People have seen, in short In the past few years, Delphi has standfined in many development tools! It is Delphi's excellent quality, so that the programmer can develop a special professional use software in a short period of time, but the work is quite small!

The so-called let's us make better! How should we make full use of Delphi's advantages to make programming programs more quickly?

First, make full use of code full sharing (lounged):

The purpose of doing this is not only for "lazy", which is also a way to optimize the program code. Of course, the first thing to consider is to be shared (this is very simple, see if it is included in the drop collection collection of the event), followed by whether there is "trouble" after sharing, because it is the first step, It is necessary to pursue optimization if it is correct.

For example: We give a confirmation message before the user deletes data:

Procedure TFORM1.TABLE1BEFOREDELETE (DataSet: TDataSet);

Begin

// Confirm Delete Record

If MessageBox (Handle, 'does delete the current record?', 'confirm', MB_ICONQUESTION MB_YESNO) = IDNO THEN

Abort;

END;

So, you only want to let users confirm before deleting data records, you can share this code in the TDataSet.beforcete, Table2 BeforeDelete, Table3 BeforeDelete .... Good luck will not be every day, there is no such direct, simple ...

Second, make full use of Delphi's forced conversion: "AS" words are not only used in English, but also in Delphi! When we want to share the code for several "same type" components, we can play her huge role: we only need to write code for one of the components. For example, if you want a group of text edit boxes to get the input focus, the background color changes to a brown color, and the focus is the recovery system color, we can share the code so you can share the code (let each text edit box): Procedure TForm1.edit1ENTER (Sender: TOBJECT); Begin (Sender as tedit) .COLOR: = CLTEAL; // Get input focus END; procedure tform1.edit1exit (sender: TOBJECT); Begin (Sender as tedit) .color: = CLWindow; // Lost Enter the focus end; three, inconspicuous TAG properties: The above example seems to be a bit too special, what should I do if I do only some of the components? Take the above as an example, for example, there are two text input boxes to enter numbers, for reference users, the color changes to blue, but I still don't want to write code separately for each component. To resolve this problem, you can use the tag properties of the component, first assign non-zero, unequal TAGs to be specifically processed, unqualified TAG (must not explain whether the TAG value is equal, you can master it yourself); then write code as follows, Sharing can still be implemented: Procedure TFORM1.EDIT1ENTER (Sender: TOBJECT); Begincase (Sender as tedit) .tag of10, 20: (sender as tedit) .COLOR: = CLBLUE // Enter a text box Else (Sender As Tedit) ) .COLOR: = CLTEAL; // The rest; four, make full use of Delphi's CodeInsight technology: (The following speech assumes that under the default condition of Delphi) 1, use the SELF keyword: Maybe someone thinks me wrong! In fact, here you have to introduce you to the author (because of the less than a child) "trick". In some cases, we may notify the exact name of the component (name), then if you return to the form table to confirm it, (most friends should be like this), there is a bit too sorry, this If you use the self, you can use the self, because Self is explicitly referenced in Delphi, and therefore, we can enter Self and add a comma to this to activate Delphi's code completion, at which time the system will immediately Show you a drop-down list that contains all components and form itself attributes, you can select the desired component from it. This way, avoid this workload of the back-to-back form form. 2, use code completion: We now have no need to let yourself remember too much parameter details, because there is a Delphi code makeup function. Before the specific explanation, there is a point, and the default shortcuts of Delphi will conflict with some of the shortcuts we have used (such as Ctrl Space, turn off the shortcut conflict of the Chinese character input method), So please solve this problem first.

Of course, Code Completion is usually automatically activated, but don't think that there is all the best, I think this technology of Delphi should learn to VB. How can this speech? For example: When you enter strat1. After Delphi does not automatically display the properties of Edit1, you will use Ctrl Space to activate the Code Completion, especially when nest is very deep, Delphi seems to be confused. .3, use code parameters: The activation shortcut is Ctrl Shift Space. This feature is also Delphi Automatic implementation, as described above, when we come back, the cursor is removed, this function is also It will disappear, when we need to confirm the specific parameters of this function, you can open .4, use the code template: this technology once again reflects the engineers of the Inprise Delphi Development Group. And the noble product virtue of the users! (Just I don't want to hear anyone who is smashed by Microsoft) Activation shortcut is Ctrl J. This feature implementation mechanism is similar to the code filling, but she is not automatic, Of course, the most exciting side is that the user can define its template. For a template defined by the author: Fast -> "msg"; code -> "" messageboxMessageBox (Handle, '|', ', MB_ICON ... MB _...); ", just one input MSG then press Ctrl J" stand out ", and put the cursor to the place I added, it is hard! Note: If you define it for yourself Many cute templates must not be lost, you may wish to back up the Delphi32.dci file under the Delphi4 / bin directory, reinstall the Delphi, you can overwrite this file. Five, you can lazy when you are lazy: This topic should not write Here, but still can't help ... 1, it is not necessary to use the object observation directly to set up and do not affect the process normally run. It is not necessary to write code: Because this topic involves facing too wide, only one example is shown: It is necessary to develop automatic prompts on the status bar in Delphi4, and there is no need to "harsh" condition, we don't have to define a process (showmyhint (...), then in the program initialized Assign her to Tapplication's onhin event. Because just set the autohint attribute of the status bar! Of course, she seems to only display on the first Panel (this is not too "harsh" condition). Of course, blame me, some friends don't know that Delphi's Hint property consists of two parts. It is not a sense of speaking. I am interested, please go to the author's personal homepage www.zg169.net/~delphiok (just opened There are still few things in things).

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

New Post(0)