Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Delphi help

delphi

  • Please log in to reply
2 replies to this topic

#1 Nefrit

Nefrit

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 28 November 2007 - 11:58 PM

I decided to test my Delphi knowlege today by making myself a calculator. Took me a while, bu I figured most of it out. It all works well, except for one problem.

If, for example, you press 9 + 2 + 5, what I'd love it to do is to clear the screen when the next button after the plus sign is pressed, entering only the value of that button, clearing the values that were there before it. Can anyone help? I know that it's probably some sort of On..... thing.

Anyone here insane enough to know any Delphi anyway?
:loading::compress:
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 29 November 2007 - 09:16 AM

Delphi is the language I use at work.

You haven't given us much of anything to work with right now. Not knowing anything about the form you're using, or the logic used, I can't offer much.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 poots

poots

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 25 February 2008 - 12:15 PM

the problem you'll be having is that any event fired from within a tedit box will blow up if you try to clear it from inside that event.

This may not be the best solution, but it's the best that comes to mind. You need a form with a tedit and a tmemo on it. The Tmemo contents will be what you need to parse to do the maths.

unit Calcstarter;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
Operators : Set of Char;
Numerals : set of Char;
Specials : set of Char;
public
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
KeyPreview :=true; //this ensures the form gets first look at what's typed
edit1.readonly := true;//to stop users actively entering in it
Operators := ['/','+','-','*'];
Numerals := ['0'..'9'];
Specials := ['.' , ',' , '='];
end;


procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key in Operators then
begin
if length(edit1.text) <> 0 then
begin
memo1.Lines.Add(Key );
memo1.lines.Add(edit1.Text );
edit1.Text := '';
end;
end;

if ((key in Numerals) or (key in Specials)) then
begin
Edit1.Text := edit1.Text + key;
end;
end;

end.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download