Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Some string handling issues

jobromediajobromedia Member Posts: 168
Ok just a quick question. I've got this code that reads a list of folders:

[code]if findfirst('*.',faDirectory,sr) = 0 then
begin
Games.Items.Add(sr.Name);
repeat
findnext(sr);
Games.Items.Add(sr.Name);
until findnext(sr) <> 0;
end;[/code]

It goes ok when reading in the list, but it is here when the list is being processed that I'm getting a "List boundry out of range" error:

[code]for i := 1 to Games.Items.Count -1 do
begin
if Games.Items.Text <> '' then
begin
s := Games.Items.Strings[i];
if Games.Items.Strings[i] = '.' then
Games.Items.Delete(i);
if Games.Items.Strings[i] = '..' then
Games.Items.Delete(i);
if s[1] = '_' then Games.Items.Delete(i);
if s[1] = '%' then Games.Items.Delete(i);
end;
end;[/code]

It is ment to sort out folders starting with _ and % characters.

Just so you know, it is ment to hide damaged data folders on PlayStation Portable. One methode to do this is by inserting __SCE__ before the folder names and %__SCE__ before the folders that PSP sees as corrupted. Now don't ask me what __SCE__ stands for, I know it works when it comes to hiding the corrupted data. So what I need to know is how to detect these strings and then removing these items so the users don't reprotects them. There is also another thing I need help with. Each PSP homebrew comes with 2 folders named slightly different: Name and Name%. And it is the Name% that is intresting in this case. I need to detect the last percent and if present remove the item.

Anyone up for the task? Humble thanks in advance if you are capable of helping me out.

Comments

  • ManagesoftManagesoft Member Posts: 3
    : Ok just a quick question. I've got this code that reads a list of
    : folders:
    :
    : [code]: if findfirst('*.',faDirectory,sr) = 0 then
    : begin
    : Games.Items.Add(sr.Name);
    : repeat
    : findnext(sr);
    : Games.Items.Add(sr.Name);
    : until findnext(sr) <> 0;
    : end;[/code]:
    :
    : It goes ok when reading in the list, but it is here when the list is
    : being processed that I'm getting a "List boundry out of range" error:
    :
    : [code]: for i := 1 to Games.Items.Count -1 do
    : begin
    : if Games.Items.Text <> '' then
    : begin
    : s := Games.Items.Strings[i];
    : if Games.Items.Strings[i] = '.' then
    : Games.Items.Delete(i);
    : if Games.Items.Strings[i] = '..' then
    : Games.Items.Delete(i);
    : if s[1] = '_' then Games.Items.Delete(i);
    : if s[1] = '%' then Games.Items.Delete(i);
    : end;
    : end;[/code]:
    :
    : It is ment to sort out folders starting with _ and % characters.
    :
    : Just so you know, it is ment to hide damaged data folders on
    : PlayStation Portable. One methode to do this is by inserting __SCE__
    : before the folder names and %__SCE__ before the folders that PSP
    : sees as corrupted. Now don't ask me what __SCE__ stands for, I know
    : it works when it comes to hiding the corrupted data. So what I need
    : to know is how to detect these strings and then removing these items
    : so the users don't reprotects them. There is also another thing I
    : need help with. Each PSP homebrew comes with 2 folders named
    : slightly different: Name and Name%. And it is the Name% that is
    : intresting in this case. I need to detect the last percent and if
    : present remove the item.
    :
    : Anyone up for the task? Humble thanks in advance if you are capable
    : of helping me out.


    Good day first of all is there a reason that you are not starting the "For" at 0? Cause the listboz starts counting at zero and not one hence the reason for you to lessen the Count variable with 1. As far as the error, your code is not supposed to give the error according to me unless i missed something, or unless well i'm wrong with i don't think i am, so my guess is that there is rather something wrong with the data, or it might be that the listbox is empty and that you are starting at 1 to count or it mean that you have less than 2 items in the listboxs and you start counting at the second, start the "For" at zero it might help.

  • jobromediajobromedia Member Posts: 168
    : Good day first of all is there a reason that you are not starting
    : the "For" at 0? Cause the listboz starts counting at zero and not
    : one hence the reason for you to lessen the Count variable with 1. As
    : far as the error, your code is not supposed to give the error
    : according to me unless i missed something, or unless well i'm wrong
    : with i don't think i am, so my guess is that there is rather
    : something wrong with the data, or it might be that the listbox is
    : empty and that you are starting at 1 to count or it mean that you
    : have less than 2 items in the listboxs and you start counting at the
    : second, start the "For" at zero it might help.
    :
    :
    The reason I started at 1 was because I had the error at 0 as well. And I commented the for loop and the list is not empty. Then I tried to delete list entry 0 and 1 which only deleted entry 1 (it's a checklistbox). So that's why I changed it to 1 instead of 0.
  • zibadianzibadian Member Posts: 6,349
    : : Good day first of all is there a reason that you are not starting
    : : the "For" at 0? Cause the listboz starts counting at zero and not
    : : one hence the reason for you to lessen the Count variable with 1. As
    : : far as the error, your code is not supposed to give the error
    : : according to me unless i missed something, or unless well i'm wrong
    : : with i don't think i am, so my guess is that there is rather
    : : something wrong with the data, or it might be that the listbox is
    : : empty and that you are starting at 1 to count or it mean that you
    : : have less than 2 items in the listboxs and you start counting at the
    : : second, start the "For" at zero it might help.
    : :
    : :
    : The reason I started at 1 was because I had the error at 0 as well.
    : And I commented the for loop and the list is not empty. Then I tried
    : to delete list entry 0 and 1 which only deleted entry 1 (it's a
    : checklistbox). So that's why I changed it to 1 instead of 0.

    You need to loop from the bottom to the top. The for-do loop only checks the Count once. After that it's fixed for the entire loop. This causes a problem if you start to delete items in the loop, because the i will go out of bounds if at least one item gets deleted.
    When you start at the Count-1 and loop downto 0, then you'll have checked the highest indexed item already, before any items could be deleted.
  • jobromediajobromedia Member Posts: 168
    Ahh! Spot on, didn't think that way. Thanks.

    Still I've tried to do this and yet the list boundries are broken. Can someone show me how to write the routine properly so this doesn't happen?
  • zibadianzibadian Member Posts: 6,349
    : Ahh! Spot on, didn't think that way. Thanks.
    :
    : Still I've tried to do this and yet the list boundries are broken.
    : Can someone show me how to write the routine properly so this
    : doesn't happen?

    Here's a simple code to remove all even indexed items:
    [code]
    for i = ListBox1.Items.Count-1 downto 0 do
    if i mod 2 = 0 then
    ListBox1.Items.Delete(i);
    [/code]
Sign In or Register to comment.