FormsABC unit in PascalABC.NET

From Wikibooks, open books for an open world
Jump to navigation Jump to search

FormsABC - is a PascalABC.NET unit intended for simple GUI application's creation.

Controls

[edit | edit source]
  1. Button - a button
  2. CheckBox - a checkbox
  3. RadioButton - a radio button
  4. IntegerField - a single line text box intended to keep integer values
  5. RealField - a single line text box intended to keep real values
  6. Field - a single line text box
  7. TextBox - a multi line text box
  8. TrackBar - a track bar
  9. TextLabel - a label
  10. ListBox - a list box
  11. ComboBox - a combo box
  12. MainMenu - a main menu

Button class

[edit | edit source]

Constructor

[edit | edit source]
Type Description
string A text on the button

Properties

[edit | edit source]
Name Type Description
Text string A text on the button
Width integer A width of the button

Events

[edit | edit source]
Name Type Description
Click procedure A procedure called on the button click

Examples

[edit | edit source]

Create a new button with Click me! text on it:

new Button('Click me!');

CheckBox class

[edit | edit source]

Constructor

[edit | edit source]
Type Description
string A text on the checkbox

Properties

[edit | edit source]
Name Type Description
Checked boolean Whether the checkbox is checked

Examples

[edit | edit source]

Create a new checkbox with Check me! text on it:

new CheckBox('Check me!');

Examples

[edit | edit source]
uses System;
uses FormsABC;

const
  Sum = '+';
  Difference = '-';
  Multiplication = '*';
  Division = '/';
  
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(Sum);
  actions.Items.Add(Difference);
  actions.Items.Add(Multiplication);
  actions.Items.Add(Division);
  actions.SelectedIndex := 0;
  
  var calculate := new Button('Calculate');
  calculate.Click += () ->
    try
      case actions.SelectedValue.ToString()[1] of
        Sum: result.Value := first.Value + second.Value;
        Difference: result.Value := first.Value - second.Value;
        Multiplication: result.Value := first.Value * second.Value;
        Division:
          if second.Value <> 0 then
            result.Value := first.Value div second.Value;
      end;
    except on Exception do
    end;
end.