Delphi/BCB/third-party tool usage skills

Source: Internet
Author: User

Delphi/BCB/third-party tool usage skills

Warning excessive use of code skills may reduce code readability and maintainability. The content provided in this post is for technical reference only. Please use it as appropriate.

▲In the Code Editor, press Ctrl and scroll the scroll wheel to scroll a page each time.

▲In the code editor, you can press SHIFT + Ctrl + C to generate implementation code or declaration code for the defined class methods, or complete declaration for the defined attributes.

▲When debugging a program, press Ctrl + F7 to open the evaluate/modify window.
You can enter complex expressions in expresssion, such as tcombobox ($ a483d0 ). items. text or tobject (EDX + $24 ). classname, simple variables can also modify the value in the new value.

▲In the Code Editor, press the Alt key and drag the mouse to select the code by column block. The selected column blocks can also be copied, deleted, pasted, and replaced in blocks.

Do you think the hand cursor that comes with Delphi is ugly? It doesn't matter. One line of code solves the problem:

Screen. cursors [crhandpoint]: = loadcursor (0, idc_hand );
In the oncreate event of the main form, or in the initialization section of any unit.
In the same way, you can replace other uncomfortable default cursors.

▲Press Ctrl + E in the code editor to enter the incremental search status. Enter the text to be searched and start searching from the current cursor.

▲In the IDE Form Designer, you can press SHIFT + direction key to adjust the width and height of all selected controls in pixels, and press Ctrl + to adjust the position.

▲In the IDE Form Designer, if you hold down the Alt key while dragging the control, you can temporarily disable the automatic alignment to grid function.

▲On the main ide window, there is a "desktop" toolbar. The "save current desktop" button can save the currently set desktop layout, "Set debug desktop" allows you to set a saved desktop to the desktop layout used for debugging.

▲If you want to access the protected method or attribute of the class declared by other units, you can define a subclass of this class in this unit and forcibly convert the instance type of the accessed object to the subclass for access. For example:

Type
Tcontrolaccess = Class (tcontrol); // defines a subclass.
...
Tcontrolaccess (acontrol). Click; // forced conversion to subclass to access the protected Method

PS: This method actually breaks the encapsulation principle and is applied only in some special circumstances.

▲Sometimes, we need to modify or add the behaviors or attributes of existing controls in a small amount, but we do not want to write a new control to register it on the component panel or dynamically create it for use, you can use the control with the same name to derive.

In the following simple example, the onpaint event is added to the tpanel:

[Copy to clipboard] Code:
Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, extctrls;

Type

// A subclass is derived from the same class name.
Tpanel = Class (extctrls. tpanel)
Private
Fonpaint: tpolicyevent;
Protected
// Reload a method
Procedure paint; override;
Public
// Define a new event
Property onpaint: tpolicyevent read fonpaint write fonpaint;
End;

Tform1 = Class (tform)
Pnl1: tpanel;
Procedure formcreate (Sender: tobject );
Private
{Private Declarations}
Procedure onpnlpaint (Sender: tobject );
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

{Tpanel}

Procedure tpanel. paint;
Begin
Inherited;
If assigned (fonpaint) then
Fonpaint (Self );
End;

Procedure tform1.formcreate (Sender: tobject );
Begin
// Newly added events can only be dynamically associated at runtime
Pnl1.onpaint: = onpnlpaint;
End;

Procedure tform1.onpnlpaint (Sender: tobject );
Begin
// This sentence can be executed.
Pnl1.canvas. textout (10, 10, 'test ');
End;

End.

Follow the above method.

[Copy to clipboard] Code:
Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, buttons, stdctrls;

Type
Tspeedbutton = Class (tbutton)
Public
Constructor create (aowner: tcomponent); override;
End;

Tform1 = Class (tform)
Speedbutton1: tspeedbutton;
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

{Tspeedbutton}

Constructor tspeedbutton. Create (aowner: tcomponent );
Begin
Inherited create (aowner );
Caption: = 'tspeedbutton to tbutton ';
End;

End.

▲Can't I find a nice icon in a program? No problem. Please refer to the massive free icons here:

Http://findicons.com/

Findicons.com is an icon search engine that helps you find free icons. It has the largest searchable icon library in the world (please let us know where there is a larger icon Library) as well as advanced search filtering and matching algorithms, you can easily find the icons required for each design task.

▲A very practical method for program debugging

When using breakpoint debugging, press Ctrl and then click the variable to modify the variable value.

▲Defer method in go language in Delphi

When implementing a function, if an error occurs in the intermediate step, you need to release the resource and exit the function, which is complicated and error-prone. The author of the Go language is disappointed with the experiences of software development over the past decade. To address this problem, he brought about the defer method, which allows exit wherever in the function, make sure you have the opportunity to clean up.

Program demo_defer;

{$ Apptype console}

Uses
Sysutils,
Coroutineunit; // you can still use this unit... Or in the attachment

Begin
Tproc (Procedure () // This function demonstrates copying the content of a file to another file.
VaR
F1, F2: integer; // two file pointers. The F1 content must be copied to F2.
Begin
F1: = fileopen ('f1 ', fmopenread); // open the F1 File
The defer (Procedure () // defer function saves the Parameter Function and calls it when its function exits.
Begin
Fileclose (F1 );
Writeln ('f1 disabled ');
End );
F2: = fileopen ('F2', fmopenwrite); // open the F2 file again.
If F2 =-1 then begin
Writeln ('f2 open failed ');
Exit; // exit decisively. You do not need to consider the F1 status.
End;
// Copycontent (F1, F2); // start copy (assuming this copy function exists)
Fileclose (F2 );
End )();

Readln;
End.

In the past, when dealing with this situation, you need to determine whether the F2 open fails. If it fails, you need to disable F1 and then exit. If this function is complex, you may forget to close it, with this method, make sure that no matter how many exits you write, the code that closes F1 will be executed.

The actual output result is:
F2 open failed
F1 is disabled

The attachment is in this post.

Http://bbs.cnpack.org/viewthread.php? Tid = 9553 & pid = 23145 & page = 1 & extra = Page % 3d1 # pid23145

▲When declaring a type, if a type keyword is added before the new type name, Delphi will generate an independent rtti for this type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.