Subject Re: [IBO] Event CalculatedFields
Author Paulo Henrique Albanez
Thanks Jason.

I did the modifications, but even so it continues calling 3 times the event , when I run a Post in the table CadMaq, being the last with the value in white.

This this correct?

PHA

// Example

procedure TDatMaq03.MaqProdCalculateField(Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);
begin
inherited;
if AField.FieldName = 'DESCRICAO' then begin
if sProduto <> ARow.ByName('Produto').AsString then begin
sProduto := ARow.ByName('Produto').AsString;
EstCad.Params[0].AsString := sProduto;
EstCad.Open;
sDesEst := EstCad.FieldByName('Descricao').AsString;
EstCad.Close;
end;
AField.AsString := sDesEst;
end;
end;

----- Original Message -----
From: Jason Wharton
To: IBObjects@yahoogroups.com
Sent: Friday, May 25, 2001 5:12 PM
Subject: Re: [IBO] Event CalculatedFields


There is something ambiguous about your code that is probably causing the
problem.
You should be more explicit.

procedure TDatMaq03.MaqProdCalculateField(Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);
begin
inherited;
if AField.FieldName = 'DESCRICAO' then begin
if EstCad.Params[0].AsString <> ARow.ByName('Produto').AsString then
begin
EstCad.Close;
EstCad.Params[0].AsString := ARow.ByName('Produto').AsString;
EstCad.Open;
end;
AField.AsString := EstCad.FieldByName('Descricao').AsString;
end;
end;

I really don't even like what is above here because it leaves a dataset in a
partially fetched state. You should make it more (physical) transaction
friendly by storing the Param and the returned value in variables local to
the data module or form. Such that it looks like this:

procedure TDatMaq03.MaqProdCalculateField(Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);
begin
inherited;
if AField.FieldName = 'DESCRICAO' then
begin
if EstCadParam <> ARow.ByName('Produto').AsString then
begin
EstCad.Close;
EstCadParam := ARow.ByName('Produto').AsString;
EstCad.Params[0].AsString := EstCadParam;
EstCad.Open;
EstCadValue := EstCad.FieldByName('Descricao').AsString;
EstCad.Close;
end;
AField.AsString := EstCadValue;
end;
end;

I don't know what else you are doing with EstCad but from what I can see you
are trying to optimize in a way that leaves a cursor open all the time. This
is not healthy for InterBase because this also forces it to keep a
transaction open all the time.

The way I have done it has the same optimization benefit as you were
receiving but it won't leave the cursor open.

HTH,
Jason Wharton
CPS - Mesa AZ
http://www.ibobjects.com


----- Original Message -----
From: "Paulo Henrique Albanez" <pha@...>
To: <IBObjects@yahoogroups.com>
Sent: Friday, May 25, 2001 1:05 PM
Subject: Re: [IBO] Event CalculatedFields


> ARow
>
> 3.6.Dg
>
>
> procedure TDatMaq03.MaqProdCalculateField(Sender: TIB_Statement;
> ARow: TIB_Row; AField: TIB_Column);
> begin
> inherited;
> if AField.FieldName = 'DESCRICAO' then begin
> if EstCad.Params[0].AsString <> ARow.ByName('Produto').AsString then
begin
> EstCad.Params[0].AsString := ARow.ByName('Produto').AsString;
> if not (EstCad.Active) then EstCad.Open;
> end;
> AField.AsString := EstCad.FieldByName('Descricao').AsString;
> end;
> end;
>
> PHA
> ----- Original Message -----
> From: Jason Wharton
> To: IBObjects@yahoogroups.com
> Sent: Friday, May 25, 2001 4:06 PM
> Subject: Re: [IBO] Event CalculatedFields
>
>
> Are you using ARow in the event handler or FieldByName()?
>
> Be sure to use ARow.ByName() instead.
>
> What version of IBO are you using?
>
> Jason Wharton
> CPS - Mesa AZ
> http://www.ibobjects.com
>
>
> ----- Original Message -----
> From: "Paulo Henrique Albanez" <pha@...>
> To: <IBObjects@yahoogroups.com>
> Sent: Friday, May 25, 2001 12:06 PM
> Subject: [IBO] Event CalculatedFields
>
>
> > Because the event CalculatedFields is called several times when metodo
> Post is run, and because that occurs before the event AfterPost and not
> after, I am having problems for cause of this.
> >
> > PHA
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
> >
> >
>
>
> Yahoo! Groups Sponsor
>
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


Yahoo! Groups Sponsor



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



[Non-text portions of this message have been removed]