[問題]有關萬年暦程式 |
尚未結案
|
cleverman319
一般會員 發表:5 回覆:1 積分:1 註冊:2005-10-10 發送簡訊給我 |
|
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
|
sucm
一般會員 發表:24 回覆:29 積分:10 註冊:2005-01-17 發送簡訊給我 |
給你看我寫的萬年歷..讓你參考一下...
寫得很簡單....
希望你看得懂... unit CalendarUnit; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids; type
TCalendar = class(TForm)
SGrid: TStringGrid;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
procedure FormCreate(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure SGridMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SGridDblClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Calendar: TCalendar;
SelectDate: String;
ivTop,ivLeft: Integer;
procedure RunDate(inGrid: TStringGrid;inYear: TComboBox;inMonth: TComboBox);
procedure ClearTGrid(inGrid: TStringGrid);
procedure AddComBoxItem(inComBox1: TComboBox;inComBox2: TComboBox); implementation var
igClick: Boolean = false; {$R *.dfm} procedure TCalendar.FormCreate(Sender: TObject);
var
i,FirstDate: Integer;
begin
SGrid.Cells[0,0]:= '日';
SGrid.Cells[1,0]:= '一';
SGrid.Cells[2,0]:= '二';
SGrid.Cells[3,0]:= '三';
SGrid.Cells[4,0]:= '四';
SGrid.Cells[5,0]:= '五';
SGrid.Cells[6,0]:= '六'; AddComBoxItem(ComboBox1,ComboBox2);
RunDate(SGrid,ComboBox1,ComboBox2); end; procedure RunDate(inGrid: TStringGrid;inYear: TComboBox;inMonth: TComboBox); //===產生日期=====
var
i,j,k,l,m,FirstDate: Integer;
begin
i:= 0;
l:= 2;
j:= 0; if (inMonth.Text = '1月') or (inMonth.Text = '3月') or (inMonth.Text = '5月') or (inMonth.Text = '7月') or (inMonth.Text = '8月') or (inMonth.Text = '10月') or (inMonth.Text = '12月') then
m:= 31
else if (inMonth.Text = '4月') or (inMonth.Text = '6月') or (inMonth.Text = '9月') or (inMonth.Text = '11月') then
m:= 30
else if (inMonth.Text = '2月') then
if StrToInt(inYear.Text) mod 4 = 0 then
m:= 29
else
m:= 28;
FirstDate:= DayOfWeek(StrToDate(inYear.Text '/' IntToStr(inMonth.ItemIndex 1) '/' '01'));
while i < m do
begin
if j < 7 then
for j:= FirstDate to 7 do
begin
i:= i 1;
inGrid.Cells[j-1,1]:= IntToStr(i);
end
else
for k:= 0 to 6 do
begin
i:= i 1;
inGrid.Cells[k,l]:= IntToStr(i);
if k = 6 then
l:= l 1;
if i = m then
break;
end;
end;
end; procedure ClearTGrid(inGrid: TStringGrid); //=====清空Grid=====
var
i,j: Integer;
begin
for i:= 1 to 6 do
for j:= 0 to 6 do
begin
inGrid.Cells[j,i]:= '';
end;
end; procedure AddComBoxItem(inComBox1: TComboBox;inComBox2: TComboBox);
var
i: Integer;
begin
for i:= StrToInt(Copy(FormatDateTime('yyyymmdd',Date),1,4)) - 100 to StrToInt(Copy(FormatDateTime('yyyymmdd',Date),1,4)) 20 do
inComBox1.Items.Add(IntToStr(i));
inComBox1.Text:= Copy(FormatDateTime('yyyymmdd',Date),1,4);
inComBox2.ItemIndex:=StrToInt(Copy(FormatDateTime('yyyymmdd',Date),5,2)) - 1;
end; procedure TCalendar.ComboBox2Change(Sender: TObject);
begin
ClearTGrid(SGrid);
RunDate(SGrid,ComboBox1,ComboBox2);
end; procedure TCalendar.ComboBox1Change(Sender: TObject);
begin
ClearTGrid(SGrid);
RunDate(SGrid,ComboBox1,ComboBox2);
end; procedure TCalendar.SGridMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
C,R: Integer;
begin
if igClick then //===DbClick後才把值帶出
begin
SGrid.MouseToCell(X,Y,C,R);
if (R <> 0) and (SGrid.Cells[C,R] <> '') then
begin
SelectDate:= ComboBox1.Text '/' FormatFloat('00',ComboBox2.ItemIndex 1) '/' FormatFloat('00',StrToInt(SGrid.Cells[C,R]));
Self.Close;
end;
igClick:= false;
end;
end; procedure TCalendar.SGridDblClick(Sender: TObject);
begin
igClick:= true;
end; procedure TCalendar.FormShow(Sender: TObject);
begin
Self.Top:= ivTop;
Self.Left:= ivLeft;
end;
end. 我是新手...請原諒我的笨問題
|
cleverman319
一般會員 發表:5 回覆:1 積分:1 註冊:2005-10-10 發送簡訊給我 |
你有執行前和執行後的圖檔可以看嗎
有的程式函式我沒有辦法找到在哪裡,執行後說如下:
Error in module Unit1:Declaration class TForm is missing or incorrect
引言: 給你看我寫的萬年歷..讓你參考一下... 寫得很簡單.... 希望你看得懂... unit CalendarUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids; type TCalendar = class(TForm) SGrid: TStringGrid; ComboBox1: TComboBox; ComboBox2: TComboBox; procedure FormCreate(Sender: TObject); procedure ComboBox2Change(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure SGridMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure SGridDblClick(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } public { Public declarations } end; var Calendar: TCalendar; SelectDate: String; ivTop,ivLeft: Integer; procedure RunDate(inGrid: TStringGrid;inYear: TComboBox;inMonth: TComboBox); procedure ClearTGrid(inGrid: TStringGrid); procedure AddComBoxItem(inComBox1: TComboBox;inComBox2: TComboBox); implementation var igClick: Boolean = false; {$R *.dfm} procedure TCalendar.FormCreate(Sender: TObject); var i,FirstDate: Integer; begin SGrid.Cells[0,0]:= '日'; SGrid.Cells[1,0]:= '一'; SGrid.Cells[2,0]:= '二'; SGrid.Cells[3,0]:= '三'; SGrid.Cells[4,0]:= '四'; SGrid.Cells[5,0]:= '五'; SGrid.Cells[6,0]:= '六'; AddComBoxItem(ComboBox1,ComboBox2); RunDate(SGrid,ComboBox1,ComboBox2); end; procedure RunDate(inGrid: TStringGrid;inYear: TComboBox;inMonth: TComboBox); //===產生日期===== var i,j,k,l,m,FirstDate: Integer; begin i:= 0; l:= 2; j:= 0; if (inMonth.Text = '1月') or (inMonth.Text = '3月') or (inMonth.Text = '5月') or (inMonth.Text = '7月') or (inMonth.Text = '8月') or (inMonth.Text = '10月') or (inMonth.Text = '12月') then m:= 31 else if (inMonth.Text = '4月') or (inMonth.Text = '6月') or (inMonth.Text = '9月') or (inMonth.Text = '11月') then m:= 30 else if (inMonth.Text = '2月') then if StrToInt(inYear.Text) mod 4 = 0 then m:= 29 else m:= 28; FirstDate:= DayOfWeek(StrToDate(inYear.Text '/' IntToStr(inMonth.ItemIndex 1) '/' '01')); while i < m do begin if j < 7 then for j:= FirstDate to 7 do begin i:= i 1; inGrid.Cells[j-1,1]:= IntToStr(i); end else for k:= 0 to 6 do begin i:= i 1; inGrid.Cells[k,l]:= IntToStr(i); if k = 6 then l:= l 1; if i = m then break; end; end; end; procedure ClearTGrid(inGrid: TStringGrid); //=====清空Grid===== var i,j: Integer; begin for i:= 1 to 6 do for j:= 0 to 6 do begin inGrid.Cells[j,i]:= ''; end; end; procedure AddComBoxItem(inComBox1: TComboBox;inComBox2: TComboBox); var i: Integer; begin for i:= StrToInt(Copy(FormatDateTime('yyyymmdd',Date),1,4)) - 100 to StrToInt(Copy(FormatDateTime('yyyymmdd',Date),1,4)) 20 do inComBox1.Items.Add(IntToStr(i)); inComBox1.Text:= Copy(FormatDateTime('yyyymmdd',Date),1,4); inComBox2.ItemIndex:=StrToInt(Copy(FormatDateTime('yyyymmdd',Date),5,2)) - 1; end; procedure TCalendar.ComboBox2Change(Sender: TObject); begin ClearTGrid(SGrid); RunDate(SGrid,ComboBox1,ComboBox2); end; procedure TCalendar.ComboBox1Change(Sender: TObject); begin ClearTGrid(SGrid); RunDate(SGrid,ComboBox1,ComboBox2); end; procedure TCalendar.SGridMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var C,R: Integer; begin if igClick then //===DbClick後才把值帶出 begin SGrid.MouseToCell(X,Y,C,R); if (R <> 0) and (SGrid.Cells[C,R] <> '') then begin SelectDate:= ComboBox1.Text '/' FormatFloat('00',ComboBox2.ItemIndex 1) '/' FormatFloat('00',StrToInt(SGrid.Cells[C,R])); Self.Close; end; igClick:= false; end; end; procedure TCalendar.SGridDblClick(Sender: TObject); begin igClick:= true; end; procedure TCalendar.FormShow(Sender: TObject); begin Self.Top:= ivTop; Self.Left:= ivLeft; end; end. 我是新手...請原諒我的笨問題 |
sucm
一般會員 發表:24 回覆:29 積分:10 註冊:2005-01-17 發送簡訊給我 |
|
kgt
高階會員 發表:17 回覆:308 積分:165 註冊:2002-03-13 發送簡訊給我 |
Hi,cleverman319:
我的解讀如下,請參考
ps.程式碼在回覆貼上時,有些+號會不見,故請對照您的原始程式
----------------------------------------------------------------- procedure TForm1.Button1Click(Sender: TObject);
var
a:array [1..12] of integer; /////一維陣列計12個,用途放每月有幾天
year,month,dayofweek,i,j,k : integer;
s:String;
begin
panel1.Visible:=false;button3.Visible := true;
year:=strtoint(Edit1.Text); /////取得<年>的變數值, 例2005
month:=strtoint(Edit2.Text); /////取得<月>的變數值, 例2月 /////一維陣列計12個,用途放每月有幾天,將預設值放入一維陣列中
a[1]:=31;a[2]:=28;a[3]:=31;a[4]:=30;a[5]:=31;a[6]:=30;
a[7]:=31;a[8]:=31;a[9]:=30;a[10]:=31;a[11]:=30;a[12]:=31; /////計算當年的一月一日是星期幾,例6
DayOfWeek := ((Year-1)+((Year-1)div 4)-((Year-1)div 100)+((Year-1)div 400)+1) mod 7; /////計算閏年的部分 ,二月共有幾天,例28
if (((Year mod 4)= 0) and ( not(((Year mod 100)= 0) and (not((Year mod 400)= 0)) ) ) ) then begin
a[2] := 29;
end
else
begin
a[2] := 28;
end; /////將年月及星期放至變數s
///// 2004/10
/////
/////日 一 二 三 四 五 六
/////
s := inttostr(year) + '/'+ inttostr(month) + #13#10#13#10;
s := s + '日 一 二 三 四 五 六 ' #13#10; /////算出使用者輸入月份的1號是星期幾,例2
if month >1 then
begin
for i:=1 to month-1 do
begin
dayofweek:=dayofweek+a[i];
end;
end; dayofweek := dayofweek mod 7; /////因印當月1號若為星期二,需先印空二格
for j:=1 to dayofweek do
begin
s := s+ ' '
end; /////開始印出日期1-28,每個日期前後一個空格
for k:=1 to a[month] do
begin
if k<10 then
begin
s:= s ' ' inttostr(k) ' ';
end
else
begin
s:= s inttostr(k) ' ';
end; /////遇星期六準備換列至下一列
if dayofweek = 6 then
begin
s:=s #13#10; end;
end; dayofweek := dayofweek 1;
dayofweek := dayofweek mod 7;
end; label3.Caption :=s ;
end;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |