Solved

strange compiler message

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

22 Experts available now in Live!

Get 1:1 Help Now