我是新手  我做两个unit文件  一个是窗体   一个是自己定义类  自己定义的类继承label和image组件的属性和方法   在窗体中创建自己定义的类我不知道怎样实现  一个是类的定义(继承的方法) 一个是单元间的调用  希望高手给完整代码   要简 精 

解决方案 »

  1.   

    Unit2
    unit Unit2;interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,StdCtrls;
    type
      Tmylable=class(TLabel)
      end;
    implementationend.Unit1
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    uses Unit2;
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      l:Tmylable;
    begin
      l:=Tmylable.Create(nil);
      l.Parent:=Form1;
      l.Top:=0;
      l.Left:=0;
      l.Caption:='123456789';
    end;end.
      

  2.   

    unit1窗体,unit2类unit2中有你自己定义的类如,TClass1,TClass2等在unit1中引用unit2,然后声明变量 class1:TClass1,class2:TClass2等使用时,先创建实例 calss1 := TClass1.create等
      

  3.   

    要同时继承image和label呢   要怎样销毁
      

  4.   

    要同时继承image和label时要怎么定义  报错呀  my=class(timage,tlabel);
      

  5.   

    不是这么继承的,你如果想继承两个类,先定义一个类如TimageBase继承Timage,再定义my = class(TimageBase)
    my1: my;使用时创建my1 := my.create(nil);不建议使用DESTROY重载,
    建议使用FREEANDNIL释放
      

  6.   

    能否给出简单代码  继承image和label两个的类
      

  7.   

    unit untImgBase;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TImgBase = class(TImage)
      private
        { Private declarations }
      public
       重载函数或者新定义函数声明
        { Public declarations }
      end;implementation{$R *.dfm}
    重载函数或者新定义函数实现
    end.
    unit untMyImg;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TMyImg = class(TImgBase)
      private
        { Private declarations }
      public
        { Public declarations }
      重载函数或者新定义函数声明
      end;implementation{$R *.dfm}
    重载函数或者新定义函数声明end.