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:
Delphi help
Started by Nefrit, Nov 28 2007 11:58 PM
2 replies to this topic
#1
Posted 28 November 2007 - 11:58 PM
sig spam deleted by management.
|
|
|
#2
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.
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.
#3
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.
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.


Sign In
Create Account


Back to top









