Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:29:56+00:00 2026-05-27T04:29:56+00:00

Ok guys, I’ve been trying to find out every possible mistake i’m making but

  • 0

Ok guys, I’ve been trying to find out every possible mistake i’m making but I give up… I need help! What I’m writing is an app to manage rentals for my job and when the date is past, my app removes the name from 2 text files. I wrote 3 little functions(procedures) to make this work. Here:

This one loads from dates.dat file and remove the line containing the name of the employee.

procedure remDate(emp: String);/// Removes employee from date file
var
  pos1, i: integer;
  dateList: TStringList;
begin
  dateList:=TStringList.Create;
  dateList.LoadFromFile('Data\dates.dat');
  for i:=0 to dateList.Count-1 do begin
    pos1:=AnsiPos(emp, dateList[i]);
    if pos1<>0 then begin
      dateList.Delete(i);
      dateList.SaveToFile('Data\dates.dat');
    end;
  end;
  dateList.Free;
end; //eo remDate

This one removes the line containing the employee name from the perm.dat file.

procedure remPerm(emp: String);/// Removes employee from perm file
var
  pos1, i: integer;
  permList: TStringList;
begin
  permList:=TStringList.Create;
  permList.LoadFromFile('Data\perm.dat');
  for i:=0 to permList.Count-1 do begin
    pos1:=AnsiPos(emp, permList[i]);
    if pos1<>0 then begin
      permList.Delete(i);
      permList.SaveToFile('Data\perm.dat');
    end;
  end;
  permList.Free;
end; //eo remPerm

This one sticks those together. The isDue is a simple function that compares 2 dates and returns a TRUE if date is today or is past.

procedure updatePerms;
var
  empList: TStringList;
  i: integer;
begin
  empList:=TStringList.Create;
  empList.LoadFromFile('Data\employes.dat');
  for i:=0 to empList.Count-1 do begin
    if isDue(empList[i]) then begin
      remDate(empList[i]);
      remPerm(empList[i]);  (*) Here is where the error points.
    end;
  end;
  empList.Free;
end;

The error I get is when it gets to remPerm in the updatePerms procedure.(*)
I get a EStringList Error, out of bound (#). Figured out with many tries that it only happens when an employee’s due date is today. Please comment if you need more info!
Thanks in advance, any help is really appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:29:57+00:00Added an answer on May 27, 2026 at 4:29 am

    The problem is that you are using a for loop. The end point of a for loop is only evaluated once when the loop is entered. At that point you may have 100 items, but once you start deleting there will be less. This will then result in a list index out of bounds error.

    The simple fix is to reverse the for loop:

    procedure remDate(emp: String);
    /// Removes employee from date file
    var
      pos1, i: integer;
      dateList: TStringList;
    begin
      dateList := TStringList.Create;
      dateList.LoadFromFile('Data\dates.dat');
      for i := dateList.Count - 1 downto 0 do
      begin
        pos1 := AnsiPos(emp, dateList[i]);
        if pos1 <> 0 then
        begin
          dateList.Delete(i);
          dateList.SaveToFile('Data\dates.dat');
        end;
      end;
      dateList.Free;
    end; // eo remDate
    

    This will work if the employee occurs more than once.

    However if the employee does only occur once, you can use break to exit from the loop early:

    procedure remDate(emp: String);
    /// Removes employee from date file
    var
      pos1, i: integer;
      dateList: TStringList;
    begin
      dateList := TStringList.Create;
      dateList.LoadFromFile('Data\dates.dat');
      for i := 0 to dateList.Count - 1 do
      begin
        pos1 := AnsiPos(emp, dateList[i]);
        if pos1 <> 0 then
        begin
          dateList.Delete(i);
          dateList.SaveToFile('Data\dates.dat');
          Break; // <-- early exit
        end;
      end;
      dateList.Free;
    end; // eo remDate
    

    Another solution is to use a while loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
Guys lease help me out I think I'm close, but I'm missing something. Background
Guys I have been trying lots of different options from cutting up to building
Guys i have a textview which i need it to be blinking please help
guys. I've been searching for an answer for my issue the whole morning, but
Guys, this probably will be fairly simple, but how am I able to find
guys am having some troubles with running out of memory when displaying an animation
guys, I'm trying to realize viewing comments on internet portal and I'm using UITableView.
guys, I have iOS app, which running good on ios5.0, but on 4.3.3 it's
Guys, can someone give me a brief run through of how to change the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.