Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

parsing of strings

Posted on 1998-08-02
4
Medium Priority
?
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

722 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