Solved

strange compiler message

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

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

18 Experts available now in Live!

Get 1:1 Help Now