當前位置:編程學習大全網 - 編程軟體 - delphi7編程 從鍵盤輸入年份月份 輸出對應月的天數 代碼怎麽寫?

delphi7編程 從鍵盤輸入年份月份 輸出對應月的天數 代碼怎麽寫?

完全利用函數實現輸入年份月份實現輸出對應月的天數估計很難,因為delphi裏沒有只有年和月的分解時間函數,不過可以通過其他方法實現妳的要求.

以下是輸入年月日來實現的,妳可以通過界面輸入控制上加上默認的日這個值即可.

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Edit1: TEdit;

Edit2: TEdit;

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

function GetCurrDay(CurrDate: TDateTime): Integer;

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

function Tform1.GetCurrDay(CurrDate: TDateTime): Integer;

var

Year,Month,Day:word;

TempDate : TDateTime;

begin

DecodeDate(CurrDate,Year,Month,Day);

if Month=12 then

Result := 30

else

begin

TempDate:=EncodeDate(Year,Month+1,1)-1;

DecodeDate(TempDate,Year,Month,Day);

Result:=Day;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

Edit2.text:=IntToStr(GetCurrDay(StrToDateTime(Edit1.Text)));

end;

end.

  • 上一篇:10年大眾寶來升降器怎麽匹配
  • 下一篇:鎮江齊航數控機床科技有限公司怎麽樣?
  • copyright 2024編程學習大全網