unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Unit2;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    Procedure ShowName(Intf:IFormattedNumber);
    Procedure ShowNameConst(const Intf:IFormattedNumber);
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}
unit Unit2;interface
uses
    Classes,SysUtils,Dialogs;
type
    IFormattedNumber = interface
        ['{2985B72E-B441-4D9F-99B0-DAED049CB1D2}']
        function FormattedString: string;
        function Getname: string;
    end;    TFormattedInteger = class(TInterfacedObject, IFormattedNumber)
    private
        FValue : Integer;
    Public
        constructor Create(AValue:Integer);
        destructor Destroy; override;
        function FormattedString: string;
        function GetName: string;
    end;
    TFormattedHexInteger = class(TFormattedInteger, IFormattedNumber)
    public
        destructor Destroy; override;
        function FormattedString: string;
        function GetName: string;
    end;implementationuses
    Unit1;constructor TFormattedInteger.Create(AValue: Integer);
begin
    inherited Create;
    FValue := AValue;
end;
destructor TFormattedInteger.Destroy;
begin
    Form1
为什么我在unit2中用from1的Memo1用不上可能什么原因谢谢!

解决方案 »

  1.   

    为什么你在unit2中用from1的Memo1,你的unit2既然是个接口,那就不应该依赖其他单元,尤其像unit1这样的
      

  2.   

    interface好像是为了弥补delphi不能继承自多类而增加的,没有深入的研究过,不过你在析构函数中调用Unit1的组建是何用意那???
      

  3.   

    可以用啊,
    先ctrl + shift + c 把函數實現框架搭起來,怎麽可能用不了?