YOUSEFUL / DELPHI / COMPONENTS
TAtlasMemoryData
A data source that holds typed cells in memory, filled from invariant text or from typed cells.
Description
Columns are added in code with a title, a TAtlasCellKind and an optional read-only flag. Nothing about them is stored in the .dfm. When the component is placed at design time and linked to a grid there, add the columns in code and then call the grid's ResetColumns. Rows are added whole from text with AddRow, and changed cell by cell with SetCell or SetText. The source itself enforces column kinds and read-only columns, so they hold for code as well as for the grid. Every change notifies the watching grids; wrap bulk loads in BeginUpdate/EndUpdate so they react once. Each cell is one TAtlasCell record.
Members
| Member | Kind | What it does |
|---|---|---|
Create | constructor | Creates an empty source with no columns and no rows. |
Destroy | destructor | Frees the cells. |
AddColumn | method | Adds a column and returns its index. |
AddRow | method | Adds a row from one text per column and returns its index. |
DeleteRow | method | Removes a row; later rows move up. |
ClearRows | method | Removes every row and keeps the columns. |
ClearAll | method | Removes every row and column. |
ColumnTitle | method | The title given to AddColumn. |
ColumnKind | method | The kind given to AddColumn. |
ColumnReadOnly | method | The read-only flag given to AddColumn. |
GetCell | method | The stored cell. |
SetCell | method | Stores a cell of the column's kind; a null of that kind blanks it. |
BeginUpdate | method from TAtlasGridData | Starts a batch: the changes made until the matching EndUpdate reach watching grids as one notification. |
EndUpdate | method from TAtlasGridData | Ends a batch. |
AddListener | method from TAtlasGridData | Registers a method that is called, with the source as Sender, after every change or batch. |
RemoveListener | method from TAtlasGridData | Unregisters a method. |
SetText | method from TAtlasGridData | Parses Text for the column's kind with Settings (see TAtlasCell.TryParse) and stores the result with SetCell. |
CheckCell | method from TAtlasGridData | Raises EAtlasGridError Column n does not exist or Row n does not exist unless the cell lies inside the data. |
RowCount | property from TAtlasGridData | Number of rows. |
ColumnCount | property from TAtlasGridData | Number of columns. |
Version | property from TAtlasGridData | Increases on every change, including each change inside a batch and once more when the batch ends. |
Constructors
Create constructor
constructor Create(AOwner: TComponent); override;Creates an empty source with no columns and no rows.
Destructors
Destroy destructor
destructor Destroy; override;Frees the cells. Grids bound to the source unbind themselves.
Properties
RowCount propertyinherited from TAtlasGridData
property RowCount: Integer read GetRowCount;Number of rows.
ColumnCount propertyinherited from TAtlasGridData
property ColumnCount: Integer read GetColumnCount;Number of columns.
Version propertyinherited from TAtlasGridData
property Version: Integer read FVersion;Increases on every change, including each change inside a batch and once more when the batch ends. Compare two readings to tell whether anything changed.
Methods
AddColumn method
function AddColumn(const Title: string; Kind: TAtlasCellKind = ckText; ReadOnly: Boolean = False): Integer;Adds a column and returns its index. Existing rows get a null cell in it. A ReadOnly column refuses SetCell and SetText, from code as well as from the grid; fill it through AddRow. A grid that is already bound does not add a column for it by itself: call its ResetColumns or add a grid column.
Orders.AddColumn('Order', ckNumber, True);AddRow method
function AddRow(const Values: array of string): Integer;Adds a row from one text per column and returns its index. Values are read with invariant settings: . as the decimal separator, ISO 8601 dates such as 2026-03-31 or 2026-03-31T14:30:00 (or invariant MM/dd/yyyy), and yes/no, true/false, y/n or 1/0 in any case. Empty text is null. The row is added whole or not at all. A wrong number of values raises A row needs n values; m given, and a value that does not fit raises "x" does not fit column "Title"; both are EAtlasGridError. Read-only columns can be filled this way.
Orders.AddRow(['Contoso', '1250.50', '2026-03-31', 'no']);DeleteRow method
procedure DeleteRow(Row: Integer);Removes a row; later rows move up. Raises EAtlasGridError for a row that does not exist.
ClearRows method
procedure ClearRows;Removes every row and keeps the columns. Sends no notification when there were no rows.
ClearAll method
procedure ClearAll;Removes every row and column. Bound grids keep their own columns; call ResetColumns on them after adding the new columns.
ColumnTitle method
function ColumnTitle(Column: Integer): string; override;The title given to AddColumn. An index outside the columns raises the list's EArgumentOutOfRangeException.
ColumnKind method
function ColumnKind(Column: Integer): TAtlasCellKind; override;The kind given to AddColumn.
ColumnReadOnly method
function ColumnReadOnly(Column: Integer): Boolean; override;The read-only flag given to AddColumn.
GetCell method
function GetCell(Column, Row: Integer): TAtlasCell; override;The stored cell. Raises EAtlasGridError outside the data.
Missing := Orders.GetCell(1, 0).IsNull;SetCell method
procedure SetCell(Column, Row: Integer; const Cell: TAtlasCell); override;Stores a cell of the column's kind; a null of that kind blanks it. Raises EAtlasGridError outside the data, for a read-only column (Column "Title" is read-only) and for a cell of another kind (Column "Title" holds another kind of value).
Orders.SetCell(1, 0, TAtlasCell.OfNumber(1300.75));BeginUpdate methodinherited from TAtlasGridData
procedure BeginUpdate;Starts a batch: the changes made until the matching EndUpdate reach watching grids as one notification. Batches nest.
Orders.BeginUpdate;EndUpdate methodinherited from TAtlasGridData
procedure EndUpdate;Ends a batch. When the outermost batch ends and something changed, the listeners are called once. An EndUpdate without a BeginUpdate is ignored.
Orders.EndUpdate;AddListener methodinherited from TAtlasGridData
procedure AddListener(const Listener: TNotifyEvent);Registers a method that is called, with the source as Sender, after every change or batch. Adding the same method twice registers it once. Grids register themselves when bound, so this is for your own code.
RemoveListener methodinherited from TAtlasGridData
procedure RemoveListener(const Listener: TNotifyEvent);Unregisters a method. Safe during a notification and after the source has begun to be destroyed.
SetText methodinherited from TAtlasGridData
procedure SetText(Column, Row: Integer; const Text: string; const Settings: TFormatSettings);Parses Text for the column's kind with Settings (see TAtlasCell.TryParse) and stores the result with SetCell. Raises EAtlasGridError for a cell outside the data and for text that does not parse ("abc" is not a number, is not a date, is not yes or no); the stored value is unchanged. The grid's editor and Delete key write through this method with the global FormatSettings.
Orders.SetText(1, 0, '1300.75', TFormatSettings.Invariant);CheckCell methodinherited from TAtlasGridData
procedure CheckCell(Column, Row: Integer);Raises EAtlasGridError Column n does not exist or Row n does not exist unless the cell lies inside the data.
Examples
Fill a memory source
Four typed columns and three rows, loaded in one batch. The third row's amount, date and paid flag are null.
uses Atlas.VGridData;
procedure FillOrders(Orders: TAtlasMemoryData);
begin
Orders.AddColumn('Customer');
Orders.AddColumn('Amount', ckNumber);
Orders.AddColumn('Due', ckDateTime);
Orders.AddColumn('Paid', ckBoolean);
Orders.BeginUpdate; // one notification for the whole batch
try
// One text per column, read with invariant settings: '.' decimals, ISO dates.
Orders.AddRow(['Contoso', '1250.50', '2026-03-31', 'no']);
Orders.AddRow(['Fabrikam', '980', '2026-02-28', 'yes']);
Orders.AddRow(['Northwind', '', '', '']); // empty text is a null cell
finally
Orders.EndUpdate;
end;
end;
Bind it to a grid
The grid creates one column per data column when it has none. See the quick start sample for sorting, filtering, totals and export.
uses Vcl.Forms, Vcl.Controls, Atlas.VGridData, Atlas.VGrid;
procedure ShowOrders(Form: TForm; Orders: TAtlasMemoryData);
var Grid: TAtlasVirtualGrid;
begin
Grid := TAtlasVirtualGrid.Create(Form);
Grid.Parent := Form;
Grid.Align := alClient;
Grid.Data := Orders; // no columns yet: one per data column
Grid.FrozenColumns := 1; // Customer stays put when scrolling sideways
Grid.Columns[1].Format := '#,##0.00';
Grid.Columns[1].Total := tkSum;
Grid.Columns[2].Format := 'yyyy-mm-dd';
Grid.Sort(1, True); // largest amount first
end;
Related
TAtlasVirtualGrid · TAtlasGridData · TAtlasCell · TAtlasCellKind · TAtlasVirtualData