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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

sum up currencyedits

I have about 10 currencyedit's and would like to sum them up in one currencyedit.
How and what would be the best way ?
0
Vrtnar
Asked:
Vrtnar
  • 7
  • 5
1 Solution
 
EddieShipmanCommented:
name them consecutively like this edtCurr1, edtCurr2, ..edtCurr10, and
use the FindComponent method like this:

var
  i: Integer;
  c: Extended;
  e: TEdit;
begin
  c := 0.0;
  for i := 1 to 3 do
  begin
    e := TEdit(FindComponent('edtCurr'+ IntToStr(i)));
    c := StrToFloat(e.Text) + c;
  end;
  Edit4.Text := FloatToStr(c);
end;
0
 
EddieShipmanCommented:
oops, change the for to 1 to 10.
and change Edit4.Text to edtCurr11.Text

only had 3 on my form for testing.
0
 
VrtnarAuthor Commented:
any alternatives to renaming ??
0
Industry Leaders: 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!

 
VrtnarAuthor Commented:
I raised an exception class... RConvert error - ''' is not a valid floating value
when I tried your suggestion...
Does not work...
0
 
VrtnarAuthor Commented:
It seems that when the value of the currencyedit is 0,00 €
then the exception is raised...
0
 
VrtnarAuthor Commented:
it seems I must set  zeroempty = False of the curredits to get this thing to work...
0
 
VrtnarAuthor Commented:
eddie...I have made this work by changing the zeroempty thinggie...
Is there a way to update the currency13 (the one that sums up)
when onchange of the currencyedits occur without having to write
every single onchange event of each curredit??
0
 
EddieShipmanCommented:
You can set them all to the same OnChange event to do the computation.
0
 
EddieShipmanCommented:
Or if you have other code in the Onchange events, write a separate method to do the change and
call it from each of them.
0
 
VrtnarAuthor Commented:
"You can set them all to the same OnChange event to do the computation" -
can you give me an example,please...??
0
 
EddieShipmanCommented:
if you have one OnChange event, set the OnChange event for ALL your edits to the same
event handler in th eObject Inspector, use the dropdown and select the correct handler.
0
 
VrtnarAuthor Commented:
well..I learn something new in Delphi every day...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now