# Solved: StringList looping problem - Lazarus/Delphi



## MetaWebIT (Apr 22, 2005)

Hi all

Having a problem coding a StringList in Lazarus (open source Delphi clone), and hoping someone might point me in the right direction. I'm trying to loop getting extracted filenames strings from a listbox and putting them into a StringList, but it puts the *SAME* extracted filename when it outputs (the last filename) - what am I doing wrong?

Here's the procedure (see first part of proc for the section I am having problems with):

```
procedure TPDFLinkGeneratorFORM.GenerateCodeBITBTNClick(Sender: TObject);
{Generate HTML Code}
var
  JustFilename : TStringlist;
  i: integer;
  fnamecount : integer;
begin
JustFilename:=TStringlist.Create;
// STARTS HERE
   begin
     for fnamecount := 0 to PDFsLBX.Items.Count - 1 do
     JustFilename.Add(ExtractFileNameOnly(PDFsLBX.Items[fnamecount]));
// ENDS HERE

  i := 0;
    repeat
      begin
        GeneratedCodeMEMO.Lines.Strings[i] := '<a href="' + BaseURLEdit.Text +
          BaseFolderEdit.Text + PDFsLBX.Items[i] + '" ' +
          'target= "_blank">' + JustFilename.Strings [fnamecount] + '</a>';
        i := i + 1;
      end
    until i = PDFsLBX.Count;
    JustFilename.Free;
end;
```
Thanks in anticipation
Carl


----------



## IMM (Feb 1, 2002)

Didn't really look deep and don't know where PDFsLBX.Items comes from but it looks like the following change is needed

JustFilename.Strings [fnamecount] ==> JustFilename.Strings


----------



## MetaWebIT (Apr 22, 2005)

Thanks Imm, it's been solved now


----------

