"Mastering Delphi6" learning notes three

zhaozj2021-02-11  236

Some shortcuts in the code editor / form designer / Object Inspector

Press Ctrl E in the code editor to activate Increment Search. This avoids the cumbersome steps of selecting Search-> Find from the menu.

Select one or a few lines of text, then press CTRL Shift I to increase the amount of reducing of these lines; Ctrl Shift U reducing indentation. The retracted distance depends on the Auto Indent settings in Editor Options.

Select some text, press CTRL O U (hold Ctrl Press, press O, press U), will change the case in the selected text. Ctrl K E will select all text to turn lowercase; Ctrl K F becomes all uppercase.

When working in Form Designer, select a component, press the Ctrl and the arrow keys to drag it will be able to fine tune its location without aligning the grid (Snap to grid is only valid for the mouse operation.), If Shift Press together with Ctrl, then the component movement will automatically be aligned to the grid.

An important improvement in Object Inspector is the Object Inspector supports component Reference's in-place expanding. For example, Label's FocusControl will mark with brown, indicating that it is a special attribute to another component. Set FOCUSControl to a component, a small number appears in front of FocusControl, allowing you to edit the properties of this component directly without selecting it.

In addition, press and hold the CTRL button on the attribute value of FocusControl, and will jump to the component pointed to by FocusControl (eg Edit1).

CTRL O O will add all compiler settings in front of the unit.

About Conditions in Delphi

Delphi supports concepts similar to C conditional compilation. Its method is also very simple. However, because the frequency of use is relatively small, some people are still less familiar with it, and Delphi and C have a little difference in grammar compilation, so it is necessary to simply.

The simplest form is like this:

{$ IFDEF Debug}

ShowMessage ('Display A Debug Message!');

{$ ENDIF}

In Delphi 6, an enhanced form of IFDEF is supported: IF. IF can not only test symbol definition, but also allow test constants (including constant expressions such as SizeOf, PRED, SUCC, etc.), but also test combination conditions. Below is an example:

Const

DebugControl = 3;

{If defined (debugControl> = 3)}

ShowMessage ('High Debug Level!');

{$ Ifend}

Friends who are familiar with C should pay attention to the end of the test ends, Endif and IFEND, respectively, which are used to correspond to IFDEF (also including IFNDEF) and IF, can not be mixed, otherwise it will get an error message, this is Object Pascal And a different point of C .

More complex forms are as follows:

{$ IFDEF ...}

...

{$ Elseif ...}

...

{$ Else}

...

{$ IFEND} Condition Compilation in Delphi 6 is relatively important, because Delphi 6 supports two different libraries of VCL and CLX, respectively. Thus in the VCL and some places, you can see a statement like this:

{$ IF defined (CLX)}

...

{$ Ifend}

Some conditional compilation symbols are predefined in Delphi. Some of them are more important:

1.Ver140

This definition suggests that the real version number of Delphi 6.0 in the Borland Pascal product family is 14.0. VER130 is defined in Delphi 5. Apply as follows:

{$ IFDEF VER140}

ShowMessage ('is delphi 6!')

{$ ENDIF}

{$ IFDEF VER130}

ShowMessage ('is delphi 5!')

{$ ENDIF}

2. Mswindows / Linux / Win32

The previous two definitions are obviously prepared for cross-platform programming. As for win32, you can also use it as a msWindows; however, it is reserved for the compatibility of Delphi 1.0 / 2.0, unless you have these two versions of applications need to be maintained, otherwise it should never be again use it. Of course, on the future 64-bit platform, Win64 definition will appear; if you are a very avant-garde programmer, you can even write this code now:

{$ IFDEF WIN64}

...

{$ ENDIF}

This is not meaningful, because Delphi is currently providing a good support for the INT64 type.

3. Console

Indicates this is a console application.

4. BCB

If you need to compile the .pas file in C Builder, you may need it in some cases.

5. ConditionaLexpressions

$ IF is not supported in Delphi 5 and previous versions. However, with the following way, whether it can be compiled without problems in Delphi 5 or Delphi 6:

{$ IFDEF CONDitionAlExpressions}

{$ IF defined (debug)}

ShowMessage ('Debug!');

{$ Ifend}

{$ ENDIF}

The author of Mastering Delphi 6 gave us two advice:

1. Conditional compilation is useful, as long as it is used, it can provide considerable flexibility for the program. However, it should only be used when you do need to use them; otherwise, it is easy to make the code difficult to read, and may cause trouble to the debugger.

2. When you change some definitions, the compiler does not necessarily distinguish which code needs to be recompiled. If you change these definitions, the running situation of the program becomes a bit strange, then select Build All.

Delphi 6 introduces a new indicator: Platform. Because Delphi 6 supports cross-platform programming, but when you need to write some platform-specific code, it is best to use Platform to declare.

Here is an example:

VAR

Wininteger: Integer = 3000 Platform;

PROCEDURE TEST; Platform;

Begin

BEEP;

END;

Type

WinClass = Class

x: integer;

End platform;

The position of Platform appears in the CLASS statement seems a bit strange, it doesn't matter, know it, anyway, we generally don't use it (but when you need it, you have to have something to do). If you must get to the bottom of the words, "Mastering Delphi 6" author of this there is a brief explanation:. The position of semicolons for hint directives can be quite confusing at first The rule is that a hint directive must appear before the semicolon following the symbol it modifies. But a proce-dure, function, or unit header declaration can be followed only by reserved words, so its hint directive can appear following the semicolon. A type, variable, or constant declaration can be followed by another identifier, so ., singapore, singapore, singapore, singapore, singapore

About deprecated indicator

This section of "Mastering Delphi 6" about deprecated seems to be a bit weird, the text is very shallow, but I have seen it three times and not fully figure out what is said. Record here first, later optimistic.

The deprecated directive works in a similar way to the platform directive; the only real differences are that it is used in a different context and produces a different compiler warning.The role of deprecated is to mark dentifiers that are still part of the system for compatibility Reasons, But Either Are Going to Be Removed in The Future or Expose You To Risks of Incompatibility.this Symbol IS Used Spaingly IN The Delphi Library.

Another quite useful keyword in Delphi 6 is $ Message. You can use it to remind you that anything worth noting in the program, such as the following example:

{$ Message 'This has not been completed, remember to finish the next time! '}

Of course, use to-do list can also complete similar work, and to-do list is more perfect; however, $ Message is more than to-do list, and the compiler will meet each compiler. Remind you, so it is not easy to forget; relatively, not every programmer will often look at to-do list.

$ Message is also similar to #pragma message in Visual C . However, in the Message window of Delphi 6, you can jump to the corresponding definitions in the source file, but this is not available in Visual C . Postscript: "Mastering Delphi 6" now sees pages 65 (1071 pages), that is, the long qualifying is the first step. This book is still very well understood by this place (it is basically no need to use Jinshan word), but the later content is hard. It should be honest to admit that my English level is still very poor, and read the original book is full of hard work. Teacher Cai Xueli said that he must be sure when he started reading foreign language, and the hand must have e-dictionary, read more, and now it is very casual as a novel. Whether it is still lying, Does not affect reading. When can I achieve this realm?

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

New Post(0)