Ø tfiler
Let's take a look at the definition of the TFiler class:
Tfiler = Class (TOBJECT)
Private
FSTREAM: TSTREAM;
FBuffer: Pointer;
FBUFSIZE: Integer;
FBUFPOS: Integer;
FBUFEND: Integer;
FROOT: TComponent;
FLOOKUPROOT: TComponent;
FANCESTOR: TPERSISTENT;
FIGNORECHILDREN: BOOLEAN;
protected
Procedure Stroot (Value: tComponent); Virtual;
public
Constructor Create (Stream: TSTREAM; buffsize: integer);
DESTRUCTOR DESTROY; OVERRIDE;
Procedure DefineProperty (const name)
ReadData: TreaderProc; WriteData: TwriterProc;
Hasdata: boolean;
Procedure DefineBinaryProperty (const name)
ReadData, WriteData: TSTREAMPROC
Hasdata: boolean;
PROCEDURE FLUSHBUFFER; VIRTUAL; ABSTRACT;
Property root: tComponent Read Froot Write Stroot;
Property lookuproot: Tcomponent Read flookuproot;
Property Annce: TPERSIStent Read FanceStor Write FanceStor;
Property Ignorechildren: Boolean Read FignoreChildren Write FIGNILDREN;
END;
The TFiler object is the abstraction class of Treader and Twriter defines the basic properties and methods for component storage. It defines the root property, and root indicates the root object of the component read or written. Its create method uses the Stream object as an incoming parameter to establish contact with the stream object, and the specific read and write operation of the Filer object is a Stream object. carry out. Therefore, the components can be accessed by the FILER object by the medium that the Stream object can be accessed by the STREAM object.
The TFiler object also provides two public methods for defined attributes: DefineProperty and DefineBinaryProperty, which enables objects to read and write the properties defined by the component Publisd section. The following focuses on these two methods.
The defineProperty () method is used to allow standard data types to persist, such as strings, integers, boolean characters, floating points and enumerations.
In the defineProperty method. The Name parameter is used to specify the name of the attribute that should be written to the DFM file, which is not defined by the PublisHed section of the class.
The READDATA and WRITEDATA parameters specify how to read and write the required data when accessing objects. The type of readdata parameters and WriteData parameters is TreaderProc and TwriterProc. These two types are this statement:
TreaderProc = Procedure (Reader: Treader) OF Object;
TWRITERPROC = Procedure (Writer: twriter) of object;
The HasData parameter determines if the property is data to be stored at runtime.
The DefineBinaryProperty method and defineproperty have a lot of the same place, which is used to store binary data, such as sound and image. Here is the use of these two methods.
When we put a non-visual component such as TTIMER, we reopened the form, we found TTIMER or in the original place, but TTIMER did not Left and TOP properties, then where is its location information saved?
Open the DFM file of the form, you can see a few lines similar to the following:
Object Timer1: TTIMER
LEFT = 184
TOP = 149
end
Delphi's streaming system can only save public data, but TTIMER does not have public and TOP properties of public, then how are these data saved?
TTIMER is the derived class of Tcomponent, in the Tcomponent class, we found such a function:
Procedure Tcomponent.defineProperties (Filer: Tfiler);
VAR
Ancestor: tcomponent;
INFO: Longint;
Begin
INFO: = 0;
Ancestor: = Tcomponent (file.ancestor);
IF Ancestor <> nil dam: = ancestor.fdesigninfo;
Filer.defineProperty ('Left', Readleft, WriteLeft,
LongRec (fdesignInfo) .lo <> longrec (info) .lo);
Filer.defineProperty ('Top', Readtop, Writetop,
LongRec (fdesignInfo) .hi <> longrec (info) .hi);
END;
The Tcomponent's defineProperties is a method of overlying its ancestral class TPERSISTENT, which is empty in the TPERSISTENT class.
In the defineproperties method, we can see that there is a Filer object as its parameters, when defining properties, it references the Ancestor property, if this property is non-empty, the object should read with different properties that inherited from the Ancestor value. It calls the TFILER's definePerty method and defines Readleft, Writeleft, Readtop, Writetop method to read and write the LEFT and TOP properties.
Therefore, all components derived from Tcomponent, even if it doesn't have Left and TOP properties, there is two attributes that fluinate into the DFM file.
During the process of finding the information, it is found that there are very few information involved in the component read and write mechanism. Since the write process of the component is done in the design phase by Delphi IDE, it cannot be tracked. Therefore, the author is to analyze the write mechanism of the component through reading mechanisms and twriter by tracking VCL original code during program operation. Therefore, the following text will tell the component read and write mechanism according to this thinking process, let's talk about Treader, and then TWRITER.