Free Pascal
LAZARUS

Free Pascal / Lazarus: Equivalent statements

Instead of setting some properties, you can use equivalent methods, such as Visible and Show/Hide.
Using one format instead of the other is up to you, sometimes one way is clearer.

 PropertiesMethods Examples 
Active Open
Close
DataSet1.Active := True;
DataSet1.Active := False;
DataSet1.Open;
DataSet1.Close;
NumbersOnly SetNumbersOnly Edit1.NumbersOnly := True;
Edit1.NumbersOnly := False;
Edit1.SetNumbersOnly(True);
Edit1.SetNumbersOnly(False);
Visible Show
Hide
Panel1.Visible := True;
Panel1.Visible := False;
Panel1.Show;
Panel1.Hide;


Sometimes IF statements can be replaced with much more compact code using properties, such as in:

if Panel1.Visible then begin
  Panel2.Show;
  Label2.Show;
end
else begin

  Panel2.Show;
  Label2.Show;
end;

is equivalent to:

Panel2.Visible := Panel1.Visible;
Label2.Visible := Panel1.Visible;

Free Pascal allows the use of strings as case labels, for making a "case" equivalent to a series of complicated "if...then...else" statements. Consider the following compact code and what would be needed to write it with if...then...else:

case LowerCase(Edit1.Text) of
  'abc', 'def': Label1.Caption := 'a...f';
  'ghi'       : Label1.Caption := 'g...i';
  'jkl', 'mno': Label1.Caption := 'j...o';
else
  Label1.Caption := 'other';
end;