修正TiAnlogDisplay显示的问题

原来在DELPHI7下的程序移到XE2下,修修改改,总算行了。一直没注意这个TiAnlogDisplay控件,界面上用了好多这个控件,运行,显示为空,也不报错。看设计界面,也是空的,本来应当显示初始值的。用的是6.0.4 for xe2(网友自己改的),相同的源码在D7下没问题,这就奇怪了。再放个TiAnlogOuput控件(父类是TiCustomEdit),显示也没问题。这2个控件都继承自TiComponent,(中间的一些控件和显示无关),是控件自己的问题了。看源码,也看不出有什么不同的地方。它们的显示都是通过PaintTo这个方法,设断点,出问题了:

procedure TiAnalogDisplay.iPaintTo(Canvas: TCanvas);
var
  AText      : String;
  ATextRect  : TRect;
  ATextFlags : TiTextFlags;
begin
  with Canvas, ATextRect do
    begin
      if not ErrorActive then
        begin
          if FPrecision >= 0 then
            AText := Trim(Format('%.' + IntToStr(FPrecision) + 'f', [FValue])) + FUnitsText
          else
            AText := Trim(Format('%g', [FValue])) + FUnitsText;

          Font.Assign(FFont);
          DrawBackGround(Canvas, BackGroundColor);
        end
      else
        begin
          AText := ErrorText;
          Font.Assign(ErrorFont);
          DrawBackGround(Canvas, ErrorBackGroundColor);
        end;

      case BorderStyle of
        ibsNone    : begin
                      ATextRect.Top    := 2;
                      ATextRect.Bottom := Height - 2;
                     end;
        ibsRaised  : begin
                      ATextRect.Top    := 2;
                      ATextRect.Bottom := Height - 2;
                     end;
        ibsLowered : begin
                      ATextRect.Top    := 2;
                      ATextRect.Bottom := Height - 4;
                     end;
      end;

      case FAlignment of
        iahCenter : begin
                      ATextFlags := [itfHCenter, itfVCenter, itfSingleLine];
                      ATextRect.Left  := 2;
                      ATextRect.Right := Width - 2;
                    end;
        iahLeft   : begin
                      ATextFlags := [itfHLeft, itfVCenter, itfSingleLine];
                      ATextRect.Left  := 2 + FAlignmentMargin;
                      ATextRect.Right := Width - 2;
                    end;
        else        begin
                      ATextFlags := [itfHRight, itfVCenter, itfSingleLine];
                      ATextRect.Left  := 2;
                      ATextRect.Right := Width - 2 - FAlignmentMargin;
                    end;
      end;

      Brush.Style := bsClear;
      iDrawText(Canvas, AText, ATextRect, ATextFlags, True, BackGroundColor);
    end;
end;

这儿的Right和Bottom值变成一个巨大的数!(如44062789),Hight和Width本身的值没问题,但是代码的运算(简单运算,不就是减个常数),Bottom和Right就变成一个巨大数了,怀疑表达式中的Hight和Width在运算的时候被替换了,真奇怪啊

修改成这样:

procedure TiAnalogDisplay.iPaintTo(Canvas: TCanvas);
var
  AText      : String;
  ATextRect  : TRect;
  ATextFlags : TiTextFlags;
begin
  with Canvas, ATextRect do
    begin
      if not ErrorActive then
        begin
          if FPrecision >= 0 then
            AText := Trim(Format('%.' + IntToStr(FPrecision) + 'f', [FValue])) + FUnitsText
          else
            AText := Trim(Format('%g', [FValue])) + FUnitsText;

          Font.Assign(FFont);
          DrawBackGround(Canvas, BackGroundColor);
        end
      else
        begin
          AText := ErrorText;
          Font.Assign(ErrorFont);
          DrawBackGround(Canvas, ErrorBackGroundColor);
        end;

      case BorderStyle of
        ibsNone    : begin
                      ATextRect.Top    := 2;
                      ATextRect.Bottom := Self.Height - 2;
                     end;
        ibsRaised  : begin
                      ATextRect.Top    := 2;
                      ATextRect.Bottom := Self.Height - 2;
                     end;
        ibsLowered : begin
                      ATextRect.Top    := 2;
                      ATextRect.Bottom := Self.Height - 4;
                     end;
      end;

      case FAlignment of
        iahCenter : begin
                      ATextFlags := [itfHCenter, itfVCenter, itfSingleLine];
                      ATextRect.Left  := 2;
                      ATextRect.Right := Self.Width - 2;
                    end;
        iahLeft   : begin
                      ATextFlags := [itfHLeft, itfVCenter, itfSingleLine];
                      ATextRect.Left  := 2 + FAlignmentMargin;
                      ATextRect.Right := Self.Width - 2;
                    end;
        else        begin
                      ATextFlags := [itfHRight, itfVCenter, itfSingleLine];
                      ATextRect.Left  := 2;
                      ATextRect.Right := Self.Width - 2 - FAlignmentMargin;
                    end;
      end;

      Brush.Style := bsClear;
      iDrawText(Canvas, AText, ATextRect, ATextFlags, True, BackGroundColor);
    end;
end;

OK,好了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值