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

Содержимое удалено Содержимое добавлено
Строка 334:
|}
 
=Примеры программ=
[[Задачи на FormsABC]]
* Есть 2 числа - вывести либо минимальное, либо максимальное.
<source lang="pascal">
uses formsabc;
var
f: button;
z, x, c, h: formsabc.IntegerField;
d,d2: formsabc.RadioButton;
procedure p;
begin
if d.Checked = true then begin if z.Value > x.Value then h.Value := z.Value else h.Value := x.Value end;
if d.Checked = false then begin if z.Value < x.Value then h.Value := z.Value else h.Value := x.Value end;
end;
 
begin
z := new IntegerField('N1');
x := new IntegerField('N2');
f := new Button('Узнать ответ');
d := new RadioButton('Max');
d2 := new RadioButton('Min');
d.Checked := true;
new FlowBreak;
h := new IntegerField('Ответ:', 0);
f.Click += p;
end.
</source>
 
* Paint с совмещением модулей FormsABC и GraphABC.
<source lang="pascal">
uses FormsABC,GraphABC;
var
R_, G_, B_, A_, Si_: FormsABC.TextLabel;
R, G, B, A, Si: FormsABC.TrackBar;
 
procedure S();
begin
GraphABC.SetPenWidth(Si.Value);
GraphABC.SetPenColor(argb(A.Value, R.Value, G.Value, B.Value));
end;
 
procedure MouseDown(x, y, mb: integer);
begin
MoveTo(x, y);
end;
 
procedure MouseMove(x, y, mb: integer);
begin
if mb = 1 then LineTo(x, y);
end;
 
begin
R_ := new TextLabel('Компонент цвета R:');
R := new TrackBar(); R.Maximum := 255; R.Frequency := 50; R.ValueChanged += S; new FlowBreak;
G_ := new TextLabel('Компонент цвета G:');
G := new TrackBar(); G.Maximum := 255; G.Frequency := 50; G.ValueChanged += S; new FlowBreak;
B_ := new TextLabel('Компонент цвета B:');
B := new TrackBar(); B.Maximum := 255; B.Frequency := 50; B.ValueChanged += S; new FlowBreak;
A_ := new TextLabel('Компонент прозрачности A:');
A := new TrackBar(); A.Maximum := 255; A.Frequency := 50; A.ValueChanged += S; new FlowBreak;
Si_ := new TextLabel('Размер кисти:');
Si := new TrackBar(); Si.Maximum := 255; Si.Frequency := 50; Si.ValueChanged += S; new FlowBreak;
OnMouseDown := MouseDown;
OnMouseMove := MouseMove;
FormsABC.MainForm.Title := 'Настройки кисти';
GraphABC.SetWindowCaption('Окно для рисования');
end.
</source>
* Вычисление катета и радиуса вписанной окружности.
<source lang="pascal">
uses FormsABC;
var
f1, f2, f3, f4: FormsABC.RealField;
Get: FormsABC.Button;
 
procedure Get_();
begin
var p, a, b, c:real;
f3.Value:=Sqrt(Power(f2.Value,2)-Power(f1.Value,2));
p:=(f1.Value+f2.Value+f3.Value)/2;
a:=f1.Value; b:=f2.Value; c:=f3.Value;
f4.Value:=Sqrt(((p-a)*(p-b)*(p-c))/p);
end;
 
begin
f1 := new RealField('Катет 1:',80);
f2 := new RealField('Гипотенуза:',80);
f3 := new RealField('Катет 2:',80);
f4 := new RealField('Радиус:',80);
Get := new Button('Get');
Get.Click+=Get_;
end.</source>
* Сортировка чисел по возрастанию.
<source lang="pascal">uses FormsABC;
var
f1, f2, f3: FormsABC.RealField;
f4: FormsABC.Field;
Get: FormsABC.Button;
 
procedure Get_();
begin
var a, b, c: real;
var L: array of real;
SetLength(L,3);
a := f1.Value;b := f2.Value;c := f3.Value;
L[0] := a;L[1] := b;L[2] := c;
Sort(L);
f4.Text := '[' + FloatToStr(L[0]) + ', ' + FloatToStr(L[1]) + ', ' + FloatToStr(L[2]) + ']';
end;
 
begin
f1 := new RealField('A1:', 80);
f2 := new RealField('A2:', 80);
f3 := new RealField('A3:', 80);
f4 := new Field('Список:', 80);
Get := new Button('Get');
Get.Click += Get_;
end.</source>