![]() |
A structure tree showing organised components. |
This is a point that cannot be emphasised enough. In order to understand your own code and form layout, you must have a good idea of what everything is, where it is and what it does.The first step to making your code easier is using the basic naming convention in which each component gets a 3 letter name followed by a description. For instance Label = lbl; edit = edt; panel = pnl; checkbox = cbx; radiogroup = rgp; button = btn; timer = tmr; bitMapButton = bmb et cetera.
The description will normally be along the lines of input, output or explaining which input or output where necessary.
This alone makes it easier for you to code and for someone else to help you if you are unable to spot your error.
To truly make a difference in a complex program with many components though, you naming system needs more than just a basic description and 3-letter code, in a complex program it is often useful to know where the component is and to group components accordingly, this is made easier using components like panels and groupboxes, which will add a "branch" to your structure tree (you can see a structure tree on the left, each new colour shows a new level where it "branches" off). You can also simplify what you look at in your structure tree if you have panels and groupboxes by minimising the panel or groupbox. You can see on the left how all the components in panels under tabsheet 2 (2 {tbs2}) are hidden and how all the panels and their components are hidden in tabsheet 3 (3{tbs3}).
As previously stated, sometimes the component description will need more than "input" or "output". Often you will have multiple labels or edits that all serve different functions, and it is useful to give them names that describe exactly what these functions are. If you look at the labels on the left for frmMathLogic -> pgctrl -> 1{tbs1} -> pnl_pg1_Results you see that there are two result labels, One for the number entered and one for whether or not the number is real, differentiating between the two in the name of the label allows you to code faster and more easily as you will not get confused and thus not have to check your form.
It is also important to make your code easy to read and recognise, meaning that your component names have to be easy to read and recognise, stick to one convention for all components of a certain type or location in all your forms ( for example, don't use "output" in one program and then "result" in the next ), and use capital letters and underscore signs ( _ ) where you feel necessary.
When you combine proper naming of components with other useful tips and functions in and for Delphi, you can code a lot faster and more easily. You can understand your code at a glance and can get help if you go wrong as anyone can understand your code if it is neat and self-explanatory.
Thank-you for reading and I hope this proves helpful.
No comments:
Post a Comment