Default parametrs doesnt work lazarus / 21-General ---------------------------------------------------------------------- Parthen · 2022-09-27 20:30 I have some code with defaut parametrs: 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 ScreenWrite(Character: String; CharacterColor: Word = DefaultColor; BackgroundColor: Word = DefaultBgColor);begin    TextColor(CharacterColor);    TextBackground(BackgroundColor);    Write(Character);    Restore;end; No matter which valut I put on -- FPC give me this error: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Free Pascal Compiler version 3.2.2 [2022/08/31] for x86_64Copyright (c) 1993-2021 by Florian Klaempfl and othersTarget OS: Linux for x86-64Compiling game.pas[b]game.pas(71,63) Fatal: Syntax error, ")" expected but "=" found[/b]Fatal: Compilation abortedError: /usr/bin/ppcx64 returned an error exitcode Also, this code https://www.freepascal.org/docs- html/current/ref/refsu64.html#x180-20400014.4.1 also doesnt work and give me this error: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Free Pascal Compiler version 3.2.2 [2022/08/31] for x86_64Copyright (c) 1993-2021 by Florian Klaempfl and othersTarget OS: Linux for x86-64Compiling test1.pas[b]test1.pas(6,34) Fatal: Syntax error, ")" expected but "=" found[/b]Fatal: Compilation abortedError: /usr/bin/ppcx64 returned an error exitcode  Is something wrong in my code or its FPC problem? ---------------------------------------------------------------------- jamie · 2022-09-27 20:55 Do you have {$MODE ObjPas} at the top of your source? ---------------------------------------------------------------------- mas steindorff · 2022-09-27 20:58 I believe what you have defined here are "optional" parameters, not just default. since the compiler cant know if you are passing the 2nd or 3rd parameter when you only define 2 parameters for a 3 parameter procedure, you get an error.  An optional parameter must only be the last parameter unless something has changed recently. MAS ---------------------------------------------------------------------- jamie · 2022-09-27 21:17 I don't think so, as long as the remaining parms are defaults it should compile. I have done this myself; it should work. its only when you attempt to mix a non-default type in the middle etc. But I think it depends on what mode the compiler is in because this wasn't supported in the old days. ---------------------------------------------------------------------- KodeZwerg · 2022-09-27 22:25 Quote from: Parthen on September 27, 2022, 10:30:06 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 procedure ScreenWrite(Character: String; CharacterColor: Word = DefaultColor; BackgroundColor: Word = DefaultBgColor);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 ScreenWrite(const Character: String; const CharacterColor: Word = DefaultColor; const BackgroundColor: Word = DefaultBgColor);This should fix your problem. ---------------------------------------------------------------------- Zoran · 2022-09-27 22:35 Mas Steindorf, you are wrong; when two parameters are passed, the compiler will treat the second parameter as the second parameter and the third parameter will get the default parameter. As Jamie says, this should compile, but only in objfpc or delphi modes. Quote from the documentation: QuoteThe compiler must be in OBJFPC or DELPHI mode to accept default values. Quote from: KodeZwerg on September 28, 2022, 12:25:33 amQuote from: Parthen on September 27, 2022, 10:30:06 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 procedure ScreenWrite(Character: String; CharacterColor: Word = DefaultColor; BackgroundColor: Word = DefaultBgColor);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 ScreenWrite(const Character: String; const CharacterColor: Word = DefaultColor; const BackgroundColor: Word = DefaultBgColor);This should fix your problem. What? Const should not make a difference with this. ---------------------------------------------------------------------- Kays · 2022-09-27 23:31 MeanwhileCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$modeSwitch defaultParameters+}is sufficient if you prefer a different mode other than {$mode objFPC}/{$mode Delphi}. ---------------------------------------------------------------------- Parthen · 2022-09-28 05:44 Quote from: jamie on September 27, 2022, 10:55:26 pmDo you have {$MODE ObjPas} at the top of your source? No, I dont know anything about it. Google also doesnt have info about it, may you give me some documentation for this? ---------------------------------------------------------------------- Parthen · 2022-09-28 05:47 Quote from: Kays on September 28, 2022, 01:31:26 amMeanwhileCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$modeSwitch defaultParameters+}is sufficient if you prefer a different mode other than {$mode objFPC}/{$mode Delphi}. Okay, this helps me. Thanks! ---------------------------------------------------------------------- PascalDragon · 2022-09-28 07:12 Quote from: Parthen on September 28, 2022, 07:44:38 amQuote from: jamie on September 27, 2022, 10:55:26 pmDo you have {$MODE ObjPas} at the top of your source? No, I dont know anything about it. Google also doesnt have info about it, may you give me some documentation for this? The $Mode directive is an important part of FPC ($ModeSwitch is as well). You can read more about the modes here. ---------------------------------------------------------------------- KodeZwerg · 2022-09-28 10:02 Quote from: Zoran on September 28, 2022, 12:35:12 amQuote from: KodeZwerg on September 28, 2022, 12:25:33 amThis should fix your problem.What? Const should not make a difference with this.I am sorry, i had more in my mind, to what does the params write when there is no input. Since I am new to Lazarus/FreePascal, please forgive my inexperience. ---------------------------------------------------------------------- mas steindorff · 2022-09-28 17:16 the Wiki is a good place look for these "how to" and "what is", things you have a name for. see if ... https://wiki.freepascal.org/Default_parameter/pl explains this to your satisfaction ans se can go from there. [edit..] was checking my post and saw the text was not  English so I clicked to change.  the English and some of the others have completely different code snippets!  the code in each is good. Therefore, if available, look into the different language tabs for more info.