Now I have been doing pascal for three months. I am now trying to create a simple calculator program. However, the TEdit box is not working. I type in the value but it seems it is not recording since when converted to either a float or int it states that its value is "" meaning it hasn't taken in the data that was entered. How can i get around this. my code is below:
unit calc;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls;
type
{ TCalculator }
TCalculator = class(TForm)
CbOperation: TComboBox;
edNum1: TEdit;
edNum2: TEdit;
lblTotal: TLabel;
lblNumber1: TLabel;
lblNumber2: TLabel;
procedure CbOperationChange(Sender: TObject);
procedure CbOperationSelect(Sender: TObject);
procedure edNum1Change(Sender: TObject);
procedure edNum2Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Calculator: TCalculator;
total,num1,num2:real;
implementation
{ TCalculator }
procedure TCalculator.CbOperationChange(Sender: TObject);
begin
end;
procedure TCalculator.CbOperationSelect(Sender: TObject);
begin
if cbOperation.items.text = 'add' then
total:=num1+num2;
if cbOperation.items.text = 'subtract' then
total:=num1-num2;
if cbOperation.items.text = 'multiply' then
total:=num1*num2;
lblTotal.caption:=floattostr(total);
end;
procedure TCalculator.edNum1Change(Sender: TObject);
begin
num1:=strtofloat(edNum1.text);
end;
procedure TCalculator.edNum2Change(Sender: TObject);
begin
num2:=strtofloat(edNum2.text);
end;
initialization
{$I calc.lrs}
num1:=0;
num2:=0;
total:=0;
end.