Solved

Findnext Exception.

Posted on 1998-12-27
6
425 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

697 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