把Private改为Protected,你的目的就达到了

解决方案 »

  1.   

    我也看到过有资料上这样说,但我把Private改为Protected后为什么还不行?出的是同样的错误。哪位能给我举个例子?
      

  2.   

    可以的
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Unit2;type
      TTest = class(TForm2)
        procedure ShowTest;
      end;  TForm1 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    {$R *.dfm}{ TTest }procedure TTest.ShowTest;
    begin
      ShowMessage(FTest);
    end;end.
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm2 = class(TForm)
      private
        { Private declarations }
      protected
        FTest: string;
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.dfm}end.
      

  3.   

    >>var
    >>  Form1: TForm1;
    >>  myParams1:TMyparams;
    Form1一般情况下会在工程文件(后缀为dpr)中被实例化,
    这样有些人会误解为将变量定义放在此处就会被自动创建,
    不知你是不是这样认为的。
    !!!myParams1没有被实例化。在执行Button1Click内的代码时肯定会出错。BTW:以后提问中涉及到有出错提示的,能不能将出错的提示也写出来,
    这样对确定问题的原因会有些帮助。