From 015e6c8bd528ac326e897631afa9820d672a35b3 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 18 2019 17:58:00 +0000 Subject: lazarus: calc-line --- diff --git a/lazarus/calc-line/project1.ico b/lazarus/calc-line/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/calc-line/project1.ico differ diff --git a/lazarus/calc-line/project1.lpi b/lazarus/calc-line/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/calc-line/project1.lpi @@ -0,0 +1,79 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <i18n> + <EnableI18N LFM="False"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <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/lazarus/calc-line/project1.lpr b/lazarus/calc-line/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/calc-line/project1.lpr @@ -0,0 +1,21 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/lazarus/calc-line/project1.res b/lazarus/calc-line/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/calc-line/project1.res differ diff --git a/lazarus/calc-line/unit1.lfm b/lazarus/calc-line/unit1.lfm new file mode 100644 index 0000000..49e242c --- /dev/null +++ b/lazarus/calc-line/unit1.lfm @@ -0,0 +1,26 @@ +object Form1: TForm1 + Left = 315 + Height = 105 + Top = 260 + Width = 408 + Caption = 'Form1' + ClientHeight = 105 + ClientWidth = 408 + LCLVersion = '1.6.2.0' + object Edit1: TEdit + Left = 16 + Height = 38 + Top = 48 + Width = 368 + OnChange = Edit1Change + TabOrder = 0 + end + object Label1: TLabel + Left = 16 + Height = 21 + Top = 16 + Width = 227 + Caption = 'Enter simple expression like: 2+3=' + ParentColor = False + end +end diff --git a/lazarus/calc-line/unit1.pas b/lazarus/calc-line/unit1.pas new file mode 100644 index 0000000..c09bc8f --- /dev/null +++ b/lazarus/calc-line/unit1.pas @@ -0,0 +1,73 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; + +type + + { TForm1 } + + TForm1 = class(TForm) + Edit1: TEdit; + Label1: TLabel; + procedure Edit1Change(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +var + Form1: TForm1; + +implementation + +{$R *.lfm} + +{ TForm1 } + +procedure TForm1.Edit1Change(Sender: TObject); +var + i: integer; + a, b: single; + c, sign: char; + digits: string; + line: string; + result: string; +begin + digits := ''; + sign := ' '; + a := 0; + b := 0; + line := Edit1.Text; + + try + for i := 1 to length(line) do begin + c := line[i]; + if (c='+') or (c='-') or (c='*') or (c='/') then begin + a := StrToFloat(digits); + digits := ''; + sign := c; + end else + if c = '=' then begin + b := StrToFloat(digits); + digits := ''; + result := ''; + if sign='+' then result := FloatToStr(a + b); + if sign='-' then result := FloatToStr(a - b); + if sign='*' then result := FloatToStr(a * b); + if sign='/' then result := FloatToStr(a / b); + Edit1.Text := copy(line, 1, i) + result; + end else begin + digits := digits + c; + end; + end; + except end; +end; + +end. +