Variable Declaration with Default Value in Procedures

Asked

Viewed 1,438 times

2

You could declare a variable with a default value in Procedures?

procedure TfrmManutencao01.FormShow(Sender: TObject);
var
  lPriAber : Boolean = True;
begin
.
.
.
end;

I know that as it is above Delphi does not accept.

  • And what the need to be in the body of the procedure?

  • 1

    I just wanted to know why a friend asked me and I’m in a place without Delphi installed.

1 answer

5


Directly answering the question: No, Cannot initialize local variables.

What you can do is declare the variable before the section implementation

var
  FormX    : TFormX;
  lPriAber : Boolean = True;

That way you can use it in the procedure.

If by chance it is not changing its value, one can locally declare it as constant.

procedure TfrmManutencao01.FormShow(Sender: TObject);
const
  lPriAber : Boolean = True;
begin
..
end;

I still can’t understand the need.

  • 1

    It was just to clear a doubt... Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.