Sometimes we want an optional parameter
function doSomething(foo:Integer; bar:TObject=nil)
begin
if bar <> nil then // do something optional with bar
....
end
How do I do the equivalent with a boolean, that allows me to differentiate between the two boolean values and “no value”?
function doSomething(foo:Integer; bar:Boolean=nil) // Won't compile
begin
if bar <> nil then // do something optional with bar
end
Obviously this won’t compile as a Boolean cannot be nil.
Basically, I want a parameter with three possible states; true, false or “unspecified”.
You can do this other way, using overloading:
Then you can use it as
doSomething(1), as well asdoSomething(1, true)Using your example, it will be equivalent to: