Delphi內有沒有顯示百分比的感應控件?某字段的數據是0.2, 在編輯框內(類似TDBEdit)顯示20%.
如果是DevExpress數據感應控件能實現則更好!

解决方案 »

  1.   

    procedure TForm1.Edit1Exit(Sender: TObject);
    begin
    if Pos('%', edit1.Text) = 0 then
     Edit1.Text := Format('%.2f', [StrToFloatDef(edit1.text, 0)]);
    end;
      

  2.   

    那还不如写在procedure TForm1.DBEdit1Change(Sender: TObject);
    begin
    end;
      

  3.   

    自己写代码实现吧,在field的onchange事件中
      

  4.   

    >>那还不如写在 onchange
    試下再說, 應該有問題的
      

  5.   


    各位大俠: 
    謝謝您們的回復!
    寫代碼當然行的,我的問題是:  Delphi內有沒有顯示百分比的感應控件?
      

  6.   

    我自己的控件包里面有这个,不过没有数据榜定,如果需要,联系我,我只能给你dcu单元
      

  7.   

    procedure TfrmInsSalesInvoice.OnFieldGetText(Sender: TField;
      var Text: string; DisplayText: Boolean);
    begin
      Text := CurrToStr(Sender.AsCurrency * 100) + ' %';
    end;procedure TfrmInsSalesInvoice.OnFieldSetText(Sender: TField;
      const Text: string);
    var
      S, F: string;
      C: Currency;
    begin
      if Pos('%', Text) = 0 then
        F := Trim(Text) + ' %'
      else
        F := Text;  S := Trim(LeftStr(F, Pos('%', F) - 1));
      if (S = '') or (not TryStrToCurr(S, C)) then
      begin
        ShowMessage('Invalid value ' + QuotedStr(F));
        Abort;
      end
      else
      begin
        TryStrToCurr(S, C);
        Sender.AsCurrency := RoundTo(C / 100, -2);
      end;end;procedure TfrmInsSalesInvoice.BindPercentField(aField: TField);
    begin
      aField.OnGetText := Self.OnFieldGetText;
      aField.OnSetText := Self.OnFieldSetText;
    end;