[Original] Delphi

Source: Internet
Author: User

Note:Article
I switched from VC to Delphi. It is more likely to feel more deeply in learning.
VCL in Delphi is like MFC in VC, but you can use SDK encoding for both Delphi and VC. If you want to learn about the message mechanism and API of windows, you can directly use SDK encoding. However, the SDK is really not easy to understand.
Therefore, my basic understanding is that both VCL and MFC have encapsulated WINDOWS Message Processing Systems and APIs in an object-oriented manner. At the same time, every upgrade of Delphi will be accompanied by version incompatibility issues, but this problem rarely occurs in VC. I think it has something to do with his design structure. VCL is designed in close coupling mode, while MFC is loosely coupled. Therefore, the two designs have their own advantages and disadvantages. For example, if you feel that Delphi is easier to learn than VC, I am afraid it is not just because he has a fast programming environment, due to the tight coupling feature of VCL, you can solve many problems. For example, if you dynamically create a control on the form, you may not consider releasing it, because delphi will help you release the control when its owner is released; but in VC, you must manually release the control.
So much I want to say is that design is very important.
Some things can free you from the single-storage coding: system design, pattern design, and usage.
For example, I used to ask our project team to write the following when using the mode form: Code :
Class procedure tmyform. runform (aobj1, aobj2: tobject );
VaR
Vform: tmyform;
Begin
Vform: = tmyform. Create (application );
With vform do
Try
Initform (aobj1, aobj2 );
Showmodal;
Finally
Free;
End;
End;
Emphasize this idiom:
1. If this form is used in multiple places, this code segment can be called in a unified manner;
2. if the function is modified, for example, it can be processed based on the showmodal return value.
3, Program Good encapsulation, easy maintenance and work handover.
In fact, we are now talking about system analysis and design models, but we have not studied the basic usage, which is actually a major mistake. When foreigners write their idioms into books, it is enough to show that we are lagging behind.
When talking about the design, we can compare the Chinese table and the Excel file. From the current design level, we can see that the Excel file has fallen behind, but the Chinese table has to lag far behind the Excel file. This also shows our gap.

{No. 1}
(*
Question: design a status tracking Form B for Form C. When different operations are required in Form C, the actual information of Form B is different.
Business instance: for example, a map form, when different map elements are selected in the map, the element attribute form information is displayed as the currently selected map element. *)

// ******* Solution 1 solves general problems
Uses
...
Fproperty;
Type
Tfrmmymap = Class
...
Procedure onfrmmymapcreate (Sender: tobject );
Procedure onfrmmymapdestroy (Sender: tobject );
Procedure onmapgeoselected (Ageo: tgeometry );
Private
Ffrmproperty: tfrmproperty;
Public
End;

Procedure tfrmmymap. onfrmmymapcreate (Sender: tobject );
Begin
Ffrmproperty: = tfrmproperty. Create (application );
End;

Procedure tfrmmymap. onfrmmymapdestroy (Sender: tobject );
Begin
Ffrmproperty. Free;
End;

Procedure tfrmmymap. onmapgeoselected (Ageo: tgeometry );
Begin
Ffrmproperty. myrefresh (Ageo );
End;

// ******* Solution 2: Create an attribute form when necessary
Uses
...
Fproperty;
Type
Tfrmmymap = Class
...
Procedure onfrmmymapdestroy (Sender: tobject );
Procedure onmapgeoselected (Ageo: tgeometry );
Private
Ffrmproperty: tfrmproperty;
Procedure showpropertyform (avisible: Boolean );
Public
End;

Procedure tfrmmymap. showpropertyform (avisible: Boolean );
Begin
If not assigned (ffrmproperty) Then ffrmproperty: = tfrmproperty. Create (application );
Ffrmproperty. Visible: = avisible;
End;

Procedure tfrmmymap. onfrmmymapdestroy (Sender: tobject );
Begin
If assigned (ffrmproperty) Then ffrmproperty. Free;
End;

Procedure tfrmmymap. onmapgeoselected (Ageo: tgeometry );
Begin
If assigned (ffrmproperty) Then ffrmproperty. myrefresh (Ageo );
End;

// ******* Solution 3 uses the message mechanism to trigger the form operation. It defines common form variables and minimizes form inclusion.
Map unit:
Type
Tfrmmymap = Class
...
Procedure onfrmmymapdestroy (Sender: tobject );
Procedure onmapgeoselected (Ageo: tgeometry );
Private
Ffrmproperty: tform; // defines common form class variables
Procedure showpropertyform (avisible: Boolean );
Public
End;

Implementation
Uses
Fproperty;

Procedure tfrmmymap. showpropertyform (avisible: Boolean );
Begin
If not assigned (ffrmproperty) Then ffrmproperty: = tfrmproperty. mycreate (application, self );
Ffrmproperty. Visible: = avisible;
End;

Procedure tfrmmymap. onfrmmymapdestroy (Sender: tobject );
Begin
If assigned (ffrmproperty) Then ffrmproperty. Free;
End;

Procedure tfrmmymap. onmapgeoselected (Ageo: tgeometry );
Begin
If assigned (ffrmproperty) Then ffrmproperty. Perform (wd_mapgeoselected, INTEGER (@ Ageo), 0 );
End;
Attribute unit:
Tfrmproperty = Class (tform)
Private
Fmapform: tform;
Procedure wdmapgeoselected (VAR message: tmessage); message wd_mapgeoselected;
Public
Constructor mycreate (owner: tcomponent; amapform: tform );
End;

Constructor tfrmproperty. mycreate (owner: tcomponent; amapform: tform );
Begin
Inherited create (owner );
Fmapform: = amapform;
End;

Procedure tfrmproperty. wdmapgeoselected (VAR message: tmessage );
Begin
Fmapform. Perform (wd_mapgeoselectedbegin, 0, 0 );
....
Fmapform. Perform (wd_mapgeoselectedend, 0, 0 );
End;

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.