const
MapWidth=3;
MapHeight=3;
Maptop=24;
Mapleft=24;
UnitWidth=40;
UnitHeight=40;type
TUnitState = (X, O, Blank);
TMapUnit=array[1..MapWidth, 1..MapHeight] of TUnitState;//------------------------------Custom Class------------------------------------
type TGameMap = class
public constructor Create(DstForm: TForm; AImage : TImage);
procedure MapPaint( DstForm: TForm;
SrcImage: TImage;
x, y: integer;
UnitState: TUnitState;
WholeRepaint: boolean = false);
procedure DrawFrame(DstForm: TForm); protected function GetUnitValue(x, y: integer):TUnitState;
function GetXRect(): TRect;
function GetORect(): TRect;
function GetWidth(): integer;
function GetHeight(): integer; procedure SetUnitState(x, y: integer; UnitState: TUnitState );
procedure SetXRect(ARect: TRect);
procedure SetORect(ARect: TRect);
procedure SetWidth(value: integer);
//[Error] Unit1.pas(66): Unsatisfied forward or external declaration: 'TGameMap.SetWidth'
procedure SetHeight(value: integer);
[Error] Unit1.pas(67): Unsatisfied forward or external declaration: 'TGameMap.SetHeight' private property MapUnit:TMapUnit read GetUnitValue write SetUnitState;
//[Error] Unit1.pas(71): Incompatible types property XRect: TRect read GetXRect write SetXRect;
property ORect: TRect read GetORect write SetORect;
property Width: integer read GetWidth write SetWidth;
property Height: integer read GetHeight write SetHeight;
end;
//------------------------------End Tpye Define---------------------------------function TGameMap.GetXRect(): TRect;
begin
result:=XRect;
end;function TGameMap.GetORect(): TRect;
begin
result:=ORect;
end;function TGameMap.GetWidth(): integer;
begin
result:=Width;
end;function TGameMap.GetHeight(): integer;
begin
result:=Height;
end;procedure TGameMap.SetXRect(ARect: TRect);
begin
XRect:=ARect;
end;procedure TGameMap.SetORect(ARect: TRect);
begin
ORect:= ARect;
end;
各位大虾帮我看一下,这个是我第一次用delphi自定义写类,居然出现这么多错误,555
请各路大虾帮忙啊
MapWidth=3;
MapHeight=3;
Maptop=24;
Mapleft=24;
UnitWidth=40;
UnitHeight=40;type
TUnitState = (X, O, Blank);
TMapUnit=array[1..MapWidth, 1..MapHeight] of TUnitState;//------------------------------Custom Class------------------------------------
type TGameMap = class
public constructor Create(DstForm: TForm; AImage : TImage);
procedure MapPaint( DstForm: TForm;
SrcImage: TImage;
x, y: integer;
UnitState: TUnitState;
WholeRepaint: boolean = false);
procedure DrawFrame(DstForm: TForm); protected function GetUnitValue(x, y: integer):TUnitState;
function GetXRect(): TRect;
function GetORect(): TRect;
function GetWidth(): integer;
function GetHeight(): integer; procedure SetUnitState(x, y: integer; UnitState: TUnitState );
procedure SetXRect(ARect: TRect);
procedure SetORect(ARect: TRect);
procedure SetWidth(value: integer);
//[Error] Unit1.pas(66): Unsatisfied forward or external declaration: 'TGameMap.SetWidth'
procedure SetHeight(value: integer);
[Error] Unit1.pas(67): Unsatisfied forward or external declaration: 'TGameMap.SetHeight' private property MapUnit:TMapUnit read GetUnitValue write SetUnitState;
//[Error] Unit1.pas(71): Incompatible types property XRect: TRect read GetXRect write SetXRect;
property ORect: TRect read GetORect write SetORect;
property Width: integer read GetWidth write SetWidth;
property Height: integer read GetHeight write SetHeight;
end;
//------------------------------End Tpye Define---------------------------------function TGameMap.GetXRect(): TRect;
begin
result:=XRect;
end;function TGameMap.GetORect(): TRect;
begin
result:=ORect;
end;function TGameMap.GetWidth(): integer;
begin
result:=Width;
end;function TGameMap.GetHeight(): integer;
begin
result:=Height;
end;procedure TGameMap.SetXRect(ARect: TRect);
begin
XRect:=ARect;
end;procedure TGameMap.SetORect(ARect: TRect);
begin
ORect:= ARect;
end;
各位大虾帮我看一下,这个是我第一次用delphi自定义写类,居然出现这么多错误,555
请各路大虾帮忙啊
// Class Name: TGameMap
//
// Function Name: Create
//
// Parameter: NONE
//
//
//------------------------------------------------------------------------------constructor TGameMap.Create(DstForm: TForm; AImage : TImage);
begin
Width:= MapWidth;
Height:= MapHeight;
DstForm.Canvas.Brush.Style:=bsSolid; //default Brush Style
DstForm.Canvas.Brush.Color:=RGB(255,255,255); //default Brush Color
CopyRect(XRect, Rect(41, 1, 78, 39) ); //Rect X Image Rect Size=38*38
//[Error] Unit1.pas(132): Constant object cannot be passed as var parameter CopyRect(ORect, Rect(1, 1, 39, 39) ); //Rect O Image Rect Size=38*38
//[Error] Unit1.pas(132): Constant object cannot be passed as var parameter MapPaint(DstForm, AImage, 0, 0, Blank, true);
DrawFrame(DstForm);
end;{------------------------------------------------------------------------------
// Class Name: TGameMap
//
// Procedure Name: MapPaint
//
// Parameter: DstForm: TFrom ---The destination of From, SrcIamge: TImage; Source Image x,y: integer ---Describe the coordinate of where will be painted
//
// UnitState: TUnitState --------set which kind of nuit will be painted
// with value(X, O, Blank)
//
// WholeRepaint: boolean true-----Repaint the whole Map, and skip the
// Parameters on front.
//
// false(default)----Don't repaint the whole Map ,
// just paint map with the Parameters on front.
//
//------------------------------------------------------------------------------}
procedure TGameMap.MapPaint(DstForm: TForm;
SrcImage: TImage;
x, y: integer;
UnitState: TUnitState;
WholeRepaint: boolean = false);
var
i,j: integer;
UnitRect: TRect;
ALeft ,ARight, ATop, AButtom: integer;begin
if WholeRepaint then
begin if UnitState=Blank then //paint blank image.........Iamge size=118*118 pix
begin
UnitRect:=Rect( Maptop+1,
Maptop+1,
Maptop+UnitWidth*x-1,
Maptop+UnitHeight*y-1
) ;
DstForm.Canvas.FillRect(UnitRect);
end else if UnitState=O then //paint O image
begin for i:=1 to width do
for j:=1 to Height do
ALeft:= Mapleft+UnitWidth*i;
inc(ALeft);
ATop:= Maptop+UnitHeight*j;
inc(ATop);
ARight:= ALeft + UnitWidth;
dec(ARight);
dec(ARight);
AButtom:=ATop+UnitHeight;
dec(AButtom);
dec(AButtom);
UnitRect:=Rect(ALeft, ATop, ARight, AButtom); DstForm.Canvas.CopyRect(UnitRect, SrcImage.Canvas, ORect); end else //paint X image
begin
for i:=1 to width do
for j:=1 to Height do
ALeft:= Mapleft+UnitWidth*x;
inc(ALeft);
ATop:= Maptop+UnitHeight*y;
inc(ATop);
ARight:= ALeft+UnitWidth;
dec(ARight);
dec(ARight);
AButtom:= ATop+UnitHeight;
dec(AButtom);
dec(AButtom);
UnitRect:=Rect(ALeft, ATop, ARight, AButtom); DstForm.Canvas.CopyRect(UnitRect, SrcImage.Canvas, XRect);
end;
end else
begin
ALeft:= Mapleft+UnitWidth*x;
inc(ALeft);
ATop:= Maptop+UnitHeight*y;
inc(ATop);
ARight:= ALeft+UnitWidth;
dec(ARight);
dec(ARight);
AButtom:= ATop+UnitHeight;
dec(AButtom);
dec(AButtom);
UnitRect:=Rect(ALeft, ATop, ARight, AButtom); if UnitState=O then
DstForm.Canvas.CopyRect(UnitRect, SrcImage.Canvas, ORect)
else
DstForm.Canvas.CopyRect(UnitRect, SrcImage.Canvas, XRect); end;
end;{------------------------------------------------------------------------------
Class Name: TGameMap Procedure Name: SetUnitState Parameter: x,y:integer position
UnitState: TUnitState UnitaState
-------------------------------------------------------------------------------}
procedure TGameMap.SetUnitState(x, y: integer; UnitState: TUnitState );
begin
MapUnit[x][y]:=UnitState;//[Error] Unit1.pas(256): Left side cannot be assigned to
end;function TGameMap.GetUnitValue(x, y: integer):TUnitState;
begin
result:=MapUnit[x][y];
end;procedure TGameMap.DrawFrame(DstForm: TForm);
var
i:integer;
begin
for i:=0 to width do
begin
DstForm.Canvas.MoveTo(i*UnitWidth, 0);
DstForm.Canvas.LineTo(i*UnitWidth, Maptop+Height*UnitHeight);
end;
for i:=0 to width do
begin
DstForm.Canvas.MoveTo(0, i*UnitHeight);
DstForm.Canvas.LineTo(MapLeft+Width*UnitWidth, i*UnitHeight);
end;
end;
//-----------------------------------------------------------------------------
[Error] Unit1.pas(67): Unsatisfied forward or external declaration: 'TGameMap.SetHeight'
SetWidth和SetHeight可能已经定义了~~你试一下换个名字~~[Error] Unit1.pas(71): Incompatible types
类型不对~~
MapUnit是TMapUnit类型~~和GetUnitValue, SetUnitState不同~~
有一个属性值,
通过Function或Procedure能访问该属性
而且保证在运行时能被正确调用写了就给分,上面的那个问题太复杂了
我想应该还是数据成员未被正确调用,然后TGameMap定义位置出错了的问题现在谁先写个简单的类看看先
TCustomClass = class
private
FName: string;
procedure SetName(value: string);
function GetName;
public
property Name: string read GetName write SetName;
end;
这应该是你想要的
但是怎么掉用,比如 ,我有一个label,和一个button,在buttonclick里点击一下,给FName赋值,然后再在label显示出来,怎么做?我现在在TForm的
pulic
obj:TCustomClass;
然后在click下,obj.name:='123';
form1.label1.caption:=obj.name;运行的时候就会出错
这是为什么啊?