Subject Re: [IBO] Still having problems with OnCalculateField
Author Helen Borrie
At 10:18 AM 15/01/2004 +0000, you wrote:

>maybe I'm not explaining myself very well here. the problem is that
>we have FORENAME as a CHAR (15) and SURNAME as a CHAR (30). If we
>store the following information in these 2 fields:
>then have a TIB_Query that returns both these fields - i.e.
>if you do:
>('FORENAME').AsString+' '+IB_Query.FieldByName('SURNAME').AsString)
>then it (correctly) returns:
>"Stuart Hunt". i.e. it doesn't pad the fields out to their maximum
>If, however, you add a calculated field to the
>TIB_Query.CalculatedFields property of:
>then put the following code into the OnCalculateField event:
>ShowMessage(ARow.ByName('FORENAME').AsString+' '+ARow.ByName
>then it (incorrectly) returns:
>"Stuart Hunt "
>in other words, in this event (and it seems only in this event) the
>AsString method is padding the field out to its maximum width. I've
>put together a very simple database and example application that
>shows this that I can send if it would help.

No, not necessary, I think I understand what's the issue here. This is
happening because the event is reading the raw SQL data from each Row
object as it crosses the threshold. IOW, it might be happening before the
field-level trimming for the datalink. (Trimming doesn't alter the stored
data, only the displayed data). I think you'll need to use TrimRight.

Personally, I wouldn't generally use a calculated field for this at all -
I'd get it as a run-time column in the SQL.

But using a calc field might be useful if you know you have some nulls in
those columns...and they do have the benefit that you can call
CalculateFields to update them in the buffer...