以下是这段程序:
unit InputDateTimeUnit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons;type
TGetTimeForm = class(TForm)
DateMC: TMonthCalendar;
TimeP: TPanel;
TimeDTP: TDateTimePicker;
Label1: TLabel;
OkBitBtn: TBitBtn;
CancelBitBtn: TBitBtn;
private
{ Private declarations }
public
{ Public declarations }
end;var
GetTimeForm: TGetTimeForm;
function GetMyDateTime: TDateTime; stdcall;
implementation{$R *.dfm}1 Function GetMyDateTime: TDateTime;
2 var
3 Temp:string;
4 begin
5 result:=Now;
6 try
7 GetTimeForm:=TGetTimeForm.create(Application);
8 try
9 with GetTimeForm do
10 begin
11 if ShowModal=mrOK then
12 begin
13 Temp:=DateToStr(DateMC.Date)+''+TimeToStr(TimeDTP.Time);
14 result:=StrToDateTime(Temp);
15 end;
16 end;
17 finally
18 GetTimeForm.Free;
19 end;
20 except
21 on E: Exception do
22 MessageDlg('DLL出现错误:'+E.Message, mtError,[mbOK],0);
23 end;
24 end;
25 end.
以上程序中,第4句“result:=Now;”中“result”都没有定义过变量为什么在这里可以使用的,还是一个日期变更,“NOW()”函数是取系统时间吧。我不明“result”怎么用得了。
还有可以帮我说明每一句程序作用吗?谢谢大家了。
unit InputDateTimeUnit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons;type
TGetTimeForm = class(TForm)
DateMC: TMonthCalendar;
TimeP: TPanel;
TimeDTP: TDateTimePicker;
Label1: TLabel;
OkBitBtn: TBitBtn;
CancelBitBtn: TBitBtn;
private
{ Private declarations }
public
{ Public declarations }
end;var
GetTimeForm: TGetTimeForm;
function GetMyDateTime: TDateTime; stdcall;
implementation{$R *.dfm}1 Function GetMyDateTime: TDateTime;
2 var
3 Temp:string;
4 begin
5 result:=Now;
6 try
7 GetTimeForm:=TGetTimeForm.create(Application);
8 try
9 with GetTimeForm do
10 begin
11 if ShowModal=mrOK then
12 begin
13 Temp:=DateToStr(DateMC.Date)+''+TimeToStr(TimeDTP.Time);
14 result:=StrToDateTime(Temp);
15 end;
16 end;
17 finally
18 GetTimeForm.Free;
19 end;
20 except
21 on E: Exception do
22 MessageDlg('DLL出现错误:'+E.Message, mtError,[mbOK],0);
23 end;
24 end;
25 end.
以上程序中,第4句“result:=Now;”中“result”都没有定义过变量为什么在这里可以使用的,还是一个日期变更,“NOW()”函数是取系统时间吧。我不明“result”怎么用得了。
还有可以帮我说明每一句程序作用吗?谢谢大家了。
比如:GetMyDateTime := Now;
只不过给result赋值后程序还会执行后面的代码,而给函数名赋值后程序直接跳出,不在执行后面的代码。
相当于 Result := Now; Exit;你的代码没有什么可解释的,就是创建一个模式窗体,如果返回mrOK,函数就返回日期控件设定的日期时间,否则就返回当前日期时间。