function [status,errMsg] = udtDDGPreApply(blockObj,dlg)
% udtDDGPreApply(blockObj)
%   validates changes made in a block's Dynamic Dialog
%   and then applies the changes if valid
%  
%   blockObj = top-level UDD object for the block (the one
%              that getDialogSchema() is called on)
%  
%   returns the status (0 = failed) and error message if failed
%
%  This function is intended to be used in the getDialogSchema
%  function:
%
%  function dlgstruct = getDialogSchema(h, name)
%    % construct schema
%    dlgstruct.PreApplyCallback = 'udtDDGPreApply';
%    dlgstruct.PreApplyArgs = {h};

% Copyright 2003-2009 The MathWorks, Inc.

% first we validate changes
errMsg = blockObj.validateChanges;

% If they are valid, we apply them
if ~isempty(errMsg)
  status = 0;
else
  [status,errMsg] = blockObj.preApplyCallback(dlg);
end
