-1

私は Dephi に関する宿題をいくつか持っています (以前は使用したことがなく、c++/Java のみでしたが、私の大学では Delphi 言語の科目があります)。うーん、動くフィギュアで形を作ったり、ぶつかったりとか。抽象クラスのような uint を作り始めました

unit MyFigure;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Buttons, StdCtrls;

type
tPoint = record
 x,y: Double;
end;

oFigure = class
  c: TCanvas;
  pos: tPoint;
  vel: tPoint;
  r: Double;
  constructor create(coord, vect: tPoint; radius: Double);
  protected
    procedure move();
    procedure draw(); virtual;
  public
    function isIntersected(x:oFigure):boolean;
end;

implementation

  constructor oFigure.create(coord, vect: tPoint; radius: Double);
  begin
    pos.x:= coord.x;
    pos.y:= coord.y;
    vel.x:= vect.x;
    vel.y:= vect.y;
    r:=radius;
  end;

  procedure oShape.draw(); virtual;
  begin

  end;

  procedure oShape.move();
  begin
      pos.x:=  pos.x + vel.x;
      pos.y:=  pos.y + vel.y;
      oShape.draw();

  end;

  function isIntersected(o:oFigure):boolean;
  begin
     if ((oShape.pos.x - o.pos.x)*(oShape.pos.x - o.pos.x) +  (oShape.pos.y - o.pos.y)*(oShape.pos.y - o.pos.y)
          < (oShape.r + o.r)*(oShape.r + o.r)) then Result:=True;
  end;



end.

次に、その子を作成しました。さて、ここでキャンバスからアーク メソッドを呼び出してボールを描画する必要がありますが、表示されず、イブはunable to invoke code completion. どうしたの?

unit Ball;

interface
uses
  MyFigure;   
type

oBall = class(oFigure);
    c: TCanvas;
    procedure draw(); override;
 end;

implementation
   procedure oBall.draw();
    begin
       c.Arc()//PROBLEM!
    end;

end.
4

1 に答える 1

0

uses 句でユニットグラフィックスが指定されていないため、コード補完は呼び出されません: Try with

unit Ball;

interface
uses
  Graphics, MyFigure;

ところで、cをインスタンス化していないようです。これにはコンストラクタとデストラクタが必要です。通常の方法は、手続き draw() でパラメータとして TCanvas インスタンスを渡すことです。ユニットoFigureでは、 TPointを定義しますが、TPoint は RTL/VCL のネイティブ タイプです。定義する必要はありません。oFigure では、一部のメソッドを保護として設定していますが、逆説的に前の変数は public です。

于 2012-09-17T21:31:11.170 に答える