TWinControl の解説
A-3 :同じソース


  Unit のソース                 / A-1   A-2   A-4   A-5   A-6  


次に、Unit を作成します。
……と言いたいところですが今回は作成する必要がありません。
Section1 で作成したプログラムをそのまま使うことにしましょう。

中身は一切書き換えなくて OK です



手順1: 確認の為 Section1 の各ソースと比べてみて下さい。
      (各 Unit のバーに Section1 へのリンクを設置してあります)
手順2: ソースがまったく同じだということを確認したら、次の節に進みましょう。





  Unit1 のソース               / Section 1-3 ( Unit1 )


unit Unit1;

interface

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

type
 TCatA = class (TImage)

 private
  { Private 宣言 }
 public
  { Public 宣言 }
  RL :Boolean;
  procedure ShowImage(CatPlace: TWinControl);
end;

var
 CatA: TCatA;

implementation

procedure TCatA.ShowImage(CatPlace: TWinControl);
begin
 Parent := (CatPlace);
 Picture.LoadFromFile('bmp\Cat1.bmp');

 Stretch := True;
 Transparent:= True;
 AutoSize := True;
 Visible := True;
 Left := 0;
 RL := False;
end;

end.




  Unit2 のソース               / Section 1-4 ( Unit2 )


unit Unit2;

interface

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

type
 TCatB = class (TCatA)

 private
  { Private 宣言 }
 public
  { Public 宣言 }
 procedure Click; override

end;

var
 CatB: TCatB;

implementation

procedure TCatB.Click;
begin
inherited;
 MainForm.MP.FileName := ('cat1.wav');
 MainForm.MP.Play;
end;

end.




  Unit3 のソース               / Section 1-5 ( Unit3 )


unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
StdCtrls, Dialogs, ExtCtrls, MainUnit, Unit1, Unit2;

type
 TCatC = class (TCatB)

 private
  { Private 宣言 }
 public
  { Public 宣言 }
 procedure CATMOVE(CatPlace: TWinControl);

end;

var
 CatC: TCatC;

implementation

procedure TCatC.CATMOVE(CatPlace: TWinControl);
begin
 if RL = True then begin
  if CatC.Left <= CatC.Width -40 then begin
   CatC.Picture.LoadFromFile('Cat1.bmp');
   CatC.Left := 0;
   RL := False;
  end
   else

    Catc.Left:=CatC.Left -3;
 end

 else begin
  if
CatC.Left > Parent.Width - CatC.Width - 15 then in
   CatC.Picture.LoadFromFile('Cat2.bmp');
   CatC.Left := Parent.Width - CatC.Width -15;
   RL := True;
  end
   else

    Catc.Left := CatC.Left +3;
 end;
end;

end.



トップに戻る /  前に戻る /  次へ