美文网首页
Delphi小项目——计算器

Delphi小项目——计算器

作者: 看山望海 | 来源:发表于2017-12-17 21:10 被阅读0次

一..模块划分:显示层(forml),逻辑层和算法层。

    1.显示层:

        在forml的 TForm1.FormCreate(Sender: TObject) 方法里面加入按钮的初始化,例如

Button1:= TButton.Create(self);

Button1.Parent := self;

Button1.width := self.clientwidth/5;

Button1.height := self.clientheight/10;

Button1.position.x := 10 ;

Button1.position.y := 0.8 * self.clientheight;

Button1.Text := '1';

Button1.Onclick := Form1.ButtonOnClick;

定义一个onclick事件来处理Button.Onclick事件,例如:

if (sender is TButton) then begin

if (sender = denomiBtn) then begin

str := 'x';

Edit1.Text := m_connect_begin.get_parameter(str);

end else if (sender = dotBtn) then begin

if dopBtnCanClick then begin

Edit1.Text := m_connect_begin.get_parameter(TButton(sender).Text);

end;

end else begin

Edit1.Text := m_connect_begin.get_parameter(TButton(sender).Text);

end;

end;

2. 逻辑层:

逻辑层的处理方式我是以每次按钮点击时,传入button.Text,用两个私有变量接受,一个是PreviousNum,另一个是currentNum。逻辑层主要把PreviousNum算出并保留。我的主要想法就是

前面一操作数和当前的操作数相处理。

3.算法层

主要是算法函数

相关文章

网友评论

      本文标题:Delphi小项目——计算器

      本文链接:https://www.haomeiwen.com/subject/mibuyttx.html