Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
A Better TDateTimePicker Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
22-Nov-02
Category
VCL-General
Language
Delphi 4.x
Views
64
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

A Better TDateTimePicker

Answer:

Although the TDateTimePicker component is quite useful sometimes (I still prefer my 
own date-picking components), it lacks an important feature: the ability to set 
your own date/time format, or even a mix of both. It's restricted to the two 
Windows date/time format: the short and the long format. With that on my mind, I 
wrote a TDateTimePicker descendant, TASDateTimePickerEx that will allow you to 
change the format of the component to whatever you want. Without further delay, 
here's the code for the new component:

1   unit ASDTPickEx;
2   
3   interface
4   
5   uses
6     Windows, Classes, ComCtrls;
7   
8   type
9     TASDateTimePickerEx = class(TDateTimePicker)
10    private
11      FFormatStr: string;
12      procedure SetFormatStr(AValue: string);
13      { Private declarations }
14    protected
15      { Protected declarations }
16    public
17      constructor Create(AOwner: TComponent); override;
18      { Public declarations }
19    published
20      property FormatString: string read FFormatStr
21        write SetFormatStr;
22      { Published declarations }
23    end;
24  
25  procedure register;
26  
27  implementation
28  
29  uses CommCtrl;
30  
31  procedure register;
32  begin
33    RegisterComponents('New', [TASDateTimePickerEx]);
34  end;
35  
36  constructor TASDateTimePickerEx.Create(AOwner: TComponent);
37  begin
38    inherited;
39    FFormatStr := 'MM/dd/YYYY';
40  end;
41  
42  procedure TASDateTimePickerEx.SetFormatStr(AValue: string);
43  begin
44    try
45      Perform(DTM_SETFORMAT, 0, longint(pchar(AValue)));
46      FFormatStr := AValue;
47    except
48      Perform(DTM_SETFORMAT, 0, longint(pchar(FFormatStr)));
49    end;
50  end;
51  
52  end.

  
After installing the component (it has been tested on both Delphi 3 and 4), you can 
play with the FormatString property, by assigning it values like 'ddd, 
MMMM/dd/yyyy', or whatever you want. I mean, you can create whatever format you 
want for either the date or the time.

Download source 
code
http://www.bhnet.com.br/~simonet/archive/asdtpickex.pas

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC