Delivery technology in Delphi

zhaozj2021-02-17  34

Delivery technology in Delphi

With the continuous improvement of software technology, the software interface is getting more and more beautiful, and the operation is increasingly convenient.

Looking at the market more professional software, we will find that most of the features of the formal dockers, special elephant tool software, basically or more or less docking.

Naturally, Delphi also supports downtime, and she is closely combined with VCL, and is a big gospel for the vast number of Delphi programmers. Let us save the boring encoding time. Conceive attention to the concept of the core program.

Let us review the structure of the VCL. There is a DockSite property in the TwinControl class. It is whether other controls are allowed to stop in it, there is a Dragkind property in the TControl class, if you want this control To stop on other controls, set the Dragkind property into DKDOCK. It's as simple as it is set up, and a procedure that supports the docking is complete.

Of course, it is just the most basic steps above, there are two steps, we can continue to write code to achieve more complex features.

The general support-stop program can be docked around the main window, that is, the control that can be parked on the edge of the main window is better (as long as it is inherited from TwinControl), usually we all choose TPANEL. In order to facilitate the reader, we can assume that the left side of the main window can be stopped, so put an align property on the main window, which is the Panel of Alleft, named LeftDockPanel, the width is 0, the Docksite property is True, of course our LeftDockPanel should be You can change the size, so put a TSPLitter on the right side, named leftsplitter, the Align property is Alleft. The next step is to stop the control, the general program dock control is a form, so we also build a form, taking the name of the DockableForm, the Dragkind property set into DMAUTOMATIC (Auto Stop).

Now we can run this program, what? Ineffective? The form of docking form is stopped in docking, it will not be seen!

Oh, I almost forgot, Delphi will generate some incident when docked by the form, they are

1. OnDockover (Sender: TOBJECT; Source: TDRAGDOCKOBJECT;

X, Y: integer; state; var accept: boolean;

2. OnDockDrop (Sender: Tobject; Source: TDRAGDOCKOBJECT;

X, Y: integer;

3. OngetsiteInfo (Sender: Tobject; DockClient: tcontrol;

Var InfluenceRect: TRECT; mousepos: tpoint; var Candock: Boolean;

4. OnStartDock (Sender: Tobject) (Sender: TOBJECT)

VAR DragObject: TDRAGDOCKOBJECT);

5. OneundDock (Sender, Target: TOBJECT; X, Y: Integer);

6. Onundock (Sender: Tobject; Client: tcontrol;

NEWTARGET: TwinControl; VAR Allow: Boolean;

Wow, so much, don't worry, let me fine way:

Let's take a look at the first event onDockover is triggered when the DockableForm brushes the parked control (LeftDockPanel). Source contains information about the docking-drag operation, where there is an important attribute is control, which is DockableForm, another important property is DockRect, is the location of the stop; x, y is the position of the mouse, the state of the State has DSDRAGENTER, DSDRAGLEAVE, DSDRAGMOVE, indicating dragging, dragging, dragging; accept whether it agrees to stop. The main role of the onDockover event is to control the preview position of the form, let's add the following code:

Procedure TMAINFORM.LEFTDOCKPANELDOCKOVER (Sender: TOBJECT)

Source: TDRAGDOCKOBJECT; X, Y: Integer; State: TDRAGSTATE

VAR Accept: boolean;

VAR

Arect: TRECT;

Begin

Accept: = source.control is TDOCKLOLM;

IF accept kil

Begin

// Modify the preview stop

Arect.topleft: = LeftDockPanel.ClientToscreen (Point (0, 0));

Arect.bottomright: = LeftDockPanel.Clienttoscreen

Point (Self.ClientWidth Div 3, LeftDockPanel.Height);

Source.dockRect: = all;

END;

END;

Now run the program, when you drag the DockableForm to the left side of the main window, the preview has occurred, which is the range of dotted lines.

how? The form is gone? Of course, we just talked overdockover, not explained in detail, it was the culprit whether I decided to stop the form:

OnDockDrop (Sender: TOBJECT)

Source: TDRAGDOCKOBJECT; X, Y: Integer;

The parameters and onDockover are almost the same, but there are few state: TDRAGSTATE and VAR ACCEPT: BOOLEAN

It happened when there is a docking form that is stopped, and the function is to control the final position of the docked form. The following is added as follows:

Procedure TMAINFORM.LEFTDOCKPANELDOCKDROP (Sender: TOBJECT)

Source: TDRAGDOCKOBJECT; X, Y: Integer;

Begin

LeftdockPanel.width: = ClientWidth Div 3;

Leftsplitter.LIDTH Leftsplitter.width;

END;

Now run the program, wow, success. There is a completely ordered form of Delphi's IDE, which is two horizontal lines, used to drag it out, and a small x in the upper right corner is used to close.

However, the good scene is not long. When we close it, the LeftDockPanel loaded with DockableForm can't restore, or it is a customer area of ​​the main window. What should I do?

Hey, forgot to tell you, in fact, Delphi has long been doing everything for us.

Please open the shutdown of DockableForm, you will find it turns out when you click on the small x closing DockableForm in the upper right corner, which triggers the DockableForm's onclose event, set the width of the LeftDockPanel to 0 in the OnClose event. Procedure TDOCKABLORM.FORMCLOSE (Sender: TOBJECT)

VAR action: tclosection;

Begin

Mainform.LeftDockPanel.width: = 0;

Action: = Cahide;

END;

The above is how to stop on the main window, and the original code is tested. Similarly, we can implement docking functions on the right side of the main window.

By the way, we just introduced OnDockOver and OnDockDrop, forgot to introduce other incidents, let's brief introduction:

3. OngetsiteInfo (Sender: Tobject; DockClient: tcontrol;

Var InfluenceRect: TRECT; mousepos: tpoint; var Candock: Boolean;

This event is triggered when the form moves, so often triggered, the DockClient inside it is TDOCKABLEFORM.

There is a reference parameter called Candock, and the ACCEPT in the onDockover is similar, and it is queried whether it is allowed to stop. Here you can not write, Candock default is true, you can also write Candock: = DockClient is TDockableForm;

4. OnStartDock (Sender: Tobject) (Sender: TOBJECT)

VAR DragObject: TDRAGDOCKOBJECT);

5. OneundDock (Sender, Target: TOBJECT; X, Y: Integer);

6. Onundock (Sender: Tobject; Client: tcontrol;

NEWTARGET: TwinControl; VAR Allow: Boolean;

These three events are useful on the DockableForm, meaning that the stop start, the end of the end, whether it is not stopped (it is dragged out).

OnstartDock and OneundDock are often triggered,

Onundock triggers only when the form is turned into floating

Telling so much, have you been confused? Ok, let me do a summary:

In Delphi, as long as the control inherited from TwinControl is supported (such as the LeftDockPanel), there is a DockSite attribute; all controls inherited from TControl support (as DockableForm above), that is, Dragkind properties Therefore, support that is supported by the parked control supports downtime, and the control of the support is not necessarily supported, the reason is very simple, because TwinControl is inherited in TControl. The onDockover event is a preview location for the control of the form; the onDockdrap event is the final position of the control docked form; OnGetSiteInfo is inquiry if it can be stopped; onstartDock is starting, OneEndDock is ending, Onundock is not stopped (it is dragged out ).

If you want delphi, you can know that Delphi can be stopped between Delphi, and there are many tricks, you can stop, or stopped into pageControl style, two deactivated forms The form can be combined with other deactivated forms to form a tree. Let's introduce this technology: Say here, we have to introduce the CM_DOCKCLIENT message and the TCMDockClient structure.

The CM_DOCKCLIENT message and the TCMDockClient structure correspond to each other, and the structure of TCMDockClient is:

TCMDOCKCLIENT = Packed Record

Msg: cardinal;

Docksource: TDRAGDOCKOBJECT;

Mousepos: TsmallPoint;

Result: Integer;

END;

The DockSource contains information about the dock-drag operation, which has been mentioned before; MousePos is the location of the mouse. CM_DOCKCLIENT events can be captured in docking and docked controls because it is emitted by TwinControl classes.

code show as below:

Procedure TWINCONTROL.DOCKDROP (Source: TDRAGDOCKOBJECT; X, Y: Integer);

Begin

IF (Perform (CM_DOCKCLIENT, INTEGER (SMALLPOINT (X, Y))> = 0)

And Assigned (FondockDrop) THEN

FondockDrop (Self, Source, X, Y);

END;

It can be seen that TwinControl is first sending a DockClient message, and then triggers the onDockdrop event.

In order to demonstrate the parked form, we first create a host form, name TiledHost, set its Docksite to True. Its role is used to load two DockableForm.

First capture the DockClient message in DockableForm, and complete the mutual stop of two forms

statement:

Private

Procedure CmdockClient (var message: tcmdockclient; message cm_dockclient;

END;

achieve:

Procedure TdockableForm.cmdockClient (Var Message: TcmdockClient);

VAR

Host: tform;

Begin

If Message.dockSource.Control Is TdockableForm Then

Begin

Host: = ttiledHost.create (Application);

Host.BoundSRect: = Self.BoundSRect;

Self.manualdock (Host, NIL, Alnone);

Self.docksite: = false;

Message.docksource.Control.manualDock (Host, NIL, Alnone);

TDOCKABLORM (Message.Docksource.Control) .docksite: = false;

Host.visible: = true;

END;

END;

First explain the above code, first create a TTILEDHOST instance, then use the ManualDock function to stop yourself to TTILEDHOST, stop the message.docksource.control, so that the form is docked, of course, if we want the program Producing a preview effect, add code in DockableForm's onDockover event: Procedure TDOCKABLORM.FORMDOCKOVER (Sender: Tobject;

Source: TDRAGDOCKOBJECT; X, Y: Integer; State: TDRAGSTATE

VAR Accept: boolean;

VAR

Arect: TRECT;

Begin

Accept: = source.control is TDOCKLOLM;

IF accept kil

Begin

Arect.topleft: = ClientToscreen (Point (0, 0));

All.bottomright: = ClientToscreen

Point (ClientWidth Div 2, ClientHeight));

Source.dockRect: = all;

END;

END;

How, the effect is OK. Yes, it is necessary to pay attention to the use of the ManualDock function to complete the docking function, do not use the Dock function. The ManualDock function has some parameters:

Function ManualDock (NewDocksite: TwinControl; DropControl: tcontrol = nil; controlside: talign = alnone): boolean;

NewDocksite: To be docked by the form;

DropControl: Tcontrol already exists in NewDocksite, where you can set it into NIL;

Controlside: The location of the docked, can be upper, lower, left, right, all, etc.

Of course, we can also let TiledHost have the same function as LEFTDOCKPANEL, just see TiledHost as the previous LeftDockPanel, add some properties and events; see TileDhost as DockableForm,

You can have a function of docking. The specific practice is no longer elaborated, and it is believed that the prawns who have deep research on VCL know how to do it.

Let me talk about how two forms stopped into pageControl patterns.

First create a form, called Tabhost, put a pageControl on it, Align property is set to Alclient, let it account for the entire Tabhost, don't forget to set up the PageControl's DockSite property into True.

Then we join the code in turn:

Procedure TdockableForm.FormDockover (Sender: Tobject;

Source: TDRAGDOCKOBJECT; X, Y: Integer; State: TDRAGSTATE

VAR Accept: boolean;

VAR

Arect: TRECT;

Begin

Accept: = source.control is TDOCKLOLM;

IF accept kil

Begin

Arect.topleft: = ClientToscreen (clientRect.Topleft);

Arect.Bottomright: = ClientToscreen (ClientT.BOTTOMRIGHT); Source.DockRect: = all;

END;

with

Procedure TdockableForm.cmdockClient (Var Message: TcmdockClient);

VAR

Host: tform;

Begin

If Message.dockSource.Control Is TdockableForm Then

Begin

Host: = TTABHOST.CREATE (Application);

Host.BoundSRect: = Self.BoundSRect;

Self.manualdock (TTabhost (Host) .PageControl1, nil, alclient;

Message.docksource.Control.manualdock (TTabhost (Host) .PageControl1, nil, alclient;

Host.visible: = true;

END;

END;

The specific meaning of the code is no longer explained here. The same can also make TabHost have the function of docking and docking. It will also be necessary to explain that the TPAGEControl encapsulates some support, it captures CM_DOCKCLIENT,

CM_DOCKNOTIFICATION, CM_UNDOCKCLIENT, WM_LBUTTONDBLCLK message processing docking action. You can view the original code of TPAGEControl.

Like the docking of the toolbar, put a Controlbar or Coolbar on the main form, set their Docksite to True; put the Toolbar on the top, Toolbar's Dragkind property set into DKDOCK, and the DragMode property is set to DMautomatic. Here, TControl has a property called floatingdocksiteclass, which is the TWINControl's reference (Class of TWINCONTROL), as long as the main window is created, set the Toolbar's floatingdocksiteClass attribute to a form A, such as in design A window The body is called ToolbardockForm, but does not have explicitly created a in the program, Delphi will be created. When Toolbar is dragged out, Delphi automatically loads it into ToolbardockForm, and of course ToolbardockForm also sets the same as the DockableForm mentioned above. Attributes and add some code.

Telling a lot, still did not finish the docking function supported by Delphi, as far as I know, there are still many. Still listed them for your reference (omitted in the previous introduction)

Attributes:

1. TControl. TBDOCKHEIGHT / / Store the height of the stop control at the time of docking;

2. TControl. LrdockWidth // Stores the width of the stop control when the control is stopped;

3. TControl. Undockheight // Stores the height of the stop control during floating;

4. TControl. Undockwidth // Stores the width of the stop control during floating;

5. Tcontrol. Hostdocksite // Store an instance of the parked control

6. Tcontrol. Floatingdocksiteclass //

7. Tcontrol. Floating // is floating

9. TControl. Dockorientation // Dock the orientation of the control

10. TwinControl .dockClientCount // There are several already docked controls in this control

11. TwinControl. DockClients // There is a list of locked controls in this control

12. TwinControl. DockManager // A class that controls the parked, actually an ActiveX control, and the class corresponding to it is TDockTree.

13. TwinControl .UsedockManager // Do you use DockManager.

method:

1. Tcontrol.manualfloat // and ManualDock correspond to floating.

2. TControl.ReplacedockedControl // Replace the stop control

3. TwinControl .doadddockClient

4. TwinControl .dockdropdropdropdrop

5. TwinControl .dockOver

6. TwinControl .dodockOver

7. TwinControl .doundock

news:

CM_DOCKCLIENT,

CM_DOCKNOTIFICATION,

CM_undockClient

If the reader wants to have a more in-depth understanding of the stop technology, you can see the example of Delphi, the path is Delphi5 / Demo / Docking.

I am a rookie, the content mentioned above, the mistake is inevitable, I hope the prawn should not joke.

If you have an omission, please advise, thank you.

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

New Post(0)