I'm currently working on a large script (for me) where I need do delete some files in a folder. To identify which files I need to delete, I'm reading a text file which contains all the informations I need. I'm using a TStringList class and the function Pos() to get these informations.
My problem comes from the function Pos() which is returning several values, one value for each string of the StringList (text file).
So here is the dedicated part of my script :
Procedure Delete;
Var
SL : TStringList;
i, A, B : Integer; //i is a Counter, A and B are not mandatory but are useful for DEBUG
PCBFile : String;
Begin
PCBFile := //Full Path
SL := TStringList.Create;
SL.LoadFromFile(PCBFile);
For i := 1 To (SL.Count - 1) Do //I don't need to check the 1st line of the text file.
A := Pos('gtl', SL.Strings[i]); //Here is when the problem occurs.
B := Pos('gbl', SL.Strings[i]); //Doesn't get to here because i = SL.Count before looping
If (A = 0) And (B = 0) Then //The goal
ChangeFileExt(PCBFile, '.TX');
PCBFile := PCBFile + FloatToStr(i-2); //The files I want to delete can have several extensions (tx1, tx2... txN)
DeleteFile(PCBFile);
End;
End;
SL.Free;
End;
If I change this line :
A := Pos('gtl', SL.Strings[i]);
To this :
ShowInfo (Pos('gtl', SL.Strings[i])); //Basic function from Altium Designer, same as Writeln()
It will show a pop up with the result of the function Pos() for each line of the text file. I assume that SL.Strings[i] does an internal auto-increment of i, but I want to manage it with my For Do loop.
I past two days searching on the web but didn't find any clue on what to do, maybe the problem comes from Altium Designer, which is not really a programming software at first.
I also tried with the SL.IndexOf() function but it only works with strict Strings, which is not my case.
Thanks for your time and help.
Best regards, Jordan