Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On select begin at begin of TDateTimeField

Status
Not open for further replies.

Pietjeparasietje

Programmer
Jun 13, 2005
55
NL
I know I've asked it before but I reaaly like to know how to fix this.

Ive got 3 dateTimePickers everytime I select one I want to start at the beginning of this Time.
Right now if you have a time like this : " 08:45 AM " and I change the "45", then once I select the object again the "45" is selected. I want to select the "08" or just the begin every time a object is entered.
Hope someone knows how to do this.
Maybe there some visual component that can fix this, I don't care if it'll cost me some money. If I'm not clear enough please let me know!

Thnx Peter
 
As far I can see this is standard control behaviour, I did not find a function on MSDN to alter the "field" selection in the DateTimePicker. Try to find some third party component (I searched a bit but didnt find one that behaves like DateTimePicker). or you can make one yourself using a TMaskEdit and Implement the OnKeyDown/OnMouseDown events.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I thought about the onKeyDown event as well but wasn't able to fix it.
And I searched for a third party component as well. But without succes, I thought this would be a problem that isn't so rare....
It's just irritating that when your 'tabbing' around the components that it doesn't automticly select the beginning.
Anyone else got a bright idea?
 
The alternative, if your not happy about the behaviour is to create either create your own control, or for the less ambitious, use two spin controls (with appropriate upper and lower limits) and pass the values to the [tt]encodetime[/tt] function.

Its not the most elegant solution, and for time functions is easily controlled (ie no messy leap years etc to deal with)

In the example, I've put on a blank form, put 2 SpinEdit components, a button and a label.
I set [tt]SpinEdit_hour.maxvalue[/tt] to 23, and [tt]SpinEdit_minute.maxvalue[/tt] to 59.
viz:
Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, DateUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin;

type
  TForm1 = class(TForm)
    SpinEdit_hour: TSpinEdit;
    SpinEdit_minute: TSpinEdit;
    B_Time: TButton;
    L_time: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    procedure B_TimeClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.B_TimeClick(Sender: TObject);
var
  myTime : tDateTime;
begin
  myTime := encodetime(SpinEdit_hour.Value,SpinEdit_minute.Value,0,0);
  L_time.Caption := TimeToStr(myTime);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SpinEdit_hour.Value := hourof(now);
  SpinEdit_minute.Value := minuteof(now);
end;

end.
This example will load the spin edit with the current time, and let you modify it. When you click the time, it displays the selected value.


Cheers,
Chris [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top