• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

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
0
Mark_FreeSoftware
Asked:
Mark_FreeSoftware
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
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
 
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now