Editing data with TMSFNCGrid and TMSFNCGridDatabaseAdapter

Hello,

I'm trying to find out how TMSFNCGrid and TMSFNCGridDatabaseAdapter work with data.
I'm doing a simple FMX demo with Delphi 10.4,
TMSFNC UI Pack 3.2.3.0, FirebirdSQL Database.

I put:
FDCConnection, FDQuery, DataSource, TMSFNCGridDatabaseAdapter, TMSFNCGrid.
FDQuery contains a selection for a single table.

If I edit a cell and the data is not accepted by the server check constraint, an exception occurs and the grid is out of sync.
I can navigate to another row with mouse or arrow keys, I can edit, but the value is related to the record in the dataset that remained in the edit state.

I have seen that TMSFNCGrid is not compatible with LiveBinding
What is the best way to use TMSFNC with databases?
What can I read / learn to use TMSFNC correctly?

Hi,

FNC is not LiveBindings enabled. We chose to use a separate approach by connecting directly to the dataset instead of using LiveBindings.I assume that when the exception occurs in release mode, the exception should be handled gracefully, and the grid should not be out of sync. What happens when you ignore the error and click on continue?

In a cell I edit some data that is not conform.
I click to the next row.
An exception is occured and dataset ramain in edit mode.
TMSFNCGrid is showing like current row is moved.
Up Arrow Key and Down Arrow Key work like all is ok.

When I want to edit some date and is activate cell edit control, is showin data from the record that is still in edit mode.

Hi,

I attach a simple project.
After the exception is raised, the sync between dataset and TMSFNCGrid is broken.

I am not allow to raise an exception in before post event to block some data to propagate?

test.zip (22.0 KB)

Hi,

I'll further investigate this here as soon as possible. Thank you for the sample.

Hi,

The grid has a post mode that automatically tries to post data to the dataset. Raising an exception in the OnBeforePost event of the dataset breaks this cycle. Instead you need to use the OnCellEditValidateData event and set Allow := False to validate the data.

procedure TForm12.TMSFNCGrid1CellEditValidateData(Sender: TObject; ACol,
  ARow: Integer; CellEditor: TControl; var CellString: string;
  var Allow: Boolean);
begin
  Allow := False;
  if ckDoGenError.IsChecked and not Allow then
  begin
    try
      raise Exception.Create('test');
    finally
      TMSFNCGrid1.EditCell(MakeCell(ACol, ARow));
    end;
  end;
end;

Hi,

Thanks for the proposed solution for individual field validation.

Checks and validations on each field are not always sufficient. A final check on the data model to accept or not a record is often required.

Even if the individual values in the fields are accepted, they may not meet other business rules.

A mechanism to refuse to save (post) changes and possibly return to initial values (cancel) would be very useful.

The Dataset can be a proxy class over the data model.
In the data clases raising an exception in the save method when requirments are not fit, allows me to keep separate business rules from the UI.

Hi,

We'll add this to our todolist, There is currently no mechanism that can handled this unfortunately.

Ok, thanks.

This feature can help me very much.