Skip default options in Delphi

Is there a way to skip the default options, for example, suppose my method declaration looks like this:

procedure MyProc1(var isAttr1: Boolean = FALSE;
    var isAttr2: Boolean = FALSE; var isAttr3: Boolean = FALSE);

I cannot call the function as follows:

Self.MyProc1( , , Attr3);

because I don’t want unnecessary var declarations, at the same time I want to get the last return value of the parameter (this is type var)

Thanks for your help in advance.

+3
source share
3 answers

Sorry, you cannot do this. What else can you not have a parameter varwith a default value like yours with isAttr1.

, , . .

- :

procedure Myfunc1(var isAttr1, isAttr2, isAttr3: Boolean); overload;
procedure Myfunc1(var isAttr3: Boolean); overload;

, . , , , . , :

procedure Myfunc1(var isAttr1, isAttr2, isAttr3: Boolean); overload;
procedure Myfunc1(var isAttr1: Boolean); overload;
+15

overload:

Overload .

+4

, MyFunc1 (isAttr3: boolean = FALSE); ;

.

As another poster indicates, you can do this with VAR.
It is also incorrect to call it MyFunc if it is not a function. Call it MyProc!

My decision:

function ov(p1 : boolean; p2 : boolean; p3 : boolean) : boolean; overload;
begin
  result := p1 or p2 or p3;
end;

function ov(p3 : boolean) : boolean; overload;
begin
  result :=  ov(false, false, p3);
end;

Now you can have your choice:

OV (TestBool3)

or

ov (TestBool1, TestBool2, TestBool3)

+3
source

Source: https://habr.com/ru/post/1785230/


All Articles