Subject | Re: TIB_Grid Field Validation and Totals |
---|---|
Author | Marco Menardi |
Post date | 2002-11-21T17:37:58Z |
I can answer only to question 2:
--- In IBObjects@y..., "Bob" <rcmiszuk@y...> wrote:
> I need some advise on handling tib_grids.
[cut]
> 2. The user enters values in a column which is then totalled, but if the
> total that the user entered is greater than the total allowed,
change the
> user's input either back to zero or to the maximum that they'd be
allowed to
> enter. My difficulties appeared to be in calculating the total: a SP
on the
> server would not operate on the data in the grid, but if I operated
on the
> tib_query that the grid pointed to I would lose track of where the
user was
> in the grid and start firing off events left and right while I iterated
> through the dataset to recalc the total. I'm not sure what event to
tie to.
You have to set the query with FetchAllRows to true, so the entire
dataset you want to totalize is retrieved and buffered.
Then, you can navigate the query buffer leaving the current record the
same (and the grid position).
this is a fragment of code stolen from my program (in italian...)
var
tmpColDare, tmpColAvere: TIB_Column;
tmpCurrentBufferPos: longint;
TotDare, TotAvere, Sbilancio: currency;
begin
TotDare := 0;
TotAvere := 0;
with qryMovConRighe do
begin
tmpColDare := BufferFieldByName( 'DARE' );
tmpColAvere := BufferFieldByName( 'AVERE' );
tmpCurrentBufferPos := BufferRowNum;
BufferFirst;
while not BufferEOF do
begin
TotDare := TotDare + tmpColDare.AsCurrency;
TotAvere := TotAvere + tmpColAvere.AsCurrency;
if (FOwner as TfrmPrimaNota).Causale.REGISTRA_RIGHE_ZERO then
Inc( RigheInseriteAmmesse )
else if ((tmpColDare.AsCurrency<>0) or
(tmpColAvere.AsCurrency<>0)) then
Inc( RigheInseriteAmmesse );
BufferNext;
end;
BufferRowNum := tmpCurrentBufferPos;
end;
As far as I remember, I had to set the BufferRowNum back to the
original position because of some problem. I don't know if this is
correct or if it was a bug of IBO now fixed, anyway this way it works :)
regards
Marco Menardi