Чтение онлайн

ЖАНРЫ

Советы по Delphi. Версия 1.4.3 от 1.1.2001

Озеров Валентин

Шрифт:

Надеюсь, что помог вам.

unit Forma;

interface

uses

 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls;

type

 TForma1 = class(TForm)

Edit1: TEdit;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

GetWeekBtn: TButton;

Label4: TLabel;

procedure GetWeekBtnClick(Sender: TObject);

procedure FormCreate(Sender: TObject);

 private { Private declarations }

Function HowManyDays(pYear,pMonth,pDay:word):integer;

 public { Public declarations }

 end;

var

 Forma1: TForma1;

implementation

 {$R *.DFM}

Uses Inifiles;

procedure TForma1.FormCreate(Sender: TObject);

 var WinIni:TInifile;

begin

 WinIni:=TIniFile.Create('WIN.INI');

 WinIni.WriteString('intl','sShortDate','MM/dd/yyyy');

 WinIni.Free;

end;

Function TForma1.HowManyDays(pYear,pMonth,pDay:word):integer;

 var Sum:integer;

 pYearAux:word;

begin

 Sum:=0;

 if pMonth>1 then Sum:=Sum+31;

 if pMonth>2 then Sum:=Sum+28;

 if pMonth>3 then Sum:=Sum+31;

 if pMonth>4 then Sum:=Sum+30;

 if pMonth>5 then Sum:=Sum+31;

 if pMonth>6 then Sum:=Sum+30;

 if pMonth>7 then Sum:=Sum+31;

 if pMonth>8 then Sum:=Sum+31;

 if pMonth>9 then Sum:=Sum+30;

 if pMonth>10 then Sum:=Sum+31;

 if pMonth>11 then Sum:=Sum+30;

 Sum:=Sum + pDay;

 if ((pYear - (pYear div 4)*4)=3D0) and (pMonth>2) then inc(Sum);

 HowManyDays:=Sum;

end; { HowManyDays }

procedure TForma1.GetWeekBtnClick(Sender: TObject);

var

 ADate: TDateTime;EditAux:String;

 Week,year,month,day:Word;

begin

 EditAux:=Edit1.Text;

 ADate := StrToDate(EditAux);

 Label1.Caption := DateToStr(ADate);

 DecodeDate(Adate,Year,Month,Day);

 Case DayOfWeek(ADate) of

1: Label4.Caption:='Воскресенье';

 2: Label4.Caption:='Понедельник';

 3: Label4.Caption:='Вторник';

 4: Label4.Caption:='Среда';

 5: Label4.Caption:='Четверг';

 6: Label4.Caption:='Пятница';

 7: Label4.Caption:='Суббота';

 end

Week:=(HowManyDays(year,month,day) div 7) +1;

 Label3.Caption:='Неделя No. '+IntToStr(Week);

end;

end.

Количество

дней между двумя датами I

Delphi 1

ПЕРЕМЕННЫЕ:

Year1, Month1, Day1,

Year2, Month2, Day2,

YearResult, MonthResult, DayResult: Word;

TDay1, TDay2, DateDiff: TDateTime;

КОД:

TDay1 := EncodeDate(Year1, Month1, Day1);

TDay2 := EncodeDate(Year2, Month2, Day2);

DateDiff := TDay2 – TDay1; {предположим, что TDay2 позднее, чем TDay1}

DecodeDate(DateDiff, YearResult, MonthResult, DayResult);

DateDiff имеет тип LongInt (хотя и является объектом TDateTime), и содержит количество дней между датами.

Количество дней между двумя датами II

Delphi 1

Для DateDiff:

Вы смотрели на функцию DecodeDate? Это не точно именно то, что вам нужно, но на ее основе можно сделать вашу функцию именно с нужной вам функциональностью.

Для величины Present:

function PresentValue(const cashflows : array of double; { отсортированные транзакции, начальный индекс - cashflows[0] }

Поделиться с друзьями: