Re: multiple filenames in Delphi label.caption
Posted by webmaster Guido on September 01, 2000 at 22:14:47: In Reply to: multiple filenames in Delphi label.caption posted by Ken on August 30, 2000 at 16:06:08:
: I need a text string containing the names of multiple files (selected by clicking on a filelistbox). procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
S: string;
begin
S := '';
for i := 0 to (FLB1.Items.Count - 1) do
if FLB1.Selected[i] then begin
S := S + FLB1.Items[i] + ' ';
// Do something with S
Label1.Caption := S;
end;
end;
To save the selected filenames to a text file, for example FILES.TXT in the application's directory: procedure TForm1.Button2Click(Sender: TObject);
const
TextFileName = 'files.txt';
var
i: integer;
SL: TStringList;
Dir: string;
begin
SL := TStringList.Create;
for i := 0 to (FLB1.Items.Count - 1) do
if FLB1.Selected[i] then
SL.Add(FLB1.Items[i]);
Dir := ExtractFileDir(Application.ExeName);
if Dir[Length(Dir)] <> '\' then Dir := Dir + '\';
SL.SaveToFile(Dir + TextFileName);
SL.Free;
end;
|
|