diff --git a/numberediting/numberediting.ico b/numberediting/numberediting.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/numberediting/numberediting.ico differ diff --git a/numberediting/numberediting.lpi b/numberediting/numberediting.lpi new file mode 100644 index 0000000..60d4000 --- /dev/null +++ b/numberediting/numberediting.lpi @@ -0,0 +1,82 @@ + + + + + + + + + <Scaled Value="True"/> + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <XPManifest> + <DpiAware Value="True"/> + </XPManifest> + <Icon Value="0"/> + </General> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + <UseFileFilters Value="True"/> + </PublishOptions> + <RunParams> + <FormatVersion Value="2"/> + <Modes Count="0"/> + </RunParams> + <RequiredPackages Count="2"> + <Item1> + <PackageName Value="LazControls"/> + </Item1> + <Item2> + <PackageName Value="LCL"/> + </Item2> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="numberediting.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="numeditmain.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="numberediting"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Debugging> + <DebugInfoType Value="dsDwarf2"/> + </Debugging> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/numberediting/numberediting.lpr b/numberediting/numberediting.lpr new file mode 100644 index 0000000..b9f1a86 --- /dev/null +++ b/numberediting/numberediting.lpr @@ -0,0 +1,22 @@ +program numberediting; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, lazcontrols, numeditmain + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Scaled:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/numberediting/numeditmain.lfm b/numberediting/numeditmain.lfm new file mode 100644 index 0000000..8dd00f0 --- /dev/null +++ b/numberediting/numeditmain.lfm @@ -0,0 +1,66 @@ +object Form1: TForm1 + Left = 800 + Height = 240 + Top = 281 + Width = 320 + Caption = 'SpinEdit example' + ClientHeight = 240 + ClientWidth = 320 + OnActivate = FormActivate + LCLVersion = '2.0.12.0' + object lblA: TLabel + Left = 56 + Height = 16 + Top = 17 + Width = 55 + Caption = 'integer A' + ParentColor = False + end + object lblB: TLabel + Left = 200 + Height = 16 + Top = 17 + Width = 55 + Caption = 'integer B' + ParentColor = False + end + object seA: TSpinEdit + Left = 23 + Height = 21 + Top = 40 + Width = 129 + MaxValue = 10000 + MinValue = -10000 + OnChange = ChangeAorB + TabOrder = 0 + Value = 10 + end + object seB: TSpinEdit + Left = 160 + Height = 21 + Top = 40 + Width = 136 + MaxValue = 10000 + MinValue = -10000 + OnChange = ChangeAorB + TabOrder = 1 + Value = 10 + end + object DividerBevel1: TDividerBevel + Left = 23 + Height = 16 + Top = 80 + Width = 273 + Caption = 'calculated results' + Font.Style = [fsBold] + ParentFont = False + end + object lbResults: TListBox + Left = 23 + Height = 120 + Top = 104 + Width = 273 + ItemHeight = 0 + TabOrder = 2 + end +end diff --git a/numberediting/numeditmain.pas b/numberediting/numeditmain.pas new file mode 100644 index 0000000..e367f20 --- /dev/null +++ b/numberediting/numeditmain.pas @@ -0,0 +1,114 @@ +unit numeditmain; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Spin, + DividerBevel, math; + +type + + { TForm1 } + + TForm1 = class(TForm) + DividerBevel1: TDividerBevel; + lblB: TLabel; + lblA: TLabel; + lbResults: TListBox; + seA: TSpinEdit; + seB: TSpinEdit; + procedure ChangeAorB(Sender: TObject); + procedure FormActivate(Sender: TObject); + private + procedure UpdateCalculations; + function CalcSum: int64; + function CalcProduct: int64; + function CalcPower: double; + function CalcIntDivision(var isValid: boolean): int64; + function CalcModulus(var isValid: boolean): int64; + function CalcSumOfSquares: int64; + public + + end; + +var + Form1: TForm1; + +implementation + +{$R *.lfm} + +{ TForm1 } + +procedure TForm1.ChangeAorB(Sender: TObject); +begin + UpdateCalculations; +end; + +procedure TForm1.FormActivate(Sender: TObject); +begin + ChangeAOrB(nil); +end; + +procedure TForm1.UpdateCalculations; +var OK: boolean; + n: Int64; +begin + OK := true; + lbResults.Items.Clear; + lbResults.Items.Add('A + B : ' + IntToStr(CalcSum)); + + n := CalcIntDivision(OK); + + if OK then + begin + lbResults.Items.Add('A DIV B : ' + IntToStr(n)); + lbResults.Items.Add('A MOD B : ' + IntToStr(CalcModulus(OK))); + end + else lbResults.Items.Add('A DIV B, A MOD B are not calculable'); + + lbResults.Items.Add('A x B : ' + IntToStr(CalcProduct)); + lbResults.Items.Add('A*A + B*B : ' + IntToStr(CalcSumOfSquares)); + lbResults.Items.Add('A to POWER B : ' + FloatToStr(CalcPower)); +end; + +function TForm1.CalcSum: int64; +begin + Result := seA.Value + seB.Value; +end; + +function TForm1.CalcProduct: int64; +begin + Result := seA.Value * seB.Value; +end; + +function TForm1.CalcPower: double; +begin + Result := intpower(seA.Value, seB.Value); +end; + +function TForm1.CalcIntDivision(var isValid: boolean): int64; +begin + Result := 0; + isValid := (seB.Value <> 0); + if isValid + then Result := seA.Value div seB.Value; +end; + +function TForm1.CalcModulus(var isValid: boolean): int64; +begin + Result := 0; + isValid := (seB.Value <> 0); + if isValid + then Result := seA.Value mod seB.Value; +end; + +function TForm1.CalcSumOfSquares: int64; +begin + Result := seA.Value * seA.Value + seB.Value * seB.Value; +end; + +end. +