Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

parsing of strings

Posted on 1998-08-02
4
Medium Priority
?
149 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:mathes
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1359536
Hi mathes,

all the files you select, are stored in a TStrings property. So to get all the files the user has selected, just use the methods of TStrings.

The Property Count gives the amount of files in the TStrings. All files are stored in Strings property and you can get the first filename as Strings[0].

So, the solution to your problem :

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

Regards, Zif.
0
 

Author Comment

by:mathes
ID: 1359537

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

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359538
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.
0
 

Author Comment

by:mathes
ID: 1359539
Dear Zif,

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

With kind regards

Christian

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question