Link to home
Start Free TrialLog in
Avatar of Monsemann
Monsemann

asked on

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?
Avatar of Lischke
Lischke

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
what?i can't understand your means?;-(
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)
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
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
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.


ASKER CERTIFIED SOLUTION
Avatar of Batalf
Batalf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
um didnt i just say that.. ?
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.



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.
My comment above
Avatar of Monsemann

ASKER

Thank You!
You're an excellent expert!

Monsemann
Strange decision, I as well as Barry have told the same stuff before Batalf, and you haven't shown any reaction....
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'?????
inthe