Subject Re: [IBO] How do I do a row level validation
Author Helen Borrie
At 05:05 PM 31-12-01 +0500, you wrote:
>Hi,
> I am using IBobjects 4.And i have a problem binding the IBO's
>TDataSet decendant IBOQuery to a grid control.
>
>What i am trying to do is :
>
>Bind a woll2woll Grid to IBOQuery which has two required fields.
>
>The problem i am facing is:
>
>When the user fills only one mandatory field and hits down arrow it is
>trying to add a new record and during this time it is raising an exception
>saying "fieldName is Required and can not have empty values".
>
>So,what event should i use to do row level validations.
>
>I have gone through all the events and none seems suitable.
>
>Specific Example:
>
> I have a table called orders which has two mandatory fields
>ReceiptNo and CustomerID.
>
> I declared a IBOQuery and datasource for this table
>in a data module and bound it to a woll2woll Grid.
>
> When user fills in ReceiptNo (not CustomerID) and hits down arrow
>it raises an exception saying EIB_DatasetError With message 'CustomerID
>is a required field'.
>
> So,how do i control this?Can anybody help solving this problem

From the Delphi Help for TDataset:

Write a BeforeScroll event handler to take specific action immediately before an application scrolls to another record as a result of a call to the First, Last, MoveBy, Next, Prior, FindKey, FindFirst, FindNext, FindLast, FindPrior, and Locate methods. BeforeScroll is called before all other events triggered by these methods and any other methods that switch from record to record in the dataset.

procedure TForm1.IBOQuery1BeforeScroll(DataSet: TDataSet);
begin
if {{something isn't valid}} then
begin
{{scold the user }};
Abort; // you need SysUtils in your uses clause to call Abort
end;
end;

Setting DefaultValues (or DefaultExpression) won't help you in this situation since, presumably, each order will have a distinct Customer ID.

Happy New Year!
Helen