From RAD Studio API Documentation
Jump to: navigation, search



TDataModel = class(TMessageSender)


class PASCALIMPLEMENTATION TDataModel : public Fmx::Presentation::Messages::TMessageSender


Type Visibility Source Unit Parent
class public
FMX.Controls.Model FMX.Controls.Model


Data models for presented controls.

TDataModel is the base class of data models for presented controls. Descendant classes define properties that store data values used by properties of corresponding presented controls.

TDataModel extends TMessageSender, which provides the sending messages functionality. A Data model can define a Receiver (or presentation) and send messages to this Receiver, when a Data model's data is changed, to update the values shown in the associated presented control. When a Data model reads or writes Data values the Data model sends MM_GETDATA and MM_DATA_CHANGED messages to a presentation.

TDataModel defines the DataSource property containing a collection of key-value pairs. Keys are strings and values are instances of TValue. Since the TValue type can keep and handle any arbitrary type data; therefore, the DataSource collection can keep any required data. This means that to keep any type data TDataModel does not need to create a new separate class. For example, it can keep an array of strings, which can be used as a collection of prompt words in an editor. Like this:

  TStringArray = TArray<string>;
  ArrayList1, ArrayList2: TStringArray;
  { Setting/Getting value of array type }
  ArrayList1 := ['Apple', 'ARC', 'Auto', 'Allday', 'Alltime'];
  Edit1.Model.Data['array_value'] := TValue.From<TStringArray>(ArrayList1);
  if Edit1.Model.Data['array_value'].IsType<TStringArray> then
    ArrayList2 := Edit1.Model.Data['array_value'].AsType<TStringArray>;

When you create a data model, you must pass a presentation control to the constructor. The specified presentation control owns the model.

See Also