How to make a procedure parameter optional? lazarus / 61-Beginners ---------------------------------------------------------------------- bulrush · 2016-06-15 18:06 I did some Googling and searched the Lazarus forums but I can't seem to find out how to make a parmater optional. If I have this procedure: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure foo(a:integer; s:string);  I'd want s to be optional. Does someone know how to do this? Thank you. ---------------------------------------------------------------------- skalogryz · 2016-06-15 18:09 There's no such thing as an optional parameter in Pascal. There's however a default value for a parameter, that makes it unnecessary to specify the parameter on the routine call (by its name). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode delphi}procedure Say(const verb: string; const name: string = 'World');begin  writeln(verb,' ',name);end; begin  Say('Hello');end. ---------------------------------------------------------------------- rvk · 2016-06-15 18:17 Quote from: skalogryz on June 15, 2016, 08:09:19 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode delphi}or {$mode objfpc} ---------------------------------------------------------------------- howardpc · 2016-06-15 21:13 For the specific example procedure you asked about, you can simulate having a single procedure with an optional parameter by writing two overloaded procedures such as this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$H+} {$R *.res} Procedure foo(a:integer; s:string); overload;begin  WriteLn('foo: a=',a,' s="',s,'"');end; procedure foo(a:integer); overload;begin  WriteLn('foo: a=',a);end; begin  foo(2);  foo(2,'with optional parameter');  {$IfDef Windows}  ReadLn;  {$EndIf}end. ---------------------------------------------------------------------- howardpc · 2016-06-15 21:19 A further variation if you make use of a default parameter could be something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure fooOptional(a: integer; s: string='');begin  if (s <> '') then    WriteLn('fooOptional: a=',a,' s="',s,'"')  else WriteLn('fooOptional: a=',a);end;