delphi面向对象编程问题
我想学习面向对象编程,想做一个系统自带的“挖地雷”那个小游戏,我想把地雷定义一个类,我在单独的单元DiLei中这样定义:
unit Dilei;
interface
uses
Buttons;
type
TDiLei = class //地雷类别
private
{ Private declarations }
public
btn: TSpeedButton; {按钮}
btnLeft: Integer;{left}
btnTop: Integer;
btnWidth: Integer;
btnHeight: Integer;
constructor create(l,t: Integer);overload;
{ Public declarations }
end;
implementation
constructor TDiLei.create(l,t: Integer);
begin
Self.btn := TSpeedButton.Create(Self);
Self.btn.Width := 22;
Self.btn.Height := 22;
Self.btn.Left := l;
Self.btn.Top := t;
Self.btn.Show
end;
end.
//////////////////////////////////////////////////////////////////////////////////////
然后在窗口OnShow的时候全部创建这些地雷:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons,Dilei;
type
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
dl: array [1..20,1..20] of TDiLei;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
i,j :Integer;
begin
for i:= 1 to 20 do
begin
for j := 1 to 20 do
begin
dl[i,j] := TDiLei.create((j-1)*22,(i-1)*22);
end;
end;
end;
end.
但是编译说我的那个"Self.btn := TSpeedButton.Create(Self);"中的self不兼容,怎么做才能显示出来?
unit Dilei;
interface
uses
Buttons;
type
TDiLei = class //地雷类别
private
{ Private declarations }
public
btn: TSpeedButton; {按钮}
btnLeft: Integer;{left}
btnTop: Integer;
btnWidth: Integer;
btnHeight: Integer;
constructor create(l,t: Integer);overload;
{ Public declarations }
end;
implementation
constructor TDiLei.create(l,t: Integer);
begin
Self.btn := TSpeedButton.Create(Self);
Self.btn.Width := 22;
Self.btn.Height := 22;
Self.btn.Left := l;
Self.btn.Top := t;
Self.btn.Show
end;
end.
//////////////////////////////////////////////////////////////////////////////////////
然后在窗口OnShow的时候全部创建这些地雷:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons,Dilei;
type
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
dl: array [1..20,1..20] of TDiLei;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
i,j :Integer;
begin
for i:= 1 to 20 do
begin
for j := 1 to 20 do
begin
dl[i,j] := TDiLei.create((j-1)*22,(i-1)*22);
end;
end;
end;
end.
但是编译说我的那个"Self.btn := TSpeedButton.Create(Self);"中的self不兼容,怎么做才能显示出来?
...全文
相关推荐
Delphi面向对象编程思想
面向对象编程不仅仅是一种编程技巧,更是一种思考问题的方式。它通过将复杂问题抽象成对象,然后在对象之间定义清晰的接口和责任来解决问题。
Delphi实现骑士周游(走马)问题完整解决方案
骑士周游问题(Knight’s Tour)是图论与算法领域中的一个经典问题,其核心在于找出一条路径,使国际象棋中的“骑士”(马)从某一初始位置出发,恰好访问棋盘上的每一个格子一次。该问题本质上是一个回溯问题,具有NP难的复杂度,因此在算法设计中常作为递归与状态搜索的典型示例。Delphi语言凭借其高效的执行性能和良好的结构化编程支持,成为实现该问题求解的理想工具。本章将引导读者理解问题的数学模型与算法意义,为后续章节的代码实现与优化打下坚实基础。
Delphi面向对象编程思想附书源码
《Delphi面向对象编程思想》是一本专注于介绍如何在Delphi环境下运用面向对象编程的书籍。
delphi面向对象编程思想pdf.rar
**设计模式**:面向对象编程中的设计模式是解决常见问题的模板,例如工厂模式、观察者模式等。本书可能会深入讲解如何在Delphi中应用这些设计模式,提升代码质量。10.
(刘艺)《+Delphi面向对象编程思想》随书光盘下载+
**设计模式**: 设计模式是解决软件开发中常见问题的成熟解决方案,如单例模式、工厂模式、观察者模式等。书中可能探讨如何在Delphi中应用这些模式,提升代码质量和可维护性。5.


