> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Alex Kouznetsov
> Sent: Monday, 21 August 2000 19:46
> To: Multiple recipients of list delphi
> Subject: [DUG]: Trying to work with time portion of TDateTime
>
>
> Hi
>
> I need to work exclusively with the the time portion of a TDateTime field.
>
> I set its DisplayFormat := 'hh:nn';
>
> It looks OK until I click on the edit box. Then I get full unformatted
> datetime value displayed (eg. 30/12/99 14:15:00).
The easiest way to do this is to create a persistent field and then use its
GetText and SetText event handlers.
Here is an example from an application I wrote where I had to have complete
control over the formats in the field. In this case the GetText is used to
control the display format while editing and the SetText is used to allow
the user to type a '.' instead of ':' when inputting time (so they can use
the keypad)>
procedure TStaffData.CommonTimeFieldGetText(Sender: TField;
var Text: String; DisplayText: Boolean);
var t:TDateTime;
begin
if(not(Sender.IsNull))
then
begin
t:=Sender.AsDateTime;
Text:=FormatDateTime('h:nn',t);
end
else Text:='';
DisplayText:=false;
end;
procedure TStaffData.EmergencySupportEmergSupportHoursSetText(
Sender: TField; const Text: String);
var P:integer;
H,M:string;
begin
//Scan for delimiter
P:=Pos(':',Text);
if (P=0) then
P:=Pos('.',Text);
if (P<>0) then //Process delimited string
begin
H:=Copy(Text,1,P-1);
M:=Copy(Text,P+1,Length(Text)-P);
if H='' then
H:='0';
if length(M)=1 then
M:=M+'0';
Sender.Value:=H+TimeSeparator+M;
end
else Sender.Value:=Text+TimeSeparator+'00'; //Pass through hours on
their own
end;
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz