当用户在TDateTimePicker中选择一个值时,我想将要设置的值覆盖到与所选值对应的一周的开始。

我尝试在OnChange事件中设置它,但是在事件结束后立即设置了最初选择的值。

我将如何处理?

最佳答案

使用“ ONCloseUp”事件-该示例适用于我(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 :-)

关于delphi - 用户选择日期时,更正datetimepicker上的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2238221/

10-11 15:21