Hi, Frederic
You can set a string of blanks (actually one would be enough) to the
Format property of the DateTimePicker:
Format:=' ';
or
Format:=' . . ';
and you should get an empty editing field.
Best regards, Serge Gubenko
Well, I'm sure you haven't tried it...
There isn't a format property in a TDateTimePicker. There is a DateFormat
property of this type. TDTDateFormat = (dfShort, dfLong);
Here's what Delphi 6 help says about Format:
___________________________________
TDateTimePicker.Format
{...}
Specify format for date-time string.
property Format: String;
Description
Format specifies custom format string for the date-time display, overriding
the control panel strings. A custom format can include both date and time
fields, but time fields are not editable unless the Kind property is
dtkTime....
{..}
____________________________________
regards
Looks like Format is a new property to D6, so if you're working with
elder version you should something like this:
var
XFormat: string;
begin
XFormat:=' ';
SendMessage(DateTimePicker1.Handle, DTM_SETFORMAT,
0, integer(PChar(XFormat)));
{or}
SendMessage(Handle, DTM_SETFORMAT, 0, integer(PChar(XFormat)));
{if you're going to set format in the internal methods of TDateTimePicker
descendant class}
DTM_SETFORMAT constant is declared in the Commctrl unit
regards
I think this is because you are storing and reading the DateTime field
asociated with DBDateTimePicker in DateTime format. When you store a
blank date, you have to do something like this:
FieldByName('DateTimeFieldName').Clear
and when you read the field, do it like this:
sDateTime := FieldByName('DateTimeFieldName').AsString;
if sDateTime = '' then ...
so you can see if it´s a blank date.
--
JAM - Relájate y disfruta...
procedure TJvDBDateTimePicker.DataChange(Sender: TObject);
var
lsFormat:string;
begin
if FDataLink.Field <> nil then
Date := FDataLink.Field.AsDateTime
else if csDesigning in ComponentState then
Date := Date;
if Assigned(FDataLink.Field) then
if FDataLink.Field.IsNull then
lsFormat:=' ';
// always send the message: lsFormat will be ''
SendMessage(Handle, DTM_SETFORMAT, 0, integer(PChar(lsFormat)));
end;
This works great. I get an empty string for null value. But when I input
data by dropping down the calendar, nothing appears. The data is correctly
affected, but it doesn't appear in the control. If I post the dataset at
this moment, the data appears and then everything is correct until I get
another null value. Then, you have to post to get the data displayed.
Any hint?
Hi, Frederic
Seems, you should return empty format string to your control
when user drops down a calendar:
___________________________________________
TMyDateTimePicker = class(TDateTimePicker)
protected
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
procedure SetFormat(const AValue: string);
end;
procedure TMyDateTimePicker.CNNotify(var Message: TWMNotify);
begin
inherited;
with Message do begin
case NMHdr^.code of
DTN_DROPDOWN:
SetFormat('');
DTN_CLOSEUP:
if DateTime=0 then SetFormat(' ');
end;
end;
end;
procedure TMyDateTimePicker.SetFormat(const AValue: string);
begin
SendMessage(Handle, DTM_SETFORMAT, 0, integer(PChar(AValue)));
end;
_____________________________________________
Best regards, Serge Gubenko
Hi,
You can try to set format in the handlers of WM_SetFocus,
WM_KillFocus and WM_KeyDown messages.
Here's an example:
____________________________________________
TMyDateTimePicker = class(TDateTimePicker)
protected
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMSetFocus); message WM_KILLFOCUS;
procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
procedure SetFormat(const AValue: string);
end;
procedure TMyDateTimePicker.WMSetFocus(var Message: TWMSetFocus);
begin
inherited;
SetFormat('');
end;
procedure TMyDateTimePicker.WMKillFocus(var Message: TWMSetFocus);
begin
inherited;
if DateTime=0 then SetFormat(' ');
end;
procedure TMyDateTimePicker.WMKeyDown(var Message: TWMKeyDown);
begin
SetFormat('');
inherited;
Christopher Latta
Frederic Gelinas <fgel...@si.qc.ca> wrote in message
news:3be838f9_2@dnews...
BTW, A BIG thanks for your help!
Hi, Frederic
Seems, we need to change the SetFormat procedure.
Here's how it might look like:
TMyDateTimePicker = class(TDateTimePicker)
protected
FFormat: string;
{..}
procedure SetFormat(const AValue: string);
end;
procedure TMyDateTimePicker.SetFormat(const AValue: string);
begin
if FFormat<>AValue then begin
FFormat:=AValue;
SendMessage(Handle, DTM_SETFORMAT, 0, integer(PChar(AValue)));
end;
end;
Best regards, Serge Gubenko
> One thing to say: Thanks a lot!
> I (you) finally get it to work properly!
>
Hi,
So, how does the final code look like ?
I was just going to ask about the same thing when i saw your message.
Are you able to share the component ?
There are many similar components in Torry's and other places but they
all have the same problem in their behaviour.
Juha Manninen
--
Frederic Gelinas
www.si.qc.ca
"Juha Manninen" <juha.m...@datex-nospam-ohmeda.com> a écrit dans le
message news: 3BF93522...@datex-nospam-ohmeda.com...
> Sent by email...
>
Sorry, I think there was the 'nospan' included in my address.
Can you please resend it to : juha.m...@datex-ohmeda.com
Thanks in advance.
Juha