1
0

Add numberediting example

This commit is contained in:
Timothy Warren 2021-10-12 15:20:49 -04:00
parent c031017ad9
commit 0f547c38ff
5 changed files with 284 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="numberediting"/>
<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>

View File

@ -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.

View File

@ -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

View File

@ -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.