Load TStringList From File - LIne By Line lazarus / 61-Beginners ---------------------------------------------------------------------- nugax · 2022-02-24 03:09 I have a file with IP address on each line. I am simply trying to load and then evaluate a IP address stored in a TStringList with my own IP. It works fine if I only have 1 ip but if i add blank lines or any other lines, it doesnt find my ip. It does find the correct number of lines, but doesnt compare correctly. what the heck am I doing wrong? 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  :P//Load TStringArray List Of Allowed IPsprocedure LoadDenyList();var  F: textfile;  sFileName: string;  sData: string;  chRead: char;  sReturnString: string; begin  sFilename := programinfo.cbbsInfo.sFirewallDenyDataFile;  TBotKillerIPDenyList := TStringList.Create;  TBotKillerIPDenyList.Delimiter := #13;  TBotKillerIPDenyList.StrictDelimiter:=true;  TBotKillerIPDenyList.LoadFromFile(sFilename);    {  sFilename := programinfo.cbbsInfo.sFirewallDenyDataFile;  AssignFile(F, sFilename);  Reset(F);   TBotKillerIPDenyList := TStringList.Create;  if (FileExists(sFilename)) then  begin    while not EOF(F) do    begin      sData := '';      sReturnString := '';      repeat        Read(F, chRead);        AppendStr(sReturnString, chRead);      until (chRead = #13) or (chRead = #10);      write('len: ' + length(sReturnString).tostring);      Write('sData: ' + sReturnString);      if ((sReturnString <> '')  or (length(sReturnString) > 2)) Then      begin        delete(sReturnString, length(sReturnString), 1);        TBotKillerIPDenyList.Add(sReturnString);        Write('cnt: ' + TBotKillerIPDenyList.Count.ToString);      end;     end;    Write('here3');  end;  Write('here4');  }end; //Check Connected IP Against Loaded TStringArray Listprocedure Firewall_CheckIP();var  iCnt: integer;  boolFoundDenied: boolean;   text : string; begin  //Check Each Record In The Firewall Deny List  boolFoundDenied := False;  iCnt := 0;  repeat    boolFoundDenied := False;     text := TBotKillerIPDenyList.Strings[iCnt];     writeln('cnt:' +  TBotKillerIPDenyList.Count.tostring);    writeln('Text: ' + text);     if (cContext.Binding.PeerIP = TBotKillerIPDenyList.Strings[iCnt]) then      begin        boolFoundDenied := True;      end;     iCnt := iCnt + 1;  until (iCnt = TBotKillerIPDenyList.Count);    if (boolFoundDenied = True) then  begin    Write('found denied');    logging.WriteBotKillerLog('Checking banned IP list...');    logging.WriteBotKillerLog('IP: ' + cContext.Binding.PeerIP + ' found in deny list. Deny access to the CyberBBS Telnet Server.');    logging.WriteBotKillerLog('Disconnecting client..');    cyberio.PipeWriteString('IP ' + cContext.Binding.PeerIP + ' blacklisted/connection closed. IP Logged');    cContext.Connection.Disconnect;  end  else  begin   end; end; ---------------------------------------------------------------------- bytebites · 2022-02-24 07:23 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 Firewall_CheckIP();begin  TBotKillerIPDenyList.indexof(cContext.Binding.PeerIP)>=0  then  begin    Write('found denied');    logging.WriteBotKillerLog('Checking banned IP list...');    logging.WriteBotKillerLog('IP: ' + cContext.Binding.PeerIP + ' found in deny list. Deny access to the CyberBBS Telnet Server.');    logging.WriteBotKillerLog('Disconnecting client..');    cyberio.PipeWriteString('IP ' + cContext.Binding.PeerIP + ' blacklisted/connection closed. IP Logged');    cContext.Connection.Disconnect;  end end; ---------------------------------------------------------------------- nugax · 2022-02-24 10:33 Awesome! What great code. Question though, this is a great simple solution but why wasn’t my longer code not evaluating correctly? I’d like to understand why. It was loading the file, but not correctly comparing the two strings if the file contained more than one entry. I wouldn’t use my code obviously, but would like to know what I did wrong for future endeavors. Thanks! ---------------------------------------------------------------------- bytebites · 2022-02-24 10:58 Remove line 62? ---------------------------------------------------------------------- nugax · 2022-02-24 13:09 Well the next line or two down it checks for a comparison the sets that Boolean to true. The issue is the comparison doesn’t even work right if more than one line is entered into the file… weird ---------------------------------------------------------------------- bytebites · 2022-02-24 14:24 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 var  iCnt: integer;  boolFoundDenied: boolean;  text : string;begin  boolFoundDenied := False;  for iCnt:=0 to TBotKillerIPDenyList.Count-1 do begin    text := TBotKillerIPDenyList[iCnt];    writeln('cnt:' +  icnt.tostring);    writeln('Text: ' + text);    if cContext.Binding.PeerIP = text then      begin        boolFoundDenied := True;        break;      end;  end; ---------------------------------------------------------------------- wildfire · 2022-02-25 12:29 Quote from: nugax on February 24, 2022, 02:09:55 pmWell the next line or two down it checks for a comparison the sets that Boolean to true. The issue is the comparison doesn’t even work right if more than one line is entered into the file… weird Follow the flow of your program, it loops back and the boolean is reset to false, basically unless your final comparison in the repeat until loop is true your boolFoundDenied will always be false when the loop exits.