⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scalculator.pas

📁 AlphaControls是一个Delphi标准控件的集合
💻 PAS
字号:
unit sCalculator;

{$I sDefs.inc}

interface

uses Windows, SysUtils, sCalcUnit, sConst, sUtils,
  Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Menus, sControlsManager,
  ExtCtrls, Buttons, Clipbrd, sGraphUtils, sPanel, sStyleUtil, sEditorsManager;

const
  ButtonChars = '0123456789_./*-+Q%R='#8'C';

type
{ TsCalculator }
  TsCalculator = class(TComponent)
  private
    FCalc: TsCalcForm;
    FValue: Double;
    FMemory: Double;
    FCaption: String;
    FPrecision: Byte;
    FBeepOnError: Boolean;
    FHelpContext: THelpContext;
    FOnChange: TNotifyEvent;
    FOnCalcKey: TKeyPressEvent;
    FOnDisplayChange: TNotifyEvent;
    function GetDisplay: Double;
  protected
    procedure Change; dynamic;
    procedure CalcKey(var Key: Char); dynamic;
    procedure DisplayChange; dynamic;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function Execute(sControlsManager : TsControlsManager): Boolean; overload;
    function Execute: Boolean; overload;
    property CalcDisplay: Double read GetDisplay;
    property Memory: Double read FMemory;
  published
//    property sStyleControl : TsStyleControl read GetsStyleControl write SetsStyleControl;
    property BeepOnError: Boolean read FBeepOnError write FBeepOnError default True;
    property HelpContext: THelpContext read FHelpContext write FHelpContext default 0;
    property Precision: Byte read FPrecision write FPrecision default 24;
    property Caption: string read FCaption write FCaption;
    property Value: Double read FValue write FValue;
//    property OnCalcKey: TKeyPressEvent read FOnCalcKey write FOnCalcKey;
    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    property OnDisplayChange: TNotifyEvent read FOnDisplayChange write FOnDisplayChange;
  end;

implementation

type
  TCalcPanelLayout = (clDialog, clPopup);

{ TsCalculator }

constructor TsCalculator.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FPrecision := 24;
  FBeepOnError := True;
  if FCaption = '' then FCaption := 'Calculator';
end;

destructor TsCalculator.Destroy;
begin
  FOnChange := nil;
  FOnDisplayChange := nil;
  inherited Destroy;
end;

function TsCalculator.GetDisplay: Double;
begin
  if Assigned(FCalc)
    then Result := FCalc.GetDisplay
    else Result := FValue;
end;

procedure TsCalculator.CalcKey(var Key: Char);
begin
  if Assigned(FOnCalcKey) then FOnCalcKey(Self, Key);
end;

procedure TsCalculator.DisplayChange;
begin
  if Assigned(FOnDisplayChange) then FOnDisplayChange(Self);
end;

procedure TsCalculator.Change;
begin
  if Assigned(FOnChange) then FOnChange(Self);
end;

function TsCalculator.Execute(sControlsManager : TsControlsManager): Boolean;
begin
  Result := False;
  if FCalc = nil then FCalc := TsCalcForm.Create(Self);
  if sControlsManager <> nil then begin
    FCalc.sControlsManager1.Assign(sControlsManager);
  end;

  FCalc.Caption := Self.Caption;
  FCalc.sDragBar1.Caption := Self.Caption;
  FCalc.FormStyle := fsStayOnTop;
  FCalc.FMemory := Self.FMemory;
  FCalc.UpdateMemoryLabel;
  FCalc.FPrecision := Maxi(2, Self.Precision);
  FCalc.FBeepOnError := Self.BeepOnError;
  if Self.FValue <> 0 then begin
    FCalc.DisplayValue := Self.FValue;
    FCalc.FStatus := csFirst;
    FCalc.FOperator := '=';
  end;
//  FCalc.sStyleControl1.Assign(sStyleControl);!
  FCalc.Show;
end;

function TsCalculator.Execute: Boolean;
begin
  Result := Execute(nil);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -