YOUSEFUL / DELPHI / COMPONENTS
TAtlasSetCellEvent
Method type of TAtlasVirtualData.OnSetCell: store or refuse one edited cell.
Description
TAtlasSetCellEvent = procedure(Sender: TObject; Column, Row: Integer; const Cell: TAtlasCell) of object; Cell has the column's kind and may be null. Raise EAtlasGridError to refuse it.
This type has no members of its own beyond those listed in its description.
Examples
Validate before storing
The handler is SetPrice.
uses System.Classes, Atlas.VGridData;
type
TPrices = class(TComponent)
private
FPrices: TArray<Double>;
FData: TAtlasVirtualData;
procedure GetPrice(Sender: TObject; Column, Row: Integer; var Cell: TAtlasCell);
procedure SetPrice(Sender: TObject; Column, Row: Integer; const Cell: TAtlasCell);
public
constructor Create(AOwner: TComponent); override;
property Data: TAtlasVirtualData read FData;
end;
constructor TPrices.Create(AOwner: TComponent);
begin
inherited;
FPrices := [9.5, 12, 30];
FData := TAtlasVirtualData.Create(Self);
FData.AddColumn('Price', ckNumber);
FData.OnGetCell := GetPrice;
FData.OnSetCell := SetPrice; // without a handler every column is read-only
FData.RowCount := Length(FPrices);
end;
procedure TPrices.GetPrice(Sender: TObject; Column, Row: Integer; var Cell: TAtlasCell);
begin
Cell := TAtlasCell.OfNumber(FPrices[Row]);
end;
procedure TPrices.SetPrice(Sender: TObject; Column, Row: Integer; const Cell: TAtlasCell);
begin
// The text has already been parsed as a number. Raising EAtlasGridError
// refuses the value; a grid keeps its editor open and reports the message.
if Cell.IsNull or (Cell.Number <= 0) then
raise EAtlasGridError.Create('A price must be above zero');
FPrices[Row] := Cell.Number;
end;
Related
TAtlasVirtualData · TAtlasGetCellEvent · EAtlasGridError
Also in Atlas Virtual Grid
TAtlasVirtualGrid · TAtlasMemoryData · TAtlasVirtualData · TAtlasPlotData