定义数组的时候漏了类型: ArrayInteger : Array of Array of Integer; ArrayInteger : Array[0..3] of Integer;
我是新手,我把源程序写出来,请大家帮我瞧瞧: unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, ExtCtrls, DBGrids, Db, ADODB;type TForm1 = class(TForm) Panel1: TPanel; DrawGrid1: TDrawGrid; function IsWin(IsBlock:Boolean):Boolean; procedure FormCreate(Sender: TObject); procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } public { Public declarations } end; var Form1: TForm1; IsBlack:boolean; Tag:array[0..18,0..18]of Integer;implementation{$R *.DFM} function IsWin(IsBlack:boolean):boolean; label exit1; var i,j:Integer; wtag:Integer; begin Iswin:=false; if IsBlack then wtag:=1 else wtag:=2; for i:=0 to 18 do for j:=0 to 14 do begin if(i<15) and(Tag[i,j]=wtag) and(Tag[i+1,j]=wtag) and(Tag[i+2,j]=wtag) and(Tag[i+3,j]=wtag) and(Tag[i+4,j]=wtag) then begin IsWin:=True; goto exit1; end; if(Tag[i,j]=wtag) and(Tag[i,j+1]=wtag) and(Tag[i,j+2]=wtag) and(Tag[i,j+3]=wtag) and(Tag[i,j+4]=wtag) then begin IsWin:=True; goto exit1; end; if(i<15) and(Tag[i,j]=wtag) and(Tag[i+1,j+1]=wtag) and(Tag[i+2,j+2]=wtag) and(Tag[i+3,j+3]=wtag) and(Tag[i+4,j+4]=wtag) then begin IsWin:=True; goto exit1; end; if(Tag[i,j]=wtag) and(Tag[i-1,j+1]=wtag) and(Tag[i-2,j+2]=wtag) and(Tag[i-3,j+3]=wtag) and(Tag[i-4,j+4]=wtag) then begin IsWin:=True; goto exit1; end; end; exit1: end; procedure TForm1.FormCreate(Sender: TObject); var i,j:Integer; begin for i:=0 to 18 do for j:=0 to 18 do begin Tag[i,j]:=0;//***Array type required. end; IsBlack:=True; DrawGrid1.Canvas.Pen.Color:=clBlack; DrawGrid1.Canvas.Brush.Color:=clBlack; end;procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin DrawGrid1.Canvas.Pen.Color:=clBlack; DrawGrid1.Canvas.Brush.Color:=clBlack; if Tag[ACol,ARow]=1 then DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21) else if Tag[acol,arow]=2 then DrawGrid1.Canvas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21) else begin DrawGrid1.Canvas.Pen.Color:=clWhite; DrawGrid1.Canvas.Brush.Color:=clWhite; DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21); end; end;procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var col,row:integer; i,j:integer; begin DrawGrid1.Canvas.Pen.Color:=clBlack; DrawGrid1.Canvas.Brush.Color:=clBlack; DrawGrid1.MouseToCell(x,y,col,row); if Tag[col,row]=0 then begin if IsBlack then begin DrawGrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21); Tag[col,row]:=1; end else begin DrawGrid1.Canvas.Arc(col*21,row*21,(col+1)*21,(row+1)*21,col*21,row*21,col*21,row*21); Tag[col,row]:=2 end; if IsWin(IsBlack) then begin if MessageDlg('黑方胜利',mtInformation,[mbOK],0)=mrOK then begin for i:=0 to 18 do for j:= 0 to 18 do begin Tag[i,j]:=0; end; DrawGrid1.Invalidate; end; if not IsBlack then if MessageDlg('白方胜利',mtInformation,[mbOK],0)=mrOK then begin for i:=0 to 18 do for j:= 0 to 18 do begin Tag[i,j]:=0; end; DrawGrid1.Invalidate; end; end; IsBlack:=not IsBlack; end;end.编译时出现了很多问题。(见***)
帮你修改了几个地方,编译已经通过了 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, ExtCtrls, DBGrids, Db, ADODB; type TForm1 = class(TForm) Panel1: TPanel; DrawGrid1: TDrawGrid; procedure FormCreate(Sender: TObject); procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private function IsWin(IsBlack: boolean): boolean; { Private declarations } public Tag: array[1..18,1..18] of Integer; { Public declarations } end;var Form1: TForm1; IsBlack:boolean;implementation{$R *.DFM} function TForm1.IsWin(IsBlack:boolean):boolean; label exit1; var i,j:Integer; wtag:Integer; begin Iswin:=false; if IsBlack then wtag:=1 else wtag:=2; for i:=0 to 18 do for j:=0 to 14 do begin if(i<15) and(Tag[i,j]=wtag) and(Tag[i+1,j]=wtag) and(Tag[i+2,j]=wtag) and(Tag[i+3,j]=wtag) and(Tag[i+4,j]=wtag) then begin IsWin:=True; goto exit1; end; if(Tag[i,j]=wtag) and(Tag[i,j+1]=wtag) and(Tag[i,j+2]=wtag) and(Tag[i,j+3]=wtag) and(Tag[i,j+4]=wtag) then begin IsWin:=True; goto exit1; end; if(i<15) and(Tag[i,j]=wtag) and(Tag[i+1,j+1]=wtag) and(Tag[i+2,j+2]=wtag) and(Tag[i+3,j+3]=wtag) and(Tag[i+4,j+4]=wtag) then begin IsWin:=True; goto exit1; end; if(Tag[i,j]=wtag) and(Tag[i-1,j+1]=wtag) and(Tag[i-2,j+2]=wtag) and(Tag[i-3,j+3]=wtag) and(Tag[i-4,j+4]=wtag) then begin IsWin:=True; goto exit1; end; end; exit1: end;procedure TForm1.FormCreate(Sender: TObject); var i,j:Integer; begin for i:=0 to 18 do for j:= 0 to 18 do begin Tag[i,j]:=0;//***Array type required. end; IsBlack:=True; DrawGrid1.Canvas.Pen.Color:=clBlack; DrawGrid1.Canvas.Brush.Color:=clBlack; end;procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin DrawGrid1.Canvas.Pen.Color:=clBlack; DrawGrid1.Canvas.Brush.Color:=clBlack; if Tag[ACol,ARow]=1 then DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21) else if Tag[acol,arow]=2 then DrawGrid1.Canvas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21) else begin DrawGrid1.Canvas.Pen.Color:=clWhite; DrawGrid1.Canvas.Brush.Color:=clWhite; DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21); end; end;procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var col,row:integer; i,j:integer; begin DrawGrid1.Canvas.Pen.Color:=clBlack; DrawGrid1.Canvas.Brush.Color:=clBlack; DrawGrid1.MouseToCell(x,y,col,row); if Tag[col,row]=0 then begin if IsBlack then begin DrawGrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21); Tag[col,row]:=1; end else begin DrawGrid1.Canvas.Arc(col*21,row*21,(col+1)*21,(row+1)*21,col*21,row*21,col*21,row*21); Tag[col,row]:=2 end; if IsWin(IsBlack) then begin if MessageDlg('黑方胜利',mtInformation,[mbOK],0)=mrOK then begin for i:=0 to 18 do for j:= 0 to 18 do begin Tag[i,j]:=0; end; DrawGrid1.Invalidate; end; if not IsBlack then if MessageDlg('白方胜利',mtInformation,[mbOK],0)=mrOK then begin for i:=0 to 18 do for j:= 0 to 18 do begin Tag[i,j]:=0; end; DrawGrid1.Invalidate; end; end; IsBlack:=not IsBlack; end;end;end.
还有要把这句for i:=0 to 18 do 改为: for i:=0 to 18-1 do 才行呀
ArrayInteger : Array of Array of Integer;
ArrayInteger : Array[0..3] of Integer;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, ExtCtrls, DBGrids, Db, ADODB;type
TForm1 = class(TForm)
Panel1: TPanel;
DrawGrid1: TDrawGrid;
function IsWin(IsBlock:Boolean):Boolean;
procedure FormCreate(Sender: TObject);
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
IsBlack:boolean;
Tag:array[0..18,0..18]of Integer;implementation{$R *.DFM}
function IsWin(IsBlack:boolean):boolean;
label exit1;
var
i,j:Integer;
wtag:Integer;
begin
Iswin:=false;
if IsBlack then
wtag:=1 else
wtag:=2;
for i:=0 to 18 do
for j:=0 to 14 do
begin
if(i<15)
and(Tag[i,j]=wtag)
and(Tag[i+1,j]=wtag)
and(Tag[i+2,j]=wtag)
and(Tag[i+3,j]=wtag)
and(Tag[i+4,j]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
if(Tag[i,j]=wtag)
and(Tag[i,j+1]=wtag)
and(Tag[i,j+2]=wtag)
and(Tag[i,j+3]=wtag)
and(Tag[i,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
if(i<15)
and(Tag[i,j]=wtag)
and(Tag[i+1,j+1]=wtag)
and(Tag[i+2,j+2]=wtag)
and(Tag[i+3,j+3]=wtag)
and(Tag[i+4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
if(Tag[i,j]=wtag)
and(Tag[i-1,j+1]=wtag)
and(Tag[i-2,j+2]=wtag)
and(Tag[i-3,j+3]=wtag)
and(Tag[i-4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
end;
exit1:
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i,j:Integer;
begin
for i:=0 to 18 do
for j:=0 to 18 do
begin
Tag[i,j]:=0;//***Array type required.
end;
IsBlack:=True;
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
end;procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
if Tag[ACol,ARow]=1 then
DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
else if Tag[acol,arow]=2 then
DrawGrid1.Canvas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21)
else
begin
DrawGrid1.Canvas.Pen.Color:=clWhite;
DrawGrid1.Canvas.Brush.Color:=clWhite;
DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21);
end;
end;procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
col,row:integer;
i,j:integer;
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
DrawGrid1.MouseToCell(x,y,col,row);
if Tag[col,row]=0 then
begin
if IsBlack then
begin DrawGrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21);
Tag[col,row]:=1;
end else
begin
DrawGrid1.Canvas.Arc(col*21,row*21,(col+1)*21,(row+1)*21,col*21,row*21,col*21,row*21);
Tag[col,row]:=2
end;
if IsWin(IsBlack) then
begin
if MessageDlg('黑方胜利',mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18 do
for j:= 0 to 18 do
begin
Tag[i,j]:=0;
end;
DrawGrid1.Invalidate;
end;
if not IsBlack then
if MessageDlg('白方胜利',mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18 do
for j:= 0 to 18 do
begin
Tag[i,j]:=0;
end;
DrawGrid1.Invalidate;
end;
end;
IsBlack:=not IsBlack;
end;end.编译时出现了很多问题。(见***)
因为tag是缺省的self里的一个属性
它只是一个整形数,不是一个数组,delphi在编绎时实际上把它做为
self.tag来处理了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, ExtCtrls, DBGrids, Db, ADODB;
type
TForm1 = class(TForm)
Panel1: TPanel;
DrawGrid1: TDrawGrid;
procedure FormCreate(Sender: TObject);
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
function IsWin(IsBlack: boolean): boolean;
{ Private declarations }
public
Tag: array[1..18,1..18] of Integer;
{ Public declarations }
end;var
Form1: TForm1;
IsBlack:boolean;implementation{$R *.DFM}
function TForm1.IsWin(IsBlack:boolean):boolean;
label exit1;
var
i,j:Integer;
wtag:Integer;
begin
Iswin:=false;
if IsBlack then
wtag:=1 else
wtag:=2;
for i:=0 to 18 do
for j:=0 to 14 do
begin
if(i<15)
and(Tag[i,j]=wtag)
and(Tag[i+1,j]=wtag)
and(Tag[i+2,j]=wtag)
and(Tag[i+3,j]=wtag)
and(Tag[i+4,j]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
if(Tag[i,j]=wtag)
and(Tag[i,j+1]=wtag)
and(Tag[i,j+2]=wtag)
and(Tag[i,j+3]=wtag)
and(Tag[i,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
if(i<15)
and(Tag[i,j]=wtag)
and(Tag[i+1,j+1]=wtag)
and(Tag[i+2,j+2]=wtag)
and(Tag[i+3,j+3]=wtag)
and(Tag[i+4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
if(Tag[i,j]=wtag)
and(Tag[i-1,j+1]=wtag)
and(Tag[i-2,j+2]=wtag)
and(Tag[i-3,j+3]=wtag)
and(Tag[i-4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
end;
exit1:
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,j:Integer;
begin
for i:=0 to 18 do
for j:= 0 to 18 do
begin
Tag[i,j]:=0;//***Array type required.
end;
IsBlack:=True;
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
end;procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
if Tag[ACol,ARow]=1 then
DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
else if Tag[acol,arow]=2 then
DrawGrid1.Canvas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21)
else
begin
DrawGrid1.Canvas.Pen.Color:=clWhite;
DrawGrid1.Canvas.Brush.Color:=clWhite;
DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21);
end;
end;procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
col,row:integer;
i,j:integer;
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
DrawGrid1.MouseToCell(x,y,col,row);
if Tag[col,row]=0 then
begin
if IsBlack then
begin DrawGrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21);
Tag[col,row]:=1;
end else
begin
DrawGrid1.Canvas.Arc(col*21,row*21,(col+1)*21,(row+1)*21,col*21,row*21,col*21,row*21);
Tag[col,row]:=2
end;
if IsWin(IsBlack) then
begin
if MessageDlg('黑方胜利',mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18 do
for j:= 0 to 18 do
begin
Tag[i,j]:=0;
end;
DrawGrid1.Invalidate;
end;
if not IsBlack then
if MessageDlg('白方胜利',mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18 do
for j:= 0 to 18 do
begin
Tag[i,j]:=0;
end;
DrawGrid1.Invalidate;
end;
end;
IsBlack:=not IsBlack;
end;end;end.
for i:=0 to 18-1 do
才行呀