📄 rl_unit1.pas
字号:
$A5, $B3, $A5, $B5, $A6, $A6, $88, $88, $88, $78, $87, $87, //2042
$A5, $B4, $96, $A5, $A6, $96, $88, $88, $78, $78, $87, $87, //2043
$95, $B4, $A5, $B4, $A5, $A6, $97, $87, $87, $88, $87, $96, //2044
$A5, $C3, $A5, $B4, $A5, $A6, $87, $88, $87, $78, $87, $86, //2045
$A5, $B3, $A5, $B5, $A6, $A6, $87, $88, $88, $78, $87, $87, //2046
$A5, $B4, $96, $A5, $A6, $96, $88, $88, $78, $78, $87, $87, //2047
$95, $B4, $A5, $B4, $A5, $A5, $97, $87, $87, $88, $86, $96, //2048
$A4, $C3, $A5, $A5, $A5, $A6, $97, $87, $87, $78, $87, $86, //2049
$A5, $C3, $A5, $B5, $A6, $A6, $87, $88, $78, $78, $87, $87); //2050
//-----------------------------------------------------------------
//返回iYear年iMonth月的天数 1年1月 --- 65535年12月
function MonthDays(iYear,iMonth:Word):Word;
begin
case iMonth of
1,3,5,7,8,10,12: Result:=31;
4,6,9,11: Result:=30;
2://如果是闰年
if IsLeapYear(iYear) then //IsLeapYear(n)是一个库函数,功能就是求第n年是否为闰年
Result:=29
else
Result:=28
else
Result:=0;
end;
end;
//-------------------------------------------------------------------
//每次加载新日期后先初始化窗体
procedure TForm3.choushi;
var i:integer;
begin
For i:=0 to 39 do //将可能隐藏的都显示出来
(Form3.Components[i+3] as TFlatButton).Visible:=true;
end;
//--------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------
// 对农历的处理
//返回阴历iLunarYear年的闰月月份,如没有返回0 1901年1月---2050年12月
function GetLeapMonth(iLunarYear:Word):Word;
var
Flag:Byte;
begin
Flag:=gLunarMonth[(iLunarYear-START_YEAR) div 2];
if (iLunarYear-START_YEAR) mod 2=0 then
Result:=Flag shr 4
else
Result:=Flag and $0F;
//showMessage(inttostr(result));
end;
//------------------------------------------------------------------------------
//返回阴历iLunarYer年阴历iLunarMonth月的天数,如果iLunarMonth为闰月,
//高字为第二个iLunarMonth月的天数,否则高字为0 1901年1月---2050年12月
function LunarMonthDays(iLunarYear,iLunarMonth:Word):Longword;
var
Height,Low:Word;
iBit:Integer;
begin
if iLunarYear<START_YEAR then
begin
Result:=30;
Exit;
end;
Height:=0;
Low:=29;
iBit:=16-iLunarMonth;
if (iLunarMonth>GetLeapMonth(iLunarYear)) and (GetLeapMonth(iLunarYear)>0) then
Dec(iBit);
if (gLunarMonthDay[iLunarYear-START_YEAR] and (1 shl iBit))>0 then
Inc(Low);
if iLunarMonth=GetLeapMonth(iLunarYear) then
if (gLunarMonthDay[iLunarYear-START_YEAR] and (1 shl (iBit-1)))>0 then
Height:=30
else
Height:=29;
Result:=MakeLong(Low,Height);
//ShowMessage(IntToStr(MakeLong(Low,Height)));
end;
//------------------------------------------------------------------------------
//返回阴历iLunarYear年的总天数 1901年1月---2050年12月
function LunarYearDays(iLunarYear:Word):Word;
var
Days,i:Word;
tmp:Longword;
begin
Days:=0;
for i:=1 to 12 do
begin
tmp:=LunarMonthDays(iLunarYear,i);
Days:=Days+HiWord(tmp);
Days:=Days+LoWord(tmp);
end;
Result:=Days;
end;
//------------------------------------------------------------------------------
//把iYear年格式化成天干记年法表示的字符串
procedure FormatLunarYear(iYear:Word;var pBuffer:string);
var
szText1,szText2,szText3:string;
begin
szText1:='甲乙丙丁戊己庚辛壬癸';
szText2:='子丑寅卯辰巳午未申酉戌亥';
szText3:='鼠牛虎免龙蛇马羊猴鸡狗猪';
pBuffer:=Copy(szText1,((iYear-4) mod 10)*2+1,2);
pBuffer:=pBuffer+Copy(szText2,((iYear-4) mod 12)*2+1,2);
pBuffer:=pBuffer;
pBuffer:=pBuffer+'('+Copy(szText3,((iYear-4) mod 12)*2+1,2)+')';
pBuffer:=pBuffer+'年 ';
end;
function FormatLunarYear(iYear:Word):string;
var
pBuffer:string;
begin
FormatLunarYear(iYear,pBuffer);
Result:=pBuffer;
end;
//------------------------------------------------------------------------------
//把iMonth格式化成中文字符串 如:五月
procedure FormatMonth(iMonth:Word;var pBuffer:string;bLunar:Boolean);
var
szText:string;
begin
if (not bLunar) and (iMonth=1) then
begin
pBuffer:=' 一月';
Exit;
end;
szText:='正二三四五六七八九十';
if iMonth<=10 then
begin
pBuffer:=' ';
pBuffer:=pBuffer+Copy(szText,(iMonth-1)*2+1,2);
pBuffer:=pBuffer+'月';
Exit;
end;
if iMonth=11 then
pBuffer:='十一'
else
pBuffer:='十二';
pBuffer:=pBuffer+'月';
end;
function FormatMonth(iMonth:Word;bLunar:Boolean):string;
var
pBuffer:string;
begin
FormatMonth(iMonth,pBuffer,bLunar);
Result:=pBuffer;
end;
//-----------------------------------------------------------------------------
//把iDay格式化成中文字符串 如:二十日
procedure FormatLunarDay(iDay:Word;var pBuffer:string);
var
szText1,szText2:string;
begin
szText1:='初十廿三';
szText2:='一二三四五六七八九十';
if (iDay<>20) and (iDay<>30) then
begin
pBuffer:=Copy(szText1,((iDay-1) div 10)*2+1,2);
pBuffer:=pBuffer+Copy(szText2,((iDay-1) mod 10)*2+1,2);
end
else
begin
pBuffer:=Copy(szText1,(iDay div 10)*2+1,2);
pBuffer:=pBuffer+'十';
end;
end;
function FormatLunarDay(iDay:Word):string;
var
pBuffer:string;
begin
FormatLunarDay(iDay,pBuffer);
Result:=pBuffer;
end;
//------------------------------------------------------------------------------
//计算公历两个日期间相差的天数 1年1月1日 --- 65535年12月31日
function CalcDateDiff(iEndYear,iEndMonth,iEndDay:Word;iStartYear:Word;iStartMonth:Word;iStartDay:Word):Longword;
begin
Result:=Trunc(EncodeDate(iEndYear,iEndMonth,iEndDay)-EncodeDate(iStartYear,iStartMonth,iStartDay));
end;
function CalcDateDiff(EndDate,StartDate:TDateTime):Longword;
begin
Result:=Trunc(EndDate-StartDate);
//showMessage(IntToStr(result));
end;
//------------------------------------------------------------------------------
//计算从1901年1月1日过iSpanDays天后的阴历日期 (年,月,日)
procedure TForm3.l_CalcLunarDate(var iYear,iMonth,iDay:Word;iSpanDays:Longword);
var
tmp:Longword;
begin
//阳历1901年2月19日为阴历1901年正月初一
//阳历1901年1月1日到2月19日共有49天
if iSpanDays<49 then
begin
iYear:=START_YEAR-1;
if iSpanDays<19 then
begin
iMonth:=11;
iDay:=11+Word(iSpanDays);
end
else
begin
iMonth:=12;
iDay:=Word(iSpanDays)-18;
end;
Exit;
end;
//下面从阴历1901年正月初一算起
iSpanDays:=iSpanDays-49;
iYear:=START_YEAR;
iMonth:=1;
iDay:=1;
//计算年
tmp:=LunarYearDays(iYear);
while iSpanDays>=tmp do
begin
iSpanDays:=iSpanDays-tmp;
Inc(iYear);
tmp:=LunarYearDays(iYear);
end;
//计算月
tmp:=LoWord(LunarMonthDays(iYear,iMonth));
while iSpanDays>=tmp do
begin
iSpanDays:=iSpanDays-tmp;
if iMonth=GetLeapMonth(iYear) then
begin
tmp:=HiWord(LunarMonthDays(iYear,iMonth));
if iSpanDays<tmp then Break;
iSpanDays:=iSpanDays-tmp;
end;
Inc(iMonth);
tmp:=LoWord(LunarMonthDays(iYear,iMonth));
end;
//计算日
iDay:=iDay+Word(iSpanDays);
end;
//------------------------------------------------------------------------------
//计算公历iYear年iMonth月iDay日对应的节气 0-24,0表不是节气
function TForm3.l_GetLunarHolDay(iYear,iMonth,iDay:Word):Word;
var
Flag:Byte;
Day:Word;
begin
Flag:=gLunarHolDay[(iYear-START_YEAR)*12+iMonth-1];
if iDay<15 then
Day:=15-((Flag shr 4) and $0f)
else
Day:=(Flag and $0f)+15;
if iDay=Day then
if iDay>15 then
Result:=(iMonth-1)*2+2
else
Result:=(iMonth-1)*2+1
else
Result:= 0;
end;
//------------------------------------------------------------------------------
//返回特殊节日,假日
function Getjiejia(iMonth,iDay:word):string;
Begin
case StrToInt(IntToStr(iMonth)+IntToStr(iDay)) of
11:result:='元旦节';
22:result:='世界湿地日';
210:result:='国际气象节';
214:result:='情人节';
31:result:='国际海豹日';
33:result:='全国爱耳日';
35:result:='学雷锋纪念日';
38:result:='妇女节';
312:result:='植树节 孙中山逝世纪念日';
314:result:='国际警察日';
315:result:='消费者权益日';
317:result:='中国国医节 国际航海日';
321:result:='世界森林日';
322:result:='世界水日';
323:result:='世界气象日';
324:result:='世界防治结核病日';
325:result:='全国中小学生安全教育日';
330:result:='巴勒斯坦国土日';
401:result:='愚人节 税收宣传月';
407:result:='世界卫生日';
422:result:='世界地球日';
423:result:='世界图书和版权日';
424:result:='亚非新闻工作者日';
51:result:='劳动节';
52:result:='劳动节假日';
53:result:='劳动节假日';
54:result:='青年节';
55:result:='碘缺乏病防治日';
58:result:='世界红十字日';
512:result:='国际护士节';
515:result:='国际家庭日';
517:result:='国际电信日';
518:result:='国际博物馆日';
520:result:='全国学生营养日';
523:result:='国际牛奶日';
531:result:='世界无烟日';
61:result:='国际儿童节';
65:result:='世界环境保护日';
66:result:='全国爱眼日';
617:result:='防治荒漠化和干旱日';
623:result:='国际奥林匹克日';
625:result:='全国土地日';
626:result:='国际禁毒日';
71:result:='香港回归纪念日 中共诞辰';
72:result:='国际体育记者日';
77:result:='抗日战争纪念日';
711:result:='世界人口日';
730:result:='非洲妇女日';
81:result:='建军节';
88:result:='中国男子节';
815:result:='抗日战争胜利纪念';
98:result:='国际扫盲日';
99:result:='毛泽东逝世纪念';
910:result:='中国教师节';
914:result:='世界清洁地球日';
916:result:='国际臭氧层保护日';
918:result:='九.一八事变纪念日';
920:result:='国际爱牙日';
927:result:='世界旅游日';
928:result:='孔子诞辰';
101:result:='国庆节 国际老人节';
102:result:='国庆节假日';
103:result:='国庆节假日';
104:result:='世界动物日';
106:result:='老人节';
108:result:='全国高血压日';
109:result:='世界邮政日 万国邮联日';
1010:result:='辛亥革命纪念日';
1013:result:='国际教师节';
1014:result:='世界标准日';
1015:result:='国际盲人节';
1016:result:='世界粮食日';
1017:result:='世界消除贫困日';
1022:result:='世界传统医药日';
1024:result:='联合国日';
1031:result:='世界勤俭日';
117:result:='十月社会主义革命纪念日';
118:result:='中国记者日';
119:result:='全国消防安全宣传教育日';
1110:result:='世界青年节';
1111:result:='国际科学与和平周';
1112:result:='孙中山诞辰纪念日';
1114:result:='世界糖尿病日';
1117:result:='国际大学生节';
1120:result:='彝族年';
1121:result:='世界问候日';
1122:result:='彝族年';
1129:result:='国际声援巴勒斯坦人民国际日';
121:result:='世界艾滋病日';
123:result:='世界残疾人日';
125:result:='国际经济和社会发展志愿人员日';
128:result:='国际儿童电视日';
129:result:='世界足球日';
1210:result:='世界人权日';
1212:result:='西安事变纪念日';
1213:result:='南京大屠杀(1937年)纪念日';
1220:result:='澳门回归纪念';
1221:result:='国际篮球日';
1224:result:='平安夜';
1225:result:='圣诞节';
1226:result:='毛泽东诞辰纪念';
end;
End;
//------------------------------------------------------------------------------
//返回农历节日
function Getnonglijiejia(iYear,iMonth,iDay:Word):string;
Begin
//Form3.l_CalcLunarDate(iYear,iMonth,iDay,CalcDateDiff(EncodeDate(iYear,iMonth,iDay),EncodeDate(START_YEAR,1,1)));
case StrToInt(IntToStr(iMonth)+IntToStr(iDay)) of
11:result:='春节';
12:result:='春节';
13:result:='春节';
115:result:='元宵节';
55:result:='端午节';
624:result:='火把节';
625:result:='火把节';
626:result:='火把节';
77:result:='七夕情人节';
715:result:='中元节';
815:result:='中秋节';
99:result:='重阳节';
128:result:='腊八节';
1223:result:='小年';
10:result:='除夕';
end;
End;
//------------------------------------------------------------------------------
//计算公历iYear年iMonth月iDay日对应的阴历日期,返回对应的阴历节气 0-24
//1901年1月1日---2050年12月31日
function GetLunarHolDay(InDate:TDateTime):string;
var
i,iYear,iMonth,iDay:Word;
begin
DecodeDate(InDate,iYear,iMonth,iDay);
i:=Form3.l_GetLunarHolDay(iYear,iMonth,iDay);
case i of
1:Result:=' (小寒)';
2:Result:=' (大寒)';
3:Result:=' (立春)';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -