Routine to update database with objects or lists of objects

A simple procedure that accepts a list of bold objects and lists to commit to the database.

Frequently it is necessary to commit a single object or several objects to the database. This procedure accepts a list of objects and object lists, adds them all to a single list and commits them in a single operation.





procedure UpdateDatabaseWithObjects( Objs : array of const );

var

   i : integer;

   bie : TBoldIndirectElement;

   lstObjs : TBoldObjectList;

   currObj : TBoldElement;

begin

   lstObjs := nil;

   bie := nil;

   try

     lstObjs := TBoldObjectList.Create;

     bie := TBoldIndirectElement.Create;



     for i := 0 to Length( Objs )-1 do begin

        currObj := Objs[i].vObject as TBoldElement;



        if not Assigned( currObj ) then

           Continue;



        if not (( currObj is TBoldObject) or ( currObj is TBoldObjectList )) then

           raise Exception.Create( 'UpdateDatabaseWithObjects: can only update TBoldObject or TBoldObjectList' )

        else begin

          currObj.GetAsList( bie );

          lstObjs.AddList( bie.Value as TBoldList );

        end;

     end;



     if lstObjs.count > 0 then

        lstObjs[0].BoldSystem.UpdateDatabaseWithList( lstObjs );

   finally

      lstObjs.Free;

      bie .Free;

   end;

end;

 

Share this article!

Follow us!

Find more helpful articles: