Jump to content

Delphi help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Nefrit

Nefrit

    Newbie

  • Members
  • PipPip
  • 12 posts
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:
sig spam deleted by management.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
poots

poots

    Newbie

  • Members
  • Pip
  • 3 posts
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.