Solved

parsing of strings

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

12 Experts available now in Live!

Get 1:1 Help Now