Page 1 of 1

LocalConstraints / RequiredFields

Posted: Mon 18 May 2015 07:08
by marcodor
Hello Victor,

I'm trying to insert a record locally, later refreshing it from server, without success.
My model allow multiple edit records at once. When some record is updated/inserted, browser dataset gets notified and it should refresh itself.

Code: Select all

  BDataSet.LocalUpdate := True;
  BDataSet.Options.RequiredFields := False; // LocalConstraints := False;
  BDataSet.Insert;
  BDataSet['ID'] := EDataSet['ID'];
  BDataSet.Post;
  BDataSet.RefreshRecord;
  BDataSet.Options.RequiredFields := True; // LocalConstraints := True;
  BDataSet.LocalUpdate := False;
It stuck in "required fields", throwing an exception on Post.
As I see LocalConstraints nor RequiredFields does not help, fields are explicitly defined.
May I somehow disable constraints (fields required) checks to Post record and later enable them back (as i need Field.Required for direct edit in browser dataset grid)?


-
Dorin

Re: LocalConstraints / RequiredFields

Posted: Tue 19 May 2015 08:50
by ViktorV
To solve the problem, try to set the RequiredFields property before opening connection.

Re: LocalConstraints / RequiredFields

Posted: Tue 19 May 2015 09:10
by marcodor
Hello Victor,

User may edit record also directly in a grid browser form for "simple" record, but may opt to edit it also in "editor" form. So keeping Required properties for fields is important.

The question is to disable them just for Post & RefreshRecord period.

Deprecated LocalConstraints will be a perfect match for this case. What do you think?
It should not break some backward compatibility.

Re: LocalConstraints / RequiredFields

Posted: Wed 20 May 2015 10:44
by ViktorV
You can implement the needed functionality by yourself. For example:

Code: Select all

procedure UnRequired(DataSet: TDataSet; var ListField: TStringList);
var
  i: Integer;
begin
  for i := 0 to DataSet.Fields.Count -1 do
    if DataSet.Fields[i].Required then begin
      ListField.Add(DataSet.Fields[i].FieldName);
      DataSet.Fields[i].Required := False;
    end;
end;

procedure Required(DataSet: TDataSet; ListField: TStringList);
var
  i: Integer;
begin
  for i := 0 to ListField.Count -1 do
      DataSet.FieldByName(ListField[i]).Required := True;
end;

var
  ListRequiredField: TStringList;
begin
  ListRequiredField := TStringList.Create;
  BDataSet.LocalUpdate := True;
  UnRequired(BDataSet, ListRequiredField);
  BDataSet.Insert;
  BDataSet['ID'] := EDataSet['ID'];  
  BDataSet.Post;
  BDataSet.RefreshRecord;
  Required(BDataSet, ListRequiredField);
  BDataSet.LocalUpdate := False;
end;

Re: LocalConstraints / RequiredFields

Posted: Thu 21 May 2015 17:33
by marcodor
Hello Victor,
Thanks for spending time, coding this sample.
I implemented this using TList, where elements points directly to TField to speedup access.
Anyway, please consider, maybe it make sense to implement it in your library.
Or something like DisableConstraints/EnableConstraints
Thanks!

Re: LocalConstraints / RequiredFields

Posted: Fri 22 May 2015 10:17
by ViktorV
If you want us to implement the feature, please post it at our user voice forum: http://devart.uservoice.com/forums/1046 ... e-firebird If the suggestion gets a lot of votes, we will consider the possibility to implement it.