When the DBEdit receives focus the displayed value (in the InplaceEditor)
behaves strangely. For example 00:00 displays as 99:__, and 10:44 displays
as 10:00 (minutes set to zero).
Looking more closely this seems to be a bug in the PadInputLiterals routine
of the Mask unit, but I don't know enough to fix it. Would the experts like
to have a look at this behaviour, I'm using D5 so maybe there is a fix in
later versions?
Otherwise any advice on a simple data aware control for entering time as
hours and minutes (not DateTimePicker as that has already given users
problems).
Dave
The underlying routines can not cope with removing both leading and trailing
extranious text. Same routines are used by all decendants of
TCustomEditMask, hence InplaceEditor of DBGrid, DBEdit etc. They will all
display weird things if you use a mask to get text from the middle of a
string. Sounds like a (yet another) longstanding bug in Mask unit to me
So mask use is out. How do I enter hours and minutes to my DateTime field?
Dave
You may be able to use DisplayFormat on the TField descendent.
Or OnGetText / OnSetText on the TField plus a Mask.
I've never needed to do what you're trying to do so I can't offer
anything more concrete.
Good luck, Brian
Thanks for your reply Brian.
TField.DisplayFormat = "HH:MM" used to display existing values, but EditMask
will not work to control data entered by user. EditMask processing uses the
text property, not the displaytext, hence gets a datetime string like
"12/03/2005 10:57:03" and can not remove both leading (date) and trailing
(seconds) extraneous characters. You can not get hours and minutes from a
full datetime string using a mask.
Not sure what to do with TField.OnGetText / OnSetText. Perhaps what I could
do is control the way the user edits the hours and minutes on the
TDBEdit.OnKeyPress. I feel like I am reinventing the wheel!
Dave
As Datatype = ftDateTime the field text property contains date and time,
this gives problems.
a) No matter how the underlying field displayformat is set, DBEdit shows
full date and time whenever is has focus.
b) You can not get hours and minutes from a full datetime string using a
mask, hence EditMask does not work.
c) A date string can be entered instead of hours and minutes.
Instead use field OnGetText and OnSetText events.
procedure TForm1.TimeFieldGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
Text := FormatDateTime('hh:nn', sender.AsDateTime);
end;
procedure TForm1.TimeFieldSetText(Sender: TField; const Text: String);
var
t: TDatetime;
begin
try
t := StrToTime(text); //Prevents date entry as time
sender.asdatetime := t;
except
on e : exception do begin
sender.FocusControl;
raise;
end;
end;
end;
Dave Blake