Solved

strange compiler message

Posted on 1998-08-06
5
289 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
[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
5 Comments
 
LVL 1

Accepted Solution

by:
miv earned 50 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 352
Magic Software info 18 143
Dev express lookupcombo 3 45
Sending files from  idTcpServer Socket to idTcpClient 2 52
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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