20th Chapter-Development Delphi Object Type Data management function (III.) (1)

Source: Internet
Author: User
Tags abstract

Properties and methods of 20.2.1.1 Tfiler objects

1. Root Property

Statement: Property root:tcomponent;

The root property indicates to the Filer object which object in the read-write object is the root or primary owner. The Rootcomponent and Writerootcomponent methods set the value of root before reading and writing parts and their own parts.

2. Ancestor Properties

Statement: Property ancestor:tpersistent;

The Ancestor property is used to write the part to the inherited form, because when the part is written, the write object only needs to write a different attribute than the inherited part, so keep track of each inherited part and compare their properties before writing.

If ancestor is nil, there is no corresponding inherited part, and the writer object should fully write the part to the stream. Ancestor are generally nil and are assigned only when Writedescendant and Writedescendantres are invoked. When you write and overwrite defineproperties, you must set the ancestor value.

3. Ignorechildren Properties

Statement: Property Ignorechildren:boolean;

The Ignorechildren property enables a writer object to store a part without storing parts owned by that part. If the Ignorechildren property is true, the writer object storage part does not save the child parts it owns. Otherwise, the writer Object writes all its owned objects to the stream.

4. Create method

Statement: constructor Create (Stream:tstream; bufsize:cardinal);

The Create method creates a new Filer object, establishes its connection to the stream stream, and assigns it a buffer. The size of the buffer is specified by BufSize.

5. DefineProperty method

Statement: Procedure DefineProperty (const name:string; Readdata:treaderproc;

Writedata:twriterproc; Hasdata:boolean); Virtual Abstract

The DefineProperty method defines the data that the Filer object will store as a property. The name parameter describes the accepted property name, which is not defined in the published section. The ReadData and WriteData parameters specify how the required data is read and written when the object is accessed. The HasData parameter determines at run time whether the property has data to store.

DefineProperty is invoked in the defineproperties of an object only if it has data to store. Defineproperties has a Filer object as its argument, and it calls the DefineProperty and Definebinaryproperty methods of the Filer object. When a property is defined, the writer object should refer to the Ancestor property, and if the property is Non-null, the writer object should write only the values of the different properties inherited from ancestor.

One of the simplest examples is the Defineproperties method of Tcomponent. Although Tcomponent does not define the left and top properties in published, the method stores the location information for the part.

Procedure Tcomponent.defineproperties (Filer:tfiler);

Begin

Filer.defineproperty (' left ', Readleft, Writeleft, Longrec (fdesigninfo). Lo <> 0);

Filer.defineproperty (' Top ', Readtop, Writetop, Longrec (fdesigninfo). Hi <> 0);

End

6. Definebinaryproperty method

Statement: Procedure Definebinaryproperty (const name:string;

ReadData, Writedata:tstreamproc;

Hisdata:boolean); Virtual Abstract

The Definebinaryproperty method defines the binary data that the Filer object stores as a property. The name parameter describes the property name. The ReadData and WriteData parameters describe the methods of reading and writing the required data in the stored object. The HasData parameter determines whether the property has data to save at run time.

The difference between the Definebinaryproperty and DefineProperty methods is that the attributes of the binary are read and written directly by the stream object rather than by the Filer object. The object data is written to the stream or read from the stream directly through ReadData and WriteData incoming methods.

The Definebinaryproperty property is used less. Only a standard VCL object defines a part of a binary property, such as a graphic or an image, to use it.

7. Flushbuffer method

Statement: procedure Flushbuffer; Virtual:abstract;

The Flushbuffer method is used to synchronize the buffer of the Filer object with the associated stream object. For the reader object, by reallocating the buffer, for the writer object is by writing to the current buffer.

Flushbuffer is an abstract method, Treader and Twriter all cover it, providing a concrete implementation.

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.