Subject Re: [IBO] Re: IB_Date.NormalCellColor
Author Geoff Worboys
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)
if (not Assigned( Field )) or
(Assigned( Field ) and (DataLink.Modify)) then
begin
// 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

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.

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.

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.

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

--
Geoff Worboys
Telesis Computing