YOUSEFUL / DELPHI / COMPONENTS
EAtlasGridError
The exception class of Atlas Virtual Grid, and the way a data source refuses a value.
Description
Raised for cells and columns that do not exist, values that do not fit a column, writes to read-only sources and columns, unsupported file types and image sizes, and refused chart values. Raise it yourself from OnSetCell or a custom SetCell to refuse a value. The grid catches this class, and only this class, around edits: it reports the message through OnEditError and LastError and keeps the old value. Atlas Plot errors raised while exporting a picture or writing to a chart are translated into it.
This type has no members of its own beyond those listed in its description.
Examples
Refuse a value
The price source refuses zero and negative prices.
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
TAtlasVirtualGrid · TAtlasVirtualData · TAtlasGridData
Also in Atlas Virtual Grid
TAtlasVirtualGrid · TAtlasMemoryData · TAtlasVirtualData · TAtlasPlotData