Solved

Findnext Exception.

Posted on 1998-12-27
6
404 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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