UNIT Unit1;
{$MODE OBJFPC}{$H+}{$J-}
Interface
USES
Classes, SysUtils, Forms, Controls, Graphics, uNumEdit,
StdCtrls; // Only for TLabel;
TYPE
TForm1 = Class(TForm)
Procedure FormCreate (Sender: TObject);
Procedure AvgBagsPerPaxExit (Sender: TObject);
Procedure NoContextPopup (Sender: TObject; MousePos: TPoint;
Var Handled: Boolean);
PRIVATE
edtBookedPax,
edtAvgBagsPerPax,
edtTotalBagPieces: TNumEdit; // NumbersOnlyEdit
End; // with/without decimal separator
VAR
Form1: TForm1;
Implementation
{$R *.LFM}
Procedure TForm1.FormCreate(Sender: TObject);
Var
lab: TLabel;
Begin
SetBounds((Screen.WorkAreaWidth -500) Div 2,
(Screen.WorkAreaHeight-300) Div 2,
500, 300);
Constraints.MinHeight:= 200;
Constraints.MinWidth := 400;
edtBookedPax := TNumEdit.Create(Self);
edtBookedPax.Align := alTop;
edtBookedPax.Caption := '202';
edtBookedPax.Font.Size := 20;
edtBookedPax.Font.Quality := fqAntialiased;
edtBookedPax.DecimalSeparator:= False; // Only Numbers
edtBookedPax.OnContextPopup := @NoContextPopup;
edtBookedPax.Parent := Self;
edtAvgBagsPerPax := TNumEdit.Create(Self);
edtAvgBagsPerPax.Align := alTop;
edtAvgBagsPerPax.Caption := '1,3';
edtAvgBagsPerPax.Font.Size := 20;
edtAvgBagsPerPax.Font.Quality := fqAntialiased;
edtAvgBagsPerPax.OnExit := @AvgBagsPerPaxExit;
edtAvgBagsPerPax.OnContextPopup := @NoContextPopup;
edtAvgBagsPerPax.DecimalSeparator:= True; // Numbers and DecimalSeparator
edtAvgBagsPerPax.Parent := Self;
edtTotalBagPieces := TNumEdit.Create(Self);
edtTotalBagPieces.Caption := '';
edtTotalBagPieces.Align := alBottom;
edtTotalBagPieces.Font.Size := 20;
edtTotalBagPieces.Font.Quality := fqAntialiased;
edtTotalBagPieces.DecimalSeparator:= False; // Only Numbers
edtTotalBagPieces.OnContextPopup := @NoContextPopup;
edtTotalBagPieces.Parent := Self;
lab := TLabel.Create(Application);
lab.Font.Size := 15;
lab.Font.Quality:= fqAntialiased;
lab.Align := alBottom;
lab.Caption := 'Edit1 = AvgBagsPerPax'+sLineBreak+
'Edit2 = BookedPax' +sLineBreak+
'Edit3 = TotalBagPieces';
lab.Parent := Self;
End;
Procedure TForm1.NoContextPopup(Sender: TObject; MousePos: TPoint;
Var Handled: Boolean);
Begin
Handled:= True; // don't show context menu (no paste with mouse)
End;
Procedure TForm1.AvgBagsPerPaxExit(Sender: TObject);
Function MyRound(dNum: Double): String;
Begin
If Frac(dNum) = 0
Then Result:= FloatToStr(dNum) // don't round if frac = 0
Else Result:= IntToStr(Trunc(dNum)+1); // round if frac > 0
End;
Begin
// if empty...
If (edtAvgBagsPerPax.Text = '') Or (edtBookedPax.Text = '')
Then
Begin
edtTotalBagPieces.Clear;
Exit;
End;
If Not edtAvgBagsPerPax.IsValidInput // valid decimal or cardinal
Then
Begin
edtAvgBagsPerPax.Clear;
edtTotalBagPieces.Clear;
End
Else edtTotalBagPieces.Text:= MyRound((StrToInt (edtBookedPax.Text) *
StrToFloat(edtAvgBagsPerPax.Text)));
End;
END.