System.Classes.TWriter.DefineProperty

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure DefineProperty(const Name: string;  ReadData: TReaderProc; WriteData: TWriterProc; HasData: Boolean); override;

C++

virtual void __fastcall DefineProperty(const System::UnicodeString Name, TReaderProc ReadData, TWriterProc WriteData, bool HasData);

Properties

Type Visibility Source Unit Parent
procedure
function
public
System.Classes.pas
System.Classes.hpp
System.Classes TWriter

Description

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

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.

See Also