Link to home
Start Free TrialLog in
Avatar of mathes
mathes

asked on

parsing of strings

Hi experts,

with the help of the opendialog control I let the user select
several files. I store the selected filenames in a buffer.
How can I now scan this buffer for the selected filenames and
work these filenames in another procedure?

You have to consider that:

a) the user could have selected only 1 file, although the multiselect property
of my opendialog control is set to "TRUE", so you can't be sure before how many
filenames there will be stored in the buffer.    

b) unter Windows 95 the user has the option to use the classic DOS 8.3 filenames
and long filenames as well. The parsing routine should be able to handle
both types of filenames.

c) The routine I am searching for should support all 32 Bit versions of Windows.
(i.e. Windows 95, Windows 98 and Windows NT)

To clarify want I want please have a look at the following code. This code code
works perfectly if the multiselect property is set to FALSE. How must I modify
this source code in order to be able to process multiple file selections, too?
(Changing multiselect from TRUE to FALSE won't be the only needed adjustment
in my code :)))) )


rocedure TfrmPrintFile.Button3Click(Sender: TObject);

var filename, s: string;
    printer, t: textfile;
begin
  if opendialog1.execute then
    filename:=opendialog1.filename;
  try
    assignPrn(printer);
    rewrite(printer);
    reset(t, FileName);
    while not eof(t) do begin
      readln(t, s);
      writeln(printer, s);
    end;
  finally
    closefile(t);
    closefile(printer);
  end;
end;


With kind regards

Christian
ASKER CERTIFIED SOLUTION
Avatar of ZifNab
ZifNab

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mathes
mathes

ASKER


Dear Zif,

thank you for your source code. There is a problem in this source code.
If I select for example 3 files, there are indeed 3 printous created by
my printer. However after reading the printouts I see that multiple copies
of one these files were printed on my paper. Actually I would like to see
a printout of EACH of the selected files. However only one of the selected
files is processed by your code, whereas the other selected files are totally
ignored and not to see on the paper

Can you please review the code and please tell me what is wrong here?

procedure TfrmPrintFile.Button3Click(Sender: TObject);

var filename, s: string;
    printer, t: textfile;

begin
  if opendialog1.execute then
    filename:=opendialog1.filename;
 with OpenDialog1.Files do
    for I := 0 to Count - 1 do
    begin
 
 try
    assignPrn(printer);
    rewrite(printer);
    reset(t, FileName);
    while not eof(t) do begin
      readln(t, s);
      writeln(printer, s);
    end;
  finally
    closefile(t);
    closefile(printer);
  end;
end;


With kind regards

Christian

Hi Christian,

that's because it has to be :

 assignPrn(printer);
 rewrite(printer);
 reset(t, strings[I]); <----- !!!!!
 while not eof(t) do begin
  readln(t, s);
  writeln(printer, s);
 end;

AND NOT! :

 assignPrn(printer);
 rewrite(printer);
 reset(t, FileName); <------- !!!!!!
 while not eof(t) do begin
   readln(t, s);
   writeln(printer, s);
 end;

See also at my example code. Don't forget that in Filename property, only one file is stored. If you use multiselect, you've to go to the stringlist property 'Files'.

So, to get one selected : opendialog1.filename
to get all selected files : opendialog1.Files.Strings[Fileindex] where fileindex is of type integer and is the index of the filename in the stringlist.

Regards, Zif.
Avatar of mathes

ASKER

Dear Zif,

thank you for reviewing the code. Now all works perfectly. Sorry, this time it was clearly my mistake.

With kind regards

Christian