Procedure optional param

hello experts,


as the title states,
i would like to have a procedure with an optional parameter,

is this possible, and so yes, how?


example:
procedure WriteXY(str:string;X:byte;Y:byte; ?Optional? Color as byte);

so that Color is not giving an error when it isn filled

mark
LVL 13
Mark_FreeSoftwareAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
I don't believe you can do that in Pascal.

It has been a long timew since I wrote any Pascal.  Can you have 2 procedures with the same name but different parameters

procedure WriteXY(str:string;X:byte;Y:byte;  Color as byte);
procedure WriteXY(str:string;X:byte;Y:byte);

mlmcc
0
For-SoftCommented:
It is not possible.

Declaration of another procedure with the same name will cause a compiler error.
Optional parameters are not supported.

It is possible to set a global variable as the current color setting. And to change it before and/or after calling WriteXY procedure.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark_FreeSoftwareAuthor Commented:

too bad.....


then i'm going for a split between you two, because you both added to the final aswer

are you ok with that?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

For-SoftCommented:
I'm OK.
0
mlmccCommented:
Fine by me.

Thanks for-Soft, I couldn't remember.  I thought it was not allowed but wasn't sure.

mlmcc
0
mlmccCommented:
Glad i could help

mlmcc
0
aikimarkCommented:
Although this thread is closed, I would like to add a bit of a correction.  It is possible to assign a (default) value to a parameter, rendering it optional.  You can also do some trickery with function overrides.

Reference:
http://delphi.about.com/od/beginners/l/aa050900a.htm

======================
Thanks to Netminder for allowing me to add this post-PAQ comment.
0
Mark_FreeSoftwareAuthor Commented:

cool!

but since that page is for delphi,
does that work in pascal too?
0
aikimarkCommented:
according to the content at the link, this applies to Object Pascal, and started with Delphi 4.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.