Forum > General

Default parametrs doesnt work

(1/3) > >>

Parthen:
I have some code with defaut parametrs:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Do you have {$MODE ObjPas} at the top of your source?

mas steindorff:
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:
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:

--- Quote from: Parthen on September 27, 2022, 10:30:06 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure ScreenWrite(Character: String; CharacterColor: Word = DefaultColor; BackgroundColor: Word = DefaultBgColor);
--- End quote ---

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure ScreenWrite(const Character: String; const CharacterColor: Word = DefaultColor; const BackgroundColor: Word = DefaultBgColor);This should fix your problem.

Navigation

[0] Message Index

[#] Next page

Go to full version