Calculated TEdit in a form

Hi everyone...

In a form I have, a TDBEdit object displays a numeric value from my table. I placed a TEdit object near it, on the same form, and I'd like to have it reflect that amount multiplied times 1.15.

How can I do it?
Can it display itself conditionally based on the value of a TDBCheckBox on the same form? (It's also the same table.)
How can I have an edit box to make the 1.15 modifiable by the user?

Thanks, best regards.
Eduardo
Eduardo1Asked:
Who is Participating?
 
intheConnect With a Mentor Commented:
you can use something like this to change the value:

procedure TForm1.Button2Click(Sender: TObject);
var
   Nombre:string;
   PulsoOk:boolean;
 begin
   PulsoOk:= InputQuery('hello',
      'please enter number...', Nombre);
   if PulsoOk
     then
{save this number in variable or registry or ini file etc..}
  else ShowMessage('no number');
 end;

then TDBEdit onchange event do
edit1.text := strtoint(TDBEdit.text * variable you saved);
0
 
Eduardo1Author Commented:
We're almost there...!!!

What I have right now is this:

procedure TfrmDepartamentos.DBEdit5Change(Sender: TObject);
begin
   if DBCheckBox1.Checked then
   editConIva.Text:=InttoStr(StrtoInt(DBEdit5.text)*2)
   else
   editConIva.Text:='';
end;

1. I need to insert a real type where the number 2 is, but there's no such thing as RealtoStr or StrtoReal.
2. When I get to a record where DBCheckBox1.Checked = True, the value doesn't show on the same record, but on the next one that appears on the form.

Thanks for your help.
0
 
intheCommented:
ok i will see what i can do in a test later and let you know.

0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
intheCommented:
ahh i forget to convert real to string and string to real you can use FloattoStr() and StrToFloat() functions instead.

and for the value doesn't show on the same record maybe it will work better on the DBEdits OnEnter or OnExit events..
0
 
Eduardo1Author Commented:
Victory!!!

I used the FloattoStr() and StrtoFloat() functions, and they worked great.

I placed the code:

   if DBCheckBox1.Checked then
   editConIva.Text:=FloattoStr(StrtoFloat(DBEdit5.text)*1.15)
   else
   editConIva.Text:='';

in the DBNavigator OnClick event handler. Then I tested checking the checkbox on the first record, and when it didn't work I copied the code and added it to the FormCreate event. That did it!

Thanks inthe... you pressed the right buttons in my brain so we could both solve this.

I feel good...!
0
 
intheCommented:
hehe no problem ,
glad to be of help ;-)
see you again
Regards Barry
0
All Courses

From novice to tech pro — start learning today.