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

x
?
Solved

strange compiler message

Posted on 1998-08-06
5
Medium Priority
?
305 Views
Last Modified: 2010-04-04

Hi expertes,

I am faced with a strange compiler message. In the source code below, Delphi
complains about a missing END. at the end of the module. As everybody can clearly see,
there is an "END." at the end of this Unit. So why is there an error in this source?


unit test;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  F: Textfile;
  I: integer;
  FileName: string;

begin
  OpenDialog1.Title := 'Delete File';
  if OpenDialog1.Execute then
    with OpenDialog1.Files do
     for I := 0 to Count - 1 do
      begin {for...to}
        AssignFile(F, OpenDialog1.FileName);
        try
          Reset(F);
          if MessageDlg('Erase ' + OpenDialog1.FileName + '?',
            mtConfirmation, [mbYes, mbNo], 0) = mrYes then
          begin
            CloseFile(F);
            Erase(F);
          end; {if}
        except
          on EInOutError do
            MessageDlg('File I/O error.', mtError, [mbOk], 0);
        end; {for...to}
      end; {procedure}

end. {Unit}


With kind regards

Christian

0
Comment
Question by:mathes
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
miv earned 100 total points
ID: 1361620
You need to "END;" the try-except as well.
0
 

Author Comment

by:mathes
ID: 1361621
Dear miv,

thank you for your mail. I meanwhile added an "end" to my code. Now the compiler in line

Reset(F);

complains about an exception of class ElnOutError.

If I select only 1 file, everything works perfectly, without any errors, but as soon as I
select multiple files, I recieve this error message mentioned above.
What is wrong here? Did I add the "end" at the right place? Can you please review my code?


begin
  OpenDialog1.Title := 'Delete File';
  if OpenDialog1.Execute then
    with OpenDialog1.Files do
     for I := 0 to Count - 1 do
      begin {for...to}
        AssignFile(F, OpenDialog1.FileName);
        try
          Reset(F);
          if MessageDlg('Erase ' + OpenDialog1.FileName + '?',
            mtConfirmation, [mbYes, mbNo], 0) = mrYes then
          begin {if}
            CloseFile(F);
            Erase(F);
          end; {if}
        except
          on EInOutError do
            MessageDlg('File I/O error.', mtError, [mbOk], 0);
        end; {except}  
        end; {for...to}
      end; {procedure}



With kind regards

Christian
0
 
LVL 1

Expert Comment

by:miv
ID: 1361622
"Can you please review my code? "
Did that, but you´re only handling one file - and can´t understand why the code fails when you do a multiselect...

This place is called "Experts Exchange", your Q deals with simple programming topics. Please read the manuals or sign up for a course.

Regards,
  Michael

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1361623
The reason for the error: you are trying to delete the same file in the loop. ie when i increase, the filename is still unchanged.
You should use files[ i] rather than filename property.
Cange the line assignFile... to
AssignFile(F, OpenDialog1.Files[ i]);
0
 

Author Comment

by:mathes
ID: 1361624
hi,

due to tech problems with my monitor i must retire for a few weeks. as soon as my problems with my hardware are fixed i will return and rate your comments. sorry for the inconvience.

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline

916 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