Passing strings lazarus / 16-Databases ---------------------------------------------------------------------- nugax · 2018-01-19 21:08 I have a function to write a logfile setup as such: 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 write_bot_killer_log(var sDataToWrite : String): boolean; When I call the function 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 logging.write_bot_killer_log('Invalid BotKiller key pressed'); It is wanting a variable. Is there a way I can pass just text instead? it is set as string, so I am not sure what I'm missing! ---------------------------------------------------------------------- nugax · 2018-01-19 21:09 Sorry I posted this in wrong place -> tried to move but i couldnt! ---------------------------------------------------------------------- howardpc · 2018-01-19 21:11 Just remove the "var" from your function's parameter specification. ---------------------------------------------------------------------- taazz · 2018-01-19 21:13 Defining the parameter sDataToWrite as var instructs the compiler that you intent to change the data passed in that parameter and you want that changes to persist when you exit the function (aka return the changes to the caller).  if you have intention to change the data passed then define it as const or if you do not have any intention to return the changes then simple remove the var definition. ---------------------------------------------------------------------- mangakissa · 2018-01-20 08:32 use procedure instead of 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     procedure write_bot_killer_log(const sDataToWrite : String); ---------------------------------------------------------------------- Thaddy · 2018-01-20 09:55 No the function is a boolean: can be used to test write success or fail. Much better than procedure, actually... ---------------------------------------------------------------------- mangakissa · 2018-01-20 13:44 Why? If it will giving a result back, it's usefull. Otherwise you use memory without purposes. In his case it write something to a log and nothing more. ---------------------------------------------------------------------- Thaddy · 2018-01-20 13:47 Quote from: mangakissa on January 20, 2018, 02:44:57 pmWhy? If it will giving a result back, it's usefull. Otherwise you use memory without purposes. In his case it write something to a log and nothing more. All the more reason to check if you actually succeeded. Otherwise your log becomes unusable...  It is simply good practice. ---------------------------------------------------------------------- mangakissa · 2018-01-20 13:59 Check for what. Hello, I wrote somehing in a log. I gonna tell you that with true. 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 if not log('hello') then  showmessage('log isn't working') function log(const aValue : string) : boolean;begin  if lines.add(aValue) = -1 then     result := true  else   result := false; end; This is inefficient. ---------------------------------------------------------------------- mangakissa · 2018-01-20 14:00 Quote from: mangakissa on January 20, 2018, 02:59:41 pmCheck for what. Hello, I wrote somehing in a log. I gonna tell you that with true. 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 if not log('hello') then  showmessage('log is not  working'); function log(const aValue : string) : boolean;begin  if lines.add(aValue) = -1 then     result := true  else   result := false; end; This is inefficient. ---------------------------------------------------------------------- nugax · 2018-01-20 16:08 Quote from: Thaddy on January 20, 2018, 10:55:29 amNo the function is a boolean: can be used to test write success or fail. Much better than procedure, actually... I wanted to know if it wrote succesfully -> if it didnt, maybe the file has issues, etc. Thats why its a func ---------------------------------------------------------------------- nugax · 2018-01-20 16:15 I used rwrite(log); for opening the file -> I assume this creates a new file. What should I be looking at for appending, etc.