新建一个组件,从TCustomEdit继承,新组件与TEdit差不多,就是多了一个属性:property con_enable:boolean read ……;以及两个私有变量tempstr1:string;
tempstr2:string;现在想根据con_enable的值是true还是false,决定在新组件的Text属性中显示
tempstr1 还是 tempstr1+tempstr2;怎样才能做到?

解决方案 »

  1.   

    分别定义如下
    private
      Fcon_enable:Boolean;
    procedure Setcon_enable;
    property con_enable:boolean read Fcon_enable write Setcon_enable;proceduer Setcon_enable;
    begin
      if con_enable then Text:=tempstr1
      else Text:=tempstr1+tempstr2;
    end;大体思路如上,你下看看可否满足要求
      

  2.   

    to  u2m:这段代码当然是需要的,问题是如何将改变的信息传递并引发这段代码。看了一些VCL,发现好像是overide ‘paint’过程,并在新的paint过程引发变化,真的是这样吗?
      

  3.   

    private
      Fcon_enable:Boolean;
    procedure Setcon_enable(const Value: boolean);
    published
    property con_enable:boolean read Fcon_enable write Setcon_enable;procedure Setcon_enable(const Value: boolean);
    begin
      Fcon_enable := Value;
      if con_enable then Text:=tempstr1
      else Text:=tempstr1+tempstr2;
    end;
    没有必要overidepaint过程的
      

  4.   

    可以继承Paint方法,也可以自己写对应的消息处理函数来实现。
    在处理过程中加入对Fcon_enable的判断即可。
      

  5.   

    谢谢各位,但是U2m和 wwjwang的代码不完整,hehe,是死循环,需要稍稍改写一下