tags:

views:

66

answers:

3

Whe a user selects a value in my TDateTimePicker I want to override the to-be-set value to the start of the week that goes with the selected value.

I tried setting it in the OnChange event, but then the originally selected value will be set right after I finished the event.

How would I go about this?

+2  A: 

Use the onUserInput event!

MarkRobinson
Oh I never noticed that existed.
Warren P
A: 

I would post a message to the form, define a message (WM_USER+1000+X), post it, and handle it. If you don't "pend" it like this, you could also do a PendingDateTimeTimer:TTimer that does validation slightly later (say 10msec) after the OnChange event sets PendingDateTimeTimer.Enabled := true.

Warren P
+1  A: 

hi!

use the "ONCloseUp" event - this sample works for me (Delphi 7, WinXP)

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    dtp1: TDateTimePicker;
    btn1: TButton;
    edt1: TEdit;
    procedure btn1Click(Sender: TObject);
    procedure dtp1CloseUp(Sender: TObject);
  private
    { Private declarations }
    procedure SetDayToMonday();
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SetDayToMonday;
begin
   dtp1.DateTime := dtp1.DateTime - DayOfTheWeek(dtp1.DateTime) + 1;
end;

procedure TForm1.dtp1CloseUp(Sender: TObject);
begin
   SetDayToMonday;
end;

end.

--reinhard :-)

pastacool
That worked like a charm, Thx
borisCallens