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

42 байта добавлено ,  1 год назад
Метка: редактор вики-текста 2017
Метка: редактор вики-текста 2017
</syntaxhighlight>
 
==Перемещение фигуры кнопками==
==Простой таймер==
<syntaxhighlight lang="pascal">
uses Timers, GraphABC, ABCObjects, ABCButtons;
 
const
HButtonSize = 3025;
BoxSize = 100;
MoveValue = 2;
 
var
Start, Stop: ButtonABC;
Value: RectangleABC;
T: integer;
Timer1: Timer;
 
procedure AddTime();
begin
Startvar left := new ButtonABC(0, Y0, WButtonSize, HButtonSize, 'StartL', clMoneyGreenclRed);
Inc(T);
var right := new ButtonABC(ButtonSize, 0, ButtonSize, ButtonSize, 'R', clYellow);
Value.Text := IntToStr(T);
var up := new ButtonABC(ButtonSize * 2, 0, ButtonSize, ButtonSize, 'U', clGreen);
end;
var down := new ButtonABC(ButtonSize * 3, 0, ButtonSize, ButtonSize, 'D', clBlue);
 
procedure StartTimer() := Timer1.Start();
 
procedure StopTimer() := Timer1.Stop();
 
begin
SetWindowIsFixedSize(true);
SetWindowSize(300, 100);
SetWindowCaption('Timer');
CenterWindow();
var W := Window.Width div 2;
var Y := Window.Height - H;
Timer1 := new Timer(1000, AddTime);
var rectangle := new RectangleABC(Window().Width div 2, Window().Height div 2, BoxSize, BoxSize, clGray);
Start := new ButtonABC(0, Y, W, H, 'Start', clMoneyGreen);
Start.OnClick := StartTimer;
Stop := new ButtonABC(W, Y, W, H, 'Stop', clMoneyGreen);
Stop.OnClick := StopTimer;
left.OnClick := procedure() -> rectangle.MoveOn(-MoveValue, 0);
Value := new RectangleABC(0, 0, Window.Width, Y, clWhite);
right.OnClick := procedure() -> rectangle.MoveOn(MoveValue, 0);
Value.Text := '0';
up.OnClick := procedure() -> rectangle.MoveOn(0, -MoveValue);
down.OnClick := procedure() -> rectangle.MoveOn(0, MoveValue);
end.
</syntaxhighlight>
66

правок