RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TWriter.DefineProperty Method

Defines data the writer object writes as if the data were a property.

Pascal
procedure DefineProperty(const Name: string; ReadData: TReaderProc; WriteData: TWriterProc; HasData: Boolean); override;
C++
virtual __fastcall DefineProperty(const AnsiString Name, TReaderProc ReadData, TWriterProc WriteData, Boolean HasData);

DefineProperty is called internally by the DefineProperties method of an object that has data it needs to store. DefineProperties takes a generic filer object as its parameter. For writing data, DefineProperties takes a TWriter object and calls its DefineProperty method. DefineProperty then writes the property's name and its data, but only if the HasData parameter is true. Otherwise it does nothing. 

The Name parameter specifies the name of the "fake" property to be written to the stream. 

The WriteData parameter points to a procedure (defined in the component object) that writes the object's data, which represents a property value, to the writer object. For TWriter the ReadData parameter is ignored. 

The HasData parameter determines at run time whether the "fake" property has data to store (write). Thus, writer objects only use HasData when writing data. 

The difference between DefineBinaryProperty and DefineProperty is that with DefineBinaryProperty, the binary data is written directly to a stream object, rather than going through a filer object. 

When writing a component that has special (large) data storage requirements, the component's DefineProperties can be overridden. For each special or "fake" property item, call DefineProperty or DefineBinaryProperty. For the ReadData and WriteData parameters, pass in methods of the component that know how to handle that special data type. When reading, ReadData is called. When writing, WriteData is called.

Note: When defining properties, a component should be aware of the Ancestor property, which, if non-nil (Delphi) or non-NULL (C++) indicates that the component should only write the values of properties that differ from those inherited from Ancestor.
 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!