[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to format DBTextEdit (float field) as a percent?

Posted on 2009-12-21
7
Medium Priority
?
1,604 Views
Last Modified: 2012-05-08
I have a data entry form that has a DBTextEdit field pulling in a float but when I show the form, it needs to show as a percentage. I have this same field in a grid and the procedure I have is the following:

if (AText <> NULL) OR (AText <> '') then begin
    AText := FloatToStr(StrToFloatDef(AText,0) * 100);
    AText := AText + '%';
  end;

I tried this in both the OnValidate and OnNewLookupDisplayText and those did not work... any ideas how to accomplish this? I'm sure it will be simple and I am just overlooking something really silly... thanks for your help!
0
Comment
Question by:Bianca
  • 3
  • 3
7 Comments
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 26097927
You should use field.ongettext

if (AText <> NULL) OR (AText <> '') then begin
    AText := FormatFloat('#,### %',(StrToFloatDef(AText,0) * 100));

0
 

Author Comment

by:Bianca
ID: 26098366
I dont have an event for OnGetText for the DBTextEdit, I only have that in the grid.
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 26098384
I was meaning in the Table.field.ongettext
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Bianca
ID: 26098571
Oh ok... I already have that procedure for the field in the table but I need to also format to percent for the field that is not in the table, it is just an edit box on a form.
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 26098667
What is the class of the component?
0
 
LVL 9

Accepted Solution

by:
Mahdi78 earned 2000 total points
ID: 26213431
This is my own method :)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables;

type
  TForm1 = class(TForm)
    Table1: TTable;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure MyProcedure(Sender: TField; var Text: string;
      DisplayText: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.MyProcedure(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
if (Sender.AsString <> NULL) OR (Sender.AsString <> '') then
    Text := FloatToStr(Sender.AsFloat * 100) + '%';
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
(Table1.FieldByName('MyField') as TField).OnGetText := MyProcedure;
end;

end.

Open in new window

0
 

Author Closing Comment

by:Bianca
ID: 31668605
Worked great, thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question