Subject Re: [IBO] IB_Edit and computed value.
Author Helen Borrie
At 10:07 AM 02-05-01 +0100, you wrote:
>I have a Form where the operator has to enter the customer's Height in cms.
>I have done this with a vertical trackbar, which on change converts its position into a height in cm (and ft and inches) which is shown on a label beside the trackbar. The operators like this. (It is much quicker than entering from the keyboard or using a spin-edit, and they can look at feet and inches if they wish although cm is what is stored).
>The values are inserted into the data record when a 'check' button is pressed.
>Now I am trying to convert to use data-aware controls instead.
>So I have the idea to put the height in cms as calculated into an Ib_Edit.text instead of a label and link that to the dataset directly. Alas this does nothing !
>In fact if I click on the Edit it simply copies back the old value out of the dataset.
>So what I need to know is what action normally causes the Edit.Text to be passed to the dataset ?

I don't know the TTrackbar component but...presumably you already have a handler on it to calculate the value you want to "transfer to the IB_Edit".

Remember that it's the dataset fields that give the value to the IB_Controls, not the other way around. As soon as you give the new value to the dataset field, it will show up in the IB_Edit (complete with any masking attributes you have given it at design time). You don't have to do anything yourself with the control's Text property.

Let's say your handler routine gets a value from the trackbar, does the calculation and puts a value into MyVariable..and the dataset is qryMyData...

with qryMyData do
if not(State = dssEdit) then //and maybe other tests
if State = dssEdit then
FieldByName('Height').AsFloat := MyVariable
// fix up whatever is preventing the edit


>(The dataset is from an ib_query with sql * and 'for update' and of course the source and 'height' field linked to the ib_edit.)

I still can't get to the bottom of why people want to use the 'for update' clause in their SQL. I believed FOR UPDATE was only valid for updating database cursors and wasn't valid in DSQL...but people do seem to use it in DSQL without getting invalid token errors...I don't know what it gives you that the encapsulated Edit doesn't; and it precludes you from using the statement for inserting.

I'm not saying it's wrong: just wondering if it is some undocumented feature that gives some benefit.

>I can use the TTrackbar event of 'on stop drag' to invoke this action but what is it ? Is is 'lose focus', but the edit has never had the focus ?! Is it Tab keyed ?

The process you describe here wouldn't require focus, would it? Presumably, if you don't have the column set READONLY in ColumnAttributes, the user could still use Tab or the mouse to go to the control and alter or enter a value, as an alternative or follow-up to setting the value using the trackbar. In this case, you still don't have to do anything to make this do the right thing - except to ensure that the dataset is in Edit mode, of course.


All for Open and Open for All
InterBase Developer Initiative ยท