Validating objects by their constraints

You may have noticed by now that by default Bold will allow you to save objects with invalid constraints. Here is a solution.

Override MayUpdate in your base class (BusinessClassesRoot in this example) and include the following code....

function TBusinessClassesRoot.MayUpdate: Boolean;


  I: Integer;

  Errors: TStringList;

  IE: TBoldIndirectElement;

  List: TBoldList;


  IE := TBoldIndirectElement.Create;

  Errors := TStringList.Create;



      EvaluateExpression('constraints->select(c| not c)', IE);

      List := IE.Value as TBoldList;

      for I := 0 to List.Count - 1 do


      Result := (Errors.Count = 0);

      if not Result then



        SetBoldLastFailureReason(TBoldFailureReason.Create(Errors.Text, Self));



      Result := False;








If an attempt is made to save an object with broken constraints an error will occur.


Share this article!

Follow us!

Find more helpful articles: