Solved

strange compiler message

Posted on 1998-08-06
5
298 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 10 hours left to enroll

632 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