Введение в FormsABC: различия между версиями

1074 байта добавлено ,  2 года назад
м
Метка: редактор вики-текста 2017
Метка: редактор вики-текста 2017
== Простой калькулятор ==
 
<syntaxhighlight lang="pascal">uses FormsABCSystem;
uses FormsABC;
 
const
var calculate := new Button('Calculate');
calculate.Click += () ->
try
case actions.SelectedValue.ToString()[1] of
Sum: result.Value := first.Value + second.Value;
Difference Sum: result.Value := first.Value -+ second.Value;
Multiplication Difference: result.Value := first.Value *- second.Value;
Multiplication: result.Value := first.Value * second.Value;
Division:
if second.Value <> 0 thenDivision:
resultif second.Value :=<> first.Value0 div second.Value;then
Sum: result.Value := first.Value +div second.Value;
end;
except on Exception do
end;
end.
end.</syntaxhighlight>
 
== Max-Min калькулятор ==
<syntaxhighlight lang="pascal">
uses System;
uses FormsABC;
 
const
Max = 'Max';
Min = 'Min';
Average = 'Average';
begin
mainForm.Width := 350;
mainForm.Height := 120;
mainForm.Title := 'Calculator';
mainForm.IsFixedSize := true;
var first := new IntegerField('First:', 100);
var second := new IntegerField('Second:', 100);
var result := new IntegerField('Result:', 100);
 
LineBreak();
var actions := new ComboBox();
actions.Items.Add(Max);
actions.Items.Add(Min);
actions.Items.Add(Average);
actions.SelectedIndex := 0;
var calculate := new Button('Calculate');
calculate.Click += () ->
try
case actions.SelectedValue.ToString() of
Max: result.Value := Math.Max(first.Value, second.Value);
Min: result.Value := Math.Min(first.Value, second.Value);
Average: result.Value := (first.Value + second.Value) div 2;
end;
except on Exception do
end;
end.
</syntaxhighlight>
 
== Демонтрация стека ==
66

правок