Subject [IBO] Re: IB_Date.NormalCellColor
Author mmenaz
--- In IBObjects@y..., Geoff Worboys <geoff@t...> wrote:
> Hi Marco & Guido,
>
> I was just taking a quick look at this code and I have a few
> questions...
>
> > procedure TIB_CustomDate.KeyPress(var Key: Char);
> ...
> // I understand this, process if unbound or if bound and can
> // modify. You probably should be checking the "AllowUnboundEdits"
> // property - and maybe even the readonly property - as well.
> // (but then there are a few places where the code in IB_Date
> // is inconsistent in regard to unbound edits)

I'm not a IBO guru, I've read IBO code (maybe old IB_Date) and see that this is the one used in this situations. If I recall correctly, in IB_Date AllowUnboundEdits is always true.

> // I dont understand this...
> if (Key = char(VK_SPACE)) or
> (((Text = FormatMaskText( EditMask, '' )) or
> (EditText = SelText)) and (Key in [ '0'..'9' ])) then
> begin
>
> // Dont you want something more like...
> // - let number keys be processed by normal mask processing
> // - only accept space when control is empty or all text selected
> if (Key = char(VK_SPACE)) AND
> ( (Text = FormatMaskText( EditMask, '' )) or
> (EditText = SelText) ) then

Not exactly. I want auto-fill when:
a) you press spacebar. This meand "I *DO* want the date, don't check nothing else"
b) the control is empty or is all selected and I start typing a number. This means: "I want to enter a date, please help me filling it with a default (now), so I could save some typing"
With your code, if the control is empty and I press "x", then the date if filled. With mine, I have to enter a number to fire it.

>
> You may even be safer to only accept VK_SPACE only when all text is
> selected - so space can still be used during normal edit input.

Do you think that space could ever be useful in a date control? This could be, but could make more difficoult to understand the "space" shortcut (customer: "hey, space is not working here!" programmer "is the control empty or all selected?" cutomer "what do you mean?"...

>
> Better yet may be the idea of using one or more shortcut properties on
> the control - allowing people to define their own "TodayShortcut" or
> even disabling the option altogether. This makes it harder to use
> simple character/keypress keys like space - although you may be able
> to get it to work using KeyUp instead of KeyDown.

I hate adding unnecessary properties. My intention was to provide a function that is or useful or not damaging, so no one would have to disable it.
I've received an e-mail from Guido while I was writing these lines that made me aware that he is using the control without edit mask!
So I will have to fire autofill only if an edit mask is defined, so you can enter something like 5/4/02 without having to delete what autofill provided.


>
> Note also that I think you should avoid calling
> SysUpdateData( Field );
> from inside KeyPress etc. (I see you have removed that in the code
> you posted). Remember that the standard processing of data-aware
> controls is NOT to post changes to the field-buffer until exit (or
> told to by the datasource). This allows people to reset the contents
> of the control (re-read the previous value from the field buffer) by
> pressing escape.

Thank you very much for this suggestion.

>
> Just some thoughts - I have not actually experimented with this.
>

I've sent a fix to Jason for the code that is D6 dependent, and now I will work to:
a) let space bar being used (your suggestions, but not adding a shortcut property)
b) don't fire autofill if no edit mask is set

May I e-mail you privately for a test of the code, when done?
Thanks a lot, Geoff (and Guido too)
Marco Menardi