算法 - 小挑战(日历) 求比这还简单并清晰的数据对应日历算法(300)(0分)

  • 主题发起人 主题发起人 delp
  • 开始时间 开始时间
D

delp

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
const
WeekCName : array [0..6] of String = ('日','一','二','三','四','五','六');

function ToDateText(Y,M : Integer;AData : array of String;POut : TStrings;AMaxL : Integer = -1) : Integer;
procedure SetRL(var RL : array of Integer;Y,M : Integer);
var
I,MaxI,N : Integer;
begin
MaxI := DateUtils.DaysInAMonth(Y,M);

N := DateUtils.DayOfTheWeek(EncodeDate(Y,M,1));
N := N mod 7;

for I := 0 to MaxI - 1 do
RL[I + N] := I + 1;
end;

function GetDMaxU : Integer;
var
I : Integer;
begin
Result := Length(AData[0]);
for I := 1 to 31 - 1 do
begin
if Length(AData) > Result then
Result := Length(AData);
end;
end;
var
RL : array [1..42] of Integer;
SL,SD : String;

I : Integer;
N,MaxL : Integer;
begin
for I := Low(RL) to High(RL) do
RL := 0;

if AMaxL < 0 then
N := GetDMaxU
else
N := AMaxL div 7;

SetRL(RL,Y,M);

for I := 0 to 6 do
SL := SL + Format('%-*.*s ',[N,N,WeekCName]);
POut.Append(SL);

SL := '';
SD := '';
MaxL := Length(SD);
for I := 1 to 42 do
begin
if RL > 0 then
begin
SL := SL + Format('%-*.d ',[N,RL]);
SD := SD + Format('%-*.*s ',[N,N,AData[RL - 1]]);
end else
begin
SL := SL + Format('%*.*s ',[N,N,'']);
SD := SD + Format('%*.*s ',[N,N,'']);
end;

if MaxL < Length(SD) then
MaxL := Length(SD);

if (I mod 7) = 0 then
begin
POut.Append(SL);
POut.Append(SD);
SL := '';
SD := '';
end;
end;

Result := MaxL;
end;

procedure SetRD(var RD : array of String);
var
I : Integer;
begin
for I := 0 to 31 - 1 do
RD := '';

//在这里为数据赋值
RD[0] := 'A,+8';
RD[1] := 'A+,-1.5';
RD[2] := 'D';
RD[3] := 'E';
RD[4] := '';
RD[5] := 'BX';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
RD : array [1..31] of String;
begin
SetRD(RD);
ToDateText(StrToInt(Edit1.Text),StrToInt(Edit2.Text),RD,Memo1.Lines,40);
end;

end.
 
楼主能给解释一下这个的实现过程吗 ?
 
后退
顶部