unit SLDUnit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, contexthelpunit; type { TSLDepFrm } TSLDepFrm = class(TForm) HelpBtn: TButton; ResetBtn: TButton; ComputeBtn: TButton; ReturnBtn: TButton; CostEdit: TEdit; SalvageEdit: TEdit; PeriodsEdit: TEdit; DepreciationEdit: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; procedure ComputeBtnClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure HelpBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject); function SLNDepreciation(Cost, Salvage: Extended; Life: Integer): Extended; private { private declarations } public { public declarations } end; var SLDepFrm: TSLDepFrm; implementation { TSLDepFrm } procedure TSLDepFrm.ResetBtnClick(Sender: TObject); begin CostEdit.Text := ''; SalvageEdit.Text := ''; PeriodsEdit.Text := ''; DepreciationEdit.Text := ''; end; procedure TSLDepFrm.FormShow(Sender: TObject); begin ResetBtnClick(self); end; procedure TSLDepFrm.HelpBtnClick(Sender: TObject); begin ContextHelpForm.HelpMessage((Sender as TButton).tag); end; procedure TSLDepFrm.ComputeBtnClick(Sender: TObject); VAR Cost, Depr, Salvage : Extended; Life : integer; begin // Obtain results Cost := StrToFloat(CostEdit.Text); Salvage := StrToFloat(SalvageEdit.Text); Life := StrToInt(PeriodsEdit.Text); Depr := SLNDepreciation(Cost, Salvage, Life); DepreciationEdit.Text := FloatToStr(Depr); end; function TSLDepFrm.SLNDepreciation(Cost, Salvage: Extended; Life: Integer): Extended; { Spreads depreciation linearly over life. } begin if Life < 1 then ShowMessage('ERROR in SLNDepreciation - Life < 1'); Result := (Cost - Salvage) / Life end; initialization {$I sldunit.lrs} end.