Solved

Findnext Exception.

Posted on 1998-12-27
6
433 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

Technology Partners: 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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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