Unified editing, searching, and printing of projects

Source: Internet
Author: User

In many c/sProgramYou can edit, query, and print data in the database. In the past, different data tables were edited, queried, and printed separately. Each form was brand new. We will sniff"CodeRepetition makes it difficult to maintain and modify code in the future. This may be worse if it is a multi-person project, because each pair of programmers may provide different interface methods for editing, querying, and printing.
In response to the above problems, I have made some adjustments in my previous projects and I will share them with you.
Since the data editing, query, and printing functions appear in each data form, such as "Order Form", "warehouse receiving form", and "Purchase Order Form", the data is uniformly planned. A pop-up dialog box is usually used to edit, query, and print databases. Therefore, a dialog box form class is defined in the project.TdialogformThis class initializes the font, size, and position of the form in a unified manner, and provides an abstract MethodExecuteFor external calls. The Edit, query, and print forms inherit from the form and implement this abstract method.

We addedEdiror,SearcherAndPrinterThree attributes are used to specify the edit, query, and print form instances used.Doedit,DosearchAndDoprintThree methods are used as call interfaces. Place three buttons (toolbar buttons or menus, as needed) in the data browsing form and click the event to call them. Because the code is similar, print is used as an example here:

If Assigned (fprinter) then begin
Printer. Dataset: = Activedataset;
Printer. Execute;
End;
Else
Tdialogbox. Info ( ' Not assigned printer ' );

Now, the basic framework for editing, querying, and printing is ready. The following describes the details.
Different data tables have different fields, so the interface for editing, querying, and printing forms is naturally different. Careful friends may have discovered that there isDatasetAttribute. We use this property to obtain field information and use the dynamic creation control method to create elements on the form that can be input by users. The specific code is not written here.
This method makes full use of the inheritance and polymorphism in the object-oriented programming, minimizes the repeated code in the program, and reduces the maintenance and modification costs in the future.

Let's talk about it.

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.