The 20th Chapter-Development Delphi Object Type Data management function (four) (6)

Source: Internet
Author: User
Tags definition error handling resource

7. SetName Methods and Onsetname events

Because the name parameter is var in the Onsetname event, you can use the Onsetname event handler to modify the name of the part you read. The Onsetname event handling process is implemented in the SetName method.

Procedure Treader.setname (component:tcomponent; var name:string);

Begin

If assigned (fonsetname) then Fonsetname (Self, Component, Name);

Component.name: = Name;

End

SetName method and Onsetname event play an important role in the programming of dynamic DFM files.

8. Treader Error Handling

Treader error handling is accomplished by the combination of the error method and the OnError event. The handled parameter of the OnError event handler is a Boolean variable of Var, which can affect error handling treader by setting handled to TRUE or false. The OnError event-handling process is invoked in the error method.

function Treader.error (const message:string): Boolean;

Begin

Result: = False;

If assigned (fonerror) then Fonerror (Self, message, result);

End

9. FindMethod and Onfindmethod Events

Sometimes, it is useful to dynamically assign a method pointer (primarily an event-handling process) to a part during the program's operation, which can dynamically change the way parts respond to events. Reading a part in a stream to do something, it is necessary to use the Onfindmehtod event. The Onfindmethod event was invoked in the FindMethod method.

function Treader.findmethod (root:tcomponent;

Const methodname:string): pointer;

Var

Error:boolean;

Begin

Result: = Root.methodaddress (methodname);

Error: = result = Nil;

If assigned (Fonfindmethod) then Fonfindmethod (Self, methodname, result,

ERROR);

If Error then Propvalueerror;

End

The Onfindmethod method can also modify the error parameter to determine whether to handle the missing methods error, in addition to dynamically assigning the method pointer that is specified by the MethodName of the part. The Mehtodaddress method called in the method is defined in TObject and is a useful way to get the address of the public method defined in the object. FindMethod method and Onfindmethod event play an important role in the programming of dynamic DFM.

20.3 Delphi Object Type data Management application example

Delphi 2.0 whether its visual design tools, or Visual Component Class Library (VCL), are everywhere infiltration of object storage technology, this section will be from the Delphi visual design internal mechanism, VCL data storage, BLOB data manipulation and the storage of dynamically generated parts introduces instances of object storage functionality.

The application of 20.3.1 Delphi dynamic DFM file and component access in Hypermedia system

Delphi's visual design tool is closely integrated with its part class library.

Each part can appear on component palette only through a registration procedure and through the Install component function of Delphi; The properties of a part can appear in the Object Inspector window The component's property editor can be used by the Delphi environment. Because of this kind of natural relationship, DFM file access must be VCL in the program support.

The component access of DFM files is the central problem of file Access in Delphi Visual design environment. Because the core of Delphi visual design is the design of the form. Each form corresponds to a library unit, which is the application's module, and the form's storage on disk is the DFM file.

DFM file Structure we introduced it earlier. It is actually a property that stores the form and all the parts it owns. This kind of ownership relationship is recursive. The problem is how to relate these property data to the variable (property) code in the program.

The process of handling this connection in Delphi is divided into two situations: design time and runtime.

At design time, the relationship is established to read the DFM file, to establish the components and their attributes in the DFM file, and to contact the visual design tools (Object Inspector, Form Design window, and code Editor), which means that these parts and their properties can appear in these windows. and associated with the attribute definition in the code; The decomposition relation is performed by storing the DFM file and writing the parts and their attributes in the form window to the DFM file.

At runtime, the main is the process of establishing a connection, that is, to read the DFM file. At this point, the DFM file is not as a stand-alone disk file, but rather as a binary data of the Rcdata type in the application resource. The process of establishing a relationship is characterized by linking the parts and their attributes in the resource to the objects in the application and their data fields. The process is: according to the part class name in DFM to create the object, and then use the part attribute value in DFM to assign value to the part attribute in the program. Of course, to complete this process, you must also have a corresponding form definition in your code, because code such as methods is not stored in the part.

VCL support for reading DFM files is achieved through stream objects and filer objects. In the 20. In sections 1 and 20.1, we can see that the stream object and the Filer object have a large number of methods for accessing parts and their properties, especially in Treader objects, as well as methods for error handling and dynamic method assignment. Below we will use the procedure example to introduce the Access DFM file method, the step and the notice matter.

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.