How to make a calculator?

I want to create a calculator. How can I make a Window where the numbers can be printed. I've tried, but when i press at t.ex. '1' then '2' then '3' it prints 321 ! I want it to print 123 as a regular calculator.
Suggestions?
MonsemannAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hu? What window do you use? If you have a normal TEdit then the numbers appear in the same order as they are typed.

You can also use a string to hold all input of the user by adding each new character to the end of the string. Then use either your own output function or assign the string to a control which can display it (e.g. TLabel.Caption).

Ciao, Mike
0
men xinCEOCommented:
what?i can't understand your means?;-(
0
intheCommented:
yep
 one of my first projetcs was to write calculator and i used a tedit.
i remember this was also a question of mine when i was new to delphi using buttons for the numbers.
if i remember right just do on the  button click:


Edit1.Text:=Edit1.Text + 1  (<- the number)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

BatalfCommented:
Hi pall!

Do you use an edit-component as the display of your calculator?

In that case, I assume that your code when you press a button is :

edit1.text := edit1.text + button1.caption;

Have you tried this instead :
edit1.text:=button1.caption+edit1.text;

Regards
Batalf
0
gallagheCommented:
Unless you need special functionality, why not use a prebuilt calculator. For instance the freeware library called RX has a calculator with source code. As is you can not use it w/o RX. What I did was fixed it so that it works outside of RX.

If this is a possiblity I can email u the RX calc which I cut loose from the RX library.

Let me know

kevin.s.gallagher@state.or.us
0
intheCommented:
if you are new to delphi you can go to places like here:

http://www.torry.ru/math.htm

and get freeware components to either install or read the source code of to see how some stuff is done.


0
BatalfCommented:
Some additional comments+ a correction :

Do you use an edit-component as the display of your calculator?

In that case, I assume that your code when you press a button is :

ex : for the button "1" :

when you click it, you have this code :

edit1.text:='1'+edit1.text;


Have you tried this instead :

edit1.text := edit1.text + '1'

If you do this, the number you click would be placed at the eand of the numbers in the display instead of at the front(eks : 33+1 = 331, instead of 133)

Regards
Batalf
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
intheCommented:
um didnt i just say that.. ?
0
BatalfCommented:
To Inthe

Sorry

I didn't read what you typed.

My last comment was just a correction of my first, which I wrote when you probably was writing your comment.

I also thought that some explanation could be useful.



0
aubsCommented:
If you use the button caption like Batalf mentioned you could use code like this:

procedure TForm1.ButtonClick(Sender: TObject);
begin
  edit1.text:= edit1.text + (sender as TButton).caption;
end;

Then make all the click events for the buttons  '.', 0, 1, 2... 9 call this procedure.
0
BatalfCommented:
My comment above
0
MonsemannAuthor Commented:
Thank You!
You're an excellent expert!

Monsemann
0
LischkeCommented:
Strange decision, I as well as Barry have told the same stuff before Batalf, and you haven't shown any reaction....
0
MonsemannAuthor Commented:
To 'Lischke'

When I checked the answers to my question today, were all these comments there already. In other words: I recieved them all at the same time!
I had to choose one of the answers.
I don't think You understood my problem (or maybe I didn't understand the answer...). Therfore I rejected Your comment. Then I tryed 'inthe's answer. It didn't work!
'Batalf's answer did work!
Now i know why:
Inthe's command:    Edit1.Text + 1
Batalf's command:   Edit1.Text + '1'
You can see the difference....
I couldn't give them t.ex. 100 points each - I had to choose.
Therefor I chose the one who gave me the command that worked!

Monsemann

-who is 'Barry'?????
0
LischkeCommented:
inthe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.