我写的一个控件,有2个属性A、B,如下:
published
  property A: Boolean read FA write SetA;
  property B: string read FB write SetB;  其中SetA中用到属性B,且B不能为空,如下:
  procedure SetA(Value: Boolean)
  begin
    if FA<>Value then
      case Value of 
        True : begin
                 use B 处理...
               end;
        False:  begin
                   ...
                end;
      end;
      FA:=Value;
  end;
在窗体上放置该控件,设置B的内容,然后置A=True;但是在运行程序的时候,提示B为空(在SetA中出错),
我跟踪了一下,在控件中先执行SetA,然后才执行SetB,所以出错了。
假如我把属性A的名字改为C,那么程序就会先执行SetB,这样便不会报错了。
另外,在程序中动态给属性B赋值,然后设置属性A=True,也不会报错。像以下那样更换顺序也不行
published
  property B: string read FB write SetB;
  property A: Boolean read FA write SetA;我怎么样才能让 setB先执行呢?

解决方案 »

  1.   

    你可以在B中设置一个开关,来设置B的true,false,然后在A中去判断这个标识是否变为true,如果没有就直接调用B;或者你就把B写到A中,但是通过判断条件,外面也可以调用就行
      

  2.   

    不行啊,如果行的话早就这样做了。
    就是必须先执行setB,再执行SetA,但是在创建对象后却先执行了setA
      

  3.   

    property A: Boolean read FA write SetA default false;
      

  4.   

    在Create中给B赋初值, 装入A时,因B已经有值,就不会出错了
      

  5.   

    published
      property A: Boolean read FA write SetA default true;
      property B: string read FB write SetB default true;
    ;