Function Signature with variables lazarus / 62-General ---------------------------------------------------------------------- Weitentaaal · 2022-02-10 14:34 Hello, just wanted to ask if something like this is possible: 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  TMyClass = class  private     fSomStr: String;  public    property SomStr: String read fSomStr write fSomStr;    Function StringContainsID(ids :TIntegerSet; zstr: String = SomStr): boolean;end;  Thanks ! ---------------------------------------------------------------------- Zvoni · 2022-02-10 15:10 Huh? Whatever would you need that for? So, zstr is overwritten with SomStr when calling it? IIRC, you have some background in VB6/VBA? If yes, are you trying to set a default-value for an optional Parameter? ---------------------------------------------------------------------- rvk · 2022-02-10 15:19 Quote from: Weitentaaal on February 10, 2022, 03:34:32 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     Function StringContainsID(ids :TIntegerSet; zstr: String = SomStr): boolean; Optional parameter should be constants. The default parameter is determined during compilation (if the parameter gets omitted). So you can't use a function there. You can do 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 Function StringContainsID(ids :TIntegerSet; zstr: String = 'some_unique_string_which_is_never_passed'): boolean;begin  if zstr = 'some_unique_string_which_is_never_passed' then zstr := SomeStr;  // rest of your code  Of course you could also do 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 Function StringContainsID(ids :TIntegerSet; zstr: String = ''): boolean;begin  if zstr = '' then zstr := SomeStr;  // rest of your code but then you can't pass '' (empty string) to your function because it would get replaced by SomeStr. ---------------------------------------------------------------------- Zvoni · 2022-02-10 15:32 I'd rather go with an overloaded Function. 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 TMyClass = class  private    fSomStr: String;  public    property SomStr: String read fSomStr write fSomStr;    Function StringContainsID(ids :TIntegerSet; zstr: String): boolean;overload;    Function StringContainsID(ids :TIntegerSet): boolean;overload;  //In code assign SomStr to zstrend; ---------------------------------------------------------------------- rvk · 2022-02-10 15:34 Quote from: Zvoni on February 10, 2022, 04:32:11 pmI'd rather go with an overloaded Function. Yeah, that might even be better. I'm ancient ---------------------------------------------------------------------- Weitentaaal · 2022-02-10 15:55 Quote from: rvk on February 10, 2022, 04:19:05 pmQuote from: Weitentaaal on February 10, 2022, 03:34:32 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     Function StringContainsID(ids :TIntegerSet; zstr: String = SomStr): boolean; Optional parameter should be constants. The default parameter is determined during compilation (if the parameter gets omitted). So you can't use a function there. You can do 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 Function StringContainsID(ids :TIntegerSet; zstr: String = 'some_unique_string_which_is_never_passed'): boolean;begin  if zstr = 'some_unique_string_which_is_never_passed' then zstr := SomeStr;  // rest of your code  Of course you could also do 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 Function StringContainsID(ids :TIntegerSet; zstr: String = ''): boolean;begin  if zstr = '' then zstr := SomeStr;  // rest of your code but then you can't pass '' (empty string) to your function because it would get replaced by SomeStr. Yes, just wanted to do it like this but then i realized that i cant pass the '' Valuew anymore. A Unique String will work but i found it a "dirty" way to do this. Quote from: Zvoni on February 10, 2022, 04:32:11 pmI'd rather go with an overloaded Function. 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 TMyClass = class  private    fSomStr: String;  public    property SomStr: String read fSomStr write fSomStr;    Function StringContainsID(ids :TIntegerSet; zstr: String): boolean;overload;    Function StringContainsID(ids :TIntegerSet): boolean;overload;  //In code assign SomStr to zstrend;  Overriding will work too ! i was just curious if something i mentioned is possible. Thank you guys for your Time ---------------------------------------------------------------------- PascalDragon · 2022-02-11 11:56 Quote from: rvk on February 10, 2022, 04:19:05 pmOptional parameter should be constants. Small correction: they must be constants (and if a constant identifier is used it must be an untyped constant). Anything else is rejected by the compiler.