-2

I'm new to programming, I'm looking to make a command to add and subtract values.

Where I would have a TEdit.Value with the initial value 0 and 2 more buttons, one of " + " and one of " - ", to increase or decrease the value, but I still don't know how to do that, can someone give me one light?

I looked up some examples of how to do this, but I didn't find anything that could help me.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
Bapple
  • 3
  • 2
  • In Delphi you use the `+` and `-` operators for addition and subtraction, respectively. This is documented. – David Heffernan Jan 21 '23 at 07:20
  • To learn the basics, you should look for a book or publication about Delphi. E.g. google for "essential delphi" by Marco Cantú. – Tom Brunberg Jan 21 '23 at 08:28
  • Duplicate of [Delphi: Addition and subtraction](https://stackoverflow.com/q/8635966/4299358) and [Delphi: Arithmetic expression on Wikibooks](https://en.wikibooks.org/wiki/Delphi_Programming/Arithmetic_expression) - I wonder what "_I looked up some examples_" means to you if you haven't found these. – AmigoJack Jan 21 '23 at 08:36

1 Answers1

4

You could use StrToInt() to convert the Edit's current Text string to an integer, then increment/decrement the integer, then use IntToStr() to convert the integer to a string and assign it back to the Text property. For example:

var Value: Integer := StrToInt(Edit1.Text);
Inc(Value); // or Dec()
Edit1.Text := IntToStr(Value);

However, a better option would be to use a UI control that is specifically designed to handle numeric input, such as a TSpinEdit, or a TUpDown attached to an Edit control.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770