Solved

Findnext Exception.

Posted on 1998-12-27
6
409 Views
Last Modified: 2010-04-04
Hi, mycode is raising an exception and i don't know why. the code searches for .mp3 files
but on the findnext command it raises the exception pleaze help.

the exception is :

Project Mp3IDCompare.exe raised exception class EAccessViolation with message 'Access violation at
address 77F674CB in module 'ntdll.dll'. Read of address 00000027'. Process stopped. Use Step or Run to
continue.

the code is :

dirinfo is of the type Tstringlist.
Searchrec is of the type TSearchrec.
Oldname is of type String.
i is of the type integer.


dirinfo.add('C:\MP3\');
dirinfo.add('C:\MP3\A\');
dirinfo.add('C:\MP3\B\');
dirinfo.add('C:\MP3\C\');

  For I := 0 to DirInfo.Count - 1 do
   begin
    FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);
    while OldName <> SearchRec.Name do
     begin
      OldName:=SearchRec.Name;
      if ((SearchRec.Attr and 16 ) <> 16) {not a directory}
       then begin
             {Some Code}
          end;
      FindNext(SearchRec);
     end;
    FindClose(SearchRec);
   end;


Pleaze help me Thanx,
ruben
0
Comment
Question by:rtieland
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1353310
try doing this,,,,

code := FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);

if not code = 0 then....do the rest...

-Viktor
--Ivanov
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1353311
Use this one...

function FindFiles( sDir, sMask: string; rgsFiles: TStrings; bRecursively: Boolean ): Integer;
 var
       SR: TSearchRec;
     begin
       Result := 0;
       if not Assigned( rgsFiles ) then Exit;
       if sDir[ Length( sDir )] <> '\' then AppendStr( sDir, '\' ); // fix dir
       if FindFirst( sDir + sMask, faAnyFile, SR ) = 0 then repeat
         if ( SR.Attr and faDirectory ) <> faDirectory then rgsFiles.Add(
     sDir+SR.Name );
       until FindNext( SR ) <> 0;
       FindClose( SR );
       // recursive part...
       if bRecursively then begin
         if FindFirst( sDir + '*.*', faAnyFile, SR ) = 0 then repeat
           if (( SR.Attr and faDirectory ) = faDirectory ) and ( SR.Name[1] <> '.' )
           then FindFiles( sDir+SR.Name+'\', sMask, rgsFiles, bRecursively );
         until FindNext( SR ) <> 0;
         FindClose( SR );
       end;
       Result := rgsFiles.Count;
     end;

Example call:

FindFiles( 'C:\MP3\', '*.mp3', ListBox1.Items, True );

-Viktor
--Ivanov
0
 
LVL 1

Author Comment

by:rtieland
ID: 1353312
'code' is getting the value '2' from the findfirst command why?

code:=FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);
0
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.

 
LVL 10

Expert Comment

by:viktornet
ID: 1353313
Sorry, the correct one is ...

code := FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);

if code = 0 then //Everything is okay and do your stuff...

It is probably getting 2 because there is no such a directory as C:\MP3 or whatever.... The directory should be a real one that is present... then try including one or two MP3s and see if it works... btw- Why don't you use the function I geve you.. It works fine... try it...

-Viktor
--Ivanov
0
 
LVL 1

Author Comment

by:rtieland
ID: 1353314
The Directory exists and there are mp3 files in it but it still gives '2' (The Directory is a directory on a server and mapped to a drive letter such as r:=\\opcenter\d$ and d$ got a directory MP3 with mp3 files in it).

Does your FindFiles give back the name of the file

please give me a point from where i can work with the file name

thanx,
ruben
0
 
LVL 1

Author Comment

by:rtieland
ID: 1353315
I studied your function and adopted it in my program.
it works Great.

Thanx,
ruben
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

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…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

10 Experts available now in Live!

Get 1:1 Help Now