Hiya all,
Im new to delphi and have been creating a compent to work out the average speed for a person in a race. The compent works fine but im wanting to put in error messages with in the code that pop up a show message display.
What im trying to do is say the user enters a number into the edit box instead of a letter it will pop up a show message box saying 'Only enter letters please' This is for edit box1 in my code.
For the other edit boxs 2 and 3 the message will say ' Only enter numbers please'
Hope this makes you understand what im trying to do. All but if there is a way only to let edit boxes take numbers or text that would be great to.
Thanks for you help looking forward to your replies, a new delphi user. I know it sounds simple but having difficulties thanks.
Code below
-----------------------------------------------------
unit CustomPanel2;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, StdCtrls;
type
TDisplayAverage = class(TCustomPanel)
fButton1: TButton;
private
fLabel1: Tlabel;
fLabel2: Tlabel;
fLabel3: Tlabel;
fLabel4: Tlabel;
fLabel5: Tlabel;
fEdit1: TEdit;
fEdit2: TEdit;
fEdit3: TEdit;
FOnClick_FButton1: TNotifyEvent;
{ Private declarations }
protected
procedure Click_fButtonAverage(Sender: TObject); Virtual; {TNotifyEvent}
property Label1: Tlabel read fLabel1 write fLabel1;
property Label2: Tlabel read fLabel2 write fLabel2;
property Label3: Tlabel read fLabel3 write fLabel3;
property Label4: Tlabel read fLabel4 write fLabel4;
property Label5: Tlabel read fLabel5 write fLabel5;
property Edit1: TEdit read fEdit1 write fEdit1;
property Edit2: TEdit read fEdit2 write fEdit2;
property Edit3: TEdit read fEdit3 write fEdit3;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
// destructor destory; override;
{ Public declarations }
published
property OnClick_fButton1: TNotifyEvent read FOnClick_fButton1 write FOnClick_fButton1;
{ Published declarations }
end;
var
time, distance: integer;
result: real;
procedure Register;
implementation
procedure TDisplayAverage.Click_fButtonAverage(Sender: TObject);
begin
time:= StrToInt (Edit2.Text);
distance:= StrToInt (Edit3.Text);
result:= time / distance;
Label5.caption:= floattostr(result);
if assigned(FOnClick_fButton1) then
FOnClick_fbutton1(Self);
end;
constructor TDisplayAverage.Create(AOwner: TComponent);
begin
inherited Create (AOwner);
bevelinner := bvlowered;
Name :='o';
height :=180;
width :=340;
// Bevelinner sets the bevel on the panel and the height and width set the
// panel size.
fEdit1 := TEdit.Create(self);
with fEdit1 do
begin
left := 150;
top :=20;
Parent:= self;
end;
fEdit2 := TEdit.Create(self);
with fEdit2 do
begin
left := 150;
top :=60;
Parent:= self;
end;
fEdit3 := TEdit.Create(self);
with fEdit3 do
begin
left := 150;
top :=100;
Parent:= self;
end;
fLabel1 := TLabel.Create(Self);
with flabel1 do
begin
Caption := 'Enter your name:';
left := 10;
top :=20;
Parent := Self;
end;
fLabel2 := TLabel.Create(Self);
with flabel2 do
begin
Caption := 'Enter your finishing time:';
left := 10;
top :=60;
Parent := Self;
end;
fLabel3 := TLabel.Create(Self);
with flabel3 do
begin
Caption := 'Enter Distance:';
left := 10;
top :=100;
Parent := Self;
end;
fLabel4 := TLabel.Create(Self);
with flabel4 do
begin
Caption := '=';
left := 230;
top := 145;
Parent := Self;
end;
fLabel5 := TLabel.Create(Self);
with flabel5 do
begin
Caption := '';
left := 235;
top := 140;
font.size := 16;
Parent := Self;
end;
fButton1:= TButton.create(Self);
with fButton1 do
begin
width:= 200;
height:= 25;
left := 10;
top := 140;
Caption:= 'Calculate Average Speed for Race';
Parent:= Self;
OnClick := Click_fButtonAverage;
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [TDisplayAverage]);
end;
end.