Solved

parsing of strings

Posted on 1998-08-02
4
135 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 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now