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

📄 calcunit.pas

📁 好好的哦,包含各种科学函数,具有多种功能的计算器,而且还有源代码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    i:=0;
    while i<=(theList.Count-1) do
    begin
        If (theList.Strings[i] = '*')or(theList.Strings[i] = '/') then
        begin
            If theList.Strings[i] = '*' then
                dTemp:=StrToFloat(theList.Strings[i-1])*StrToFloat(theList.Strings[i+1]);
            If theList.Strings[i] = '/' then
                dTemp:=StrToFloat(theList.Strings[i-1])/StrToFloat(theList.Strings[i+1]);
            theList.Delete(i-1);
            theList.Delete(i);
            theList.Strings[i-1]:=FloatToStr(dTemp);
        end else
            i:=i+1;
    end;
//******************************************************************************
    i:=0;
    while i<=(theList.Count-1) do
    begin
        If (theList.Strings[i] = '+')or(theList.Strings[i] = '-') then
        begin
            If theList.Strings[i] = '+' then
                dTemp:=StrToFloat(theList.Strings[i-1])+StrToFloat(theList.Strings[i+1]);
            If theList.Strings[i] = '-' then
                dTemp:=StrToFloat(theList.Strings[i-1])-StrToFloat(theList.Strings[i+1]);
            theList.Delete(i-1);
            theList.Delete(i);
            theList.Strings[i-1]:=FloatToStr(dTemp);
        end else
            i:=i+1;
    end;
    If theList.Count<>1 then Memo1.Lines.Add('您的表达式有问题或系统不支持这种表达式!∴');
    Result:=StrToFloat(theList.Strings[0]);
//******************************************************************************
end;

//****************************************************************************************
// 以下是窗口事件
//****************************************************************************************

procedure TCalcForm.Memo1KeyPress(Sender: TObject; var Key: Char);
var dTemp: Extended;
begin
    try
        If Key = '=' then
        begin
            strCancel:=MemoLinesToStringList(theAllList,Memo1.SelStart);
            If theAllList.Count<>0 then
            begin
                dTemp:=CalcFormList(theAllList);
                strResult:=FloatToStr(dTemp);
            end;
        end; 
    except
        Memo1.Lines.Add('表达式错误!∴');
    end;
end;

procedure TCalcForm.FormShow(Sender: TObject);
var wRegistry: TRegistry;
    bReg: Boolean;
begin
    theAllList:=TStringList.Create;
    strCancel:='';
//****************************************************************************
    wRegistry:=TRegistry.Create;  //KeyExists
    wRegistry.RootKey:=HKEY_LOCAL_MACHINE;
    bReg:=wRegistry.KeyExists('Software\WgqAdvanCalc');
    If not bReg then
    begin
        If not wRegistry.CreateKey('Software\WgqAdvanCalc') then
        begin
            Application.MessageBox('未知的原因,创建注册信息失败!','注册软件',MB_ICONWARNING+MB_OK+MB_TOPMOST);
            Exit;
        end;
    end else
    begin
        try
        wRegistry.OpenKey('Software\WgqAdvanCalc',False);
        Memo1.Font.Name:=wRegistry.ReadString('FontName');
        Memo1.Font.Size:=wRegistry.ReadInteger('FontSize');
        Memo1.Font.Color:=wRegistry.ReadInteger('FontColor');
        Memo1.Font.Style:=StringToFontStyle(wRegistry.ReadString('FontStyle'));
        Memo1.Color:=wRegistry.ReadInteger('BackColor');
        Panel2.Color:=wRegistry.ReadInteger('Panel2Color');
        wRegistry.CloseKey;
        except
        end;
    end;
    wRegistry.Free;
    try
        RevertSize;
    except
    end;
end;

procedure TCalcForm.FormClose(Sender: TObject; var Action: TCloseAction);
var wRegistry: TRegistry;
    bReg: Boolean;
begin
    theAllList.Free;
//******************************************************************************
    wRegistry:=TRegistry.Create;  //KeyExists
    wRegistry.RootKey:=HKEY_LOCAL_MACHINE;
    bReg:=wRegistry.KeyExists('Software\WgqAdvanCalc');
    If bReg then
    begin
        wRegistry.OpenKey('Software\WgqAdvanCalc',False);
        wRegistry.WriteString('FontName',Memo1.Font.Name);
        wRegistry.WriteInteger('FontSize',Memo1.Font.Size);
        wRegistry.WriteInteger('FontColor',Memo1.Font.Color);
        wRegistry.WriteString('FontStyle',FontStyleToString(Memo1.Font.Style));
        wRegistry.WriteInteger('BackColor',Memo1.Color);
        wRegistry.WriteInteger('Panel2Color',Panel2.Color);
        wRegistry.CloseKey;
    end;
    wRegistry.Free;
    showTaskbar;
    If Self.BorderStyle <> bsNone then
        WritePosition;
end;

procedure TCalcForm.Memo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var theList: TStringList;
begin
    If Key = 13 then
    begin
        theList:=TStringList.Create;
        MemoLinesToStringList(theList,Memo1.SelStart,True);
        If UpperCase(Trim(theList.Text))='SETFONT' then
        begin
            FontDialog1.Font:=Memo1.Font;
            FontDialog1.Execute;
            Memo1.Font:=FontDialog1.Font;
        end;
        If (UpperCase(Trim(theList.Text))='BACKCOLOR')or
            (UpperCase(Trim(theList.Text))='BKCOLOR') then
        begin
            ColorDialog1.Color:=Memo1.Color;
            ColorDialog1.Execute;
            Memo1.Color:=ColorDialog1.Color;
            Panel2.Color:=ColorDialog1.Color;
        end;
        theList.Free;
    end;
end;

procedure TCalcForm.Memo1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var theList: TStringList;
    yearstr,monthstr,daystr,dowstr: Word;
    iTemp: Integer;
begin
    If Memo1.Lines.Text = '' then Exit;
    If (Memo1.Lines.Text[Memo1.SelStart]='=')and(Key=187) then
    begin
        Memo1.SelText:=strResult;
        If Trim(strCancel)<>'' then
        begin
            Memo1.Lines.Add('“'+Trim(strCancel)+'”'+'是个非法的东东,被忽略!∴');
            strCancel:='';
        end;
        Memo1.Lines.Add('');
        strResult:='';
    end;
    If Key = 13 then
    begin
        theList:=TStringList.Create;
        MemoLinesToStringList(theList,Memo1.SelStart,True);
        If UpperCase(Trim(theList.Text))='CLEAR' then
        begin
            Memo1.Clear;
        end
        else If (UpperCase(Trim(theList.Text))='EXIT')or
            (UpperCase(Trim(theList.Text))='QUIT')or
            (UpperCase(Trim(theList.Text))='CLOSE') then
        begin
            Close;
        end
        else If (UpperCase(Trim(theList.Text))='FULLSCREEN')or
            (UpperCase(Trim(theList.Text))='FULLSCR') then
        begin
            If Self.BorderStyle <> bsNone then
            begin
                WritePosition;
                iTemp:=Memo1.SelStart;
                Self.BorderStyle:=bsNone;
                Self.WindowState:=wsMaximized;
                hideTaskbar;
                Memo1.SetFocus;
                Memo1.SelStart:=iTemp;
            end;
        end
        else If (UpperCase(Trim(theList.Text))='REVERT')or
            (UpperCase(Trim(theList.Text))='REV') then
        begin
            showTaskbar;
            iTemp:=Memo1.SelStart;
            Self.BorderStyle:=bsSizeable;
            Self.WindowState:=wsNormal;
            Memo1.SetFocus;
            Memo1.SelStart:=iTemp;
            RevertSize;
        end
        else If (UpperCase(Trim(theList.Text))='HELP') then
        begin
            Memo1.Lines.Add('**************************************');
            Memo1.Lines.Add('1、用法:');
            Memo1.Lines.Add('输入数学表达式后,输入“=”,系统自动计算结果;');
            Memo1.Lines.Add('一个表达式可以一行输入,也可以多行输入;');
            Memo1.Lines.Add('表达式可以是加(+)、减(-)、乘(*)、除(/)、括号(()),以及系统支持的数学函数的任意组合。');
            Memo1.Lines.Add('输入系统命令后,按回车键即可执行系统命令。系统不区分大小写。');
            Memo1.Lines.Add('2、系统命令:');
            Memo1.Lines.Add('Clear:清除屏幕。');
            Memo1.Lines.Add('Quit/Exit/Close:退出系统。');
            Memo1.Lines.Add('Help:帮助系统。');
            Memo1.Lines.Add('FullScreen/FullScr:把窗口最大化。');
            Memo1.Lines.Add('Revert/Rev:把窗口还原为原来的大小。');
            Memo1.Lines.Add('DateTime/Now:返回当前日期时间,以及星期几。');
            Memo1.Lines.Add('About:关于本软件,有作者信息及电话。');
            Memo1.Lines.Add('SetFont:设置窗口的字体,系统自动记忆设置后的字体。');
            Memo1.Lines.Add('BackColor/BkColor:设置窗口的背景颜色,系统自动记忆设置后的颜色。');
            Memo1.Lines.Add('3、系统支持的数学函数:');
            Memo1.Lines.Add('PI ! ^ % SQR SQRT INT/TRUNC ROUND ABS FRAC SIN COS TAN ARCSIN ARCCOS ARCTAN LN LOG2 LOG10');
            Memo1.Lines.Add('PI:圆周率。');
            Memo1.Lines.Add('Exp!:计算Exp(表达式)的介乘。');
            Memo1.Lines.Add('Exp1^Exp2:计算Exp1的Exp2次方。');
            Memo1.Lines.Add('Exp1%Exp2:计算Exp1除以Exp2后的余数。');
            Memo1.Lines.Add('Sqr(Exp):计算Exp的平方。');
            Memo1.Lines.Add('Sqrt(Exp):计算Exp的平方根。');
            Memo1.Lines.Add('Int(Exp)/Trunc(Exp):把Exp截断取整。');
            Memo1.Lines.Add('Round(Exp):把Exp四舍五入。');
            Memo1.Lines.Add('Abs(Exp):取Exp的绝对值。');
            Memo1.Lines.Add('Frac(Exp):取Exp的小数部分。');
            Memo1.Lines.Add('Sin(Exp):求Exp的正玄。');
            Memo1.Lines.Add('Cos(Exp):求Exp的余玄。');
            Memo1.Lines.Add('Tan(Exp):求Exp的正切。');
            Memo1.Lines.Add('ArcSin(Exp):求Exp的反正玄。');
            Memo1.Lines.Add('ArcCos(Exp):求Exp的反余玄。');
            Memo1.Lines.Add('ArcTan(Exp):求Exp的反正切。');
            Memo1.Lines.Add('Ln(Exp):求Exp的自然对数。');
            Memo1.Lines.Add('Log2(Exp):求Exp的以2为低的对数。');
            Memo1.Lines.Add('Log10(Exp):求Exp的以10为低的对数。');
            Memo1.Lines.Add('**************************************∴');
        end
        else If (UpperCase(Trim(theList.Text))='ABOUT') then
        begin
            Memo1.Lines.Add('高级计算器 WgqSoft_AdvCalc 1.0');
            Memo1.Lines.Add('作者:王功勤');
            Memo1.Lines.Add('电话:13675480121');
            Memo1.Lines.Add('完成时间:2003年8月21日 ∴');
        end
        else If (UpperCase(Trim(theList.Text))='DATETIME')or
            (UpperCase(Trim(theList.Text))='NOW') then
        begin
            DecodeDatefully(now(),yearstr,monthstr,daystr,dowstr);
            Memo1.Lines.Add('当前日期时间:');
            Memo1.Lines.Add(IntToStr(yearstr)+'年'+IntToStr(monthstr)+'月'+IntToStr(dayStr)+'日 '
                +DowToWeekStr(dowstr)+' '+TimeToStr(Now)+' ∴');
        end
        else begin
            If (not IsInOperatorsArray(Trim(theList.Text)))and(not IsFloat(Trim(theList.Text))) then
            begin
                If (Trim(theList.Text)<>'')and(Uppercase(Trim(theList.Text))<>'SETFONT')
                    and(Uppercase(Trim(theList.Text))<>'BKCOLOR')AND(Uppercase(Trim(theList.Text))<>'BACKCOLOR') then
                begin
                    Memo1.Lines.Add('“'+Trim(theList.Text)+'”'+'不是一个合法的操作命令!∴');
                end;
            end;
        end;
        theList.Free;
    end;
end;

procedure TCalcForm.Timer1Timer(Sender: TObject);
begin
    Memo1.Cursor:=crNone;
end;

procedure TCalcForm.Memo1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if timer1.Enabled then //判断定时器是否打开
begin //如打开,则重新开始计时
  timer1.enabled:=false;
  timer1.enabled:=true;
end;
Memo1.cursor:=crIBeam;
end;

end.

⌨️ 快捷键说明

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