Board index » delphi » Runtme error 202: Liast all files in TPW 1.5

Runtme error 202: Liast all files in TPW 1.5

It has been a while but I ran into anther problem the program is listed below.
I get the following output.
C:\IO.SYS
C:\MSDOS.SYS
C:\84029211.4
Then I get runtime error 202 at 0001:0000, any one got any ideas and clues,
thanks in advance

program Jwlistall (input,output);
uses wincrt,
     windos,
     strings;
procedure showallfilesin (Startdir:string);
var Dirinfo:Tsearchrec;
    F:Integer;
    S:pChar;
Begin
     getMEM (S,255);
     StrpCopy (S, (StartDir + '*.*'));
     Findfirst (S,Faanyfile,dirinfo);
     while doserror=0 do
     begin
          if dirinfo.attr=fadirectory then
          begin
               if Dirinfo.Name {0} <> '.' then
                  Showallfilesin (StartDir + StrPas (Dirinfo.name) + '\');
               end
               else
                   writeln (startdir+strpas (dirinfo.Name));
                   Findnext(Dirinfo);
          end;
     Freemem (s,255);
     end;
begin
     Showallfilesin ('C:\');
end.
======================================================
DoNe By ThE pEoPlE aT hApPy SoFtWaRe :-)      Brvhart...@aol.com    
http:\\members.aol.com\brvhart662\index.html <-The Pascal Web Page            

 

Re:Runtme error 202: Liast all files in TPW 1.5


Quote
> It has been a while but I ran into anther problem the program is listed below.
> I get the following output.
> C:\IO.SYS
> C:\MSDOS.SYS
> C:\84029211.4
> Then I get runtime error 202 at 0001:0000, any one got any ideas and clues,
> thanks in advance

   The 202 error means Stack Overflow: you're using a recursive procedure
and each level of recursive call within/to it uses a fair amount of Stack
space.  I suggest making the following addition to your source program
(which may or may not fix the problem, depending on how big those local
variable are and how deeply this procedure recurses...):

Quote
> program Jwlistall;

{$M 65520,1000,10000}
Quote
> uses wincrt, windos, strings;
> procedure showallfilesin (Startdir:string);
> var Dirinfo:Tsearchrec;
>     F:Integer;
>     S:pChar;
> Begin
>   getMEM (S,255); StrpCopy (S, (StartDir + '*.*'));
>   Findfirst (S,Faanyfile,dirinfo);
>   while doserror=0 do
>     begin
>       if dirinfo.attr=fadirectory then
>         begin
>           if Dirinfo.Name {0} <> '.' then
>             Showallfilesin (StartDir + StrPas (Dirinfo.name) + '\');
>         end
>       else writeln (startdir+strpas (dirinfo.Name));
>       Findnext(Dirinfo)
>     end;
>   Freemem (s,255)
> end;
> begin
>   Showallfilesin ('C:\');
> end.

Re:Runtme error 202: Liast all files in TPW 1.5


On 15 Apr 1998 20:27:47 GMT, brvhart...@aol.com (Brvhart662) wrote:

Quote
>It has been a while but I ran into anther problem the program is listed below.
>I get the following output.
>C:\IO.SYS
>C:\MSDOS.SYS
>C:\84029211.4
>Then I get runtime error 202 at 0001:0000, any one got any ideas and clues,
>thanks in advance

>program Jwlistall (input,output);
>uses wincrt,
>     windos,
>     strings;
>procedure showallfilesin (Startdir:string);
>var Dirinfo:Tsearchrec;
>    F:Integer;
>    S:pChar;
>Begin
>     getMEM (S,255);
>     StrpCopy (S, (StartDir + '*.*'));
>     Findfirst (S,Faanyfile,dirinfo);
>     while doserror=0 do
>     begin
>          if dirinfo.attr=fadirectory then
>          begin
>               if Dirinfo.Name {0} <> '.' then
>                  Showallfilesin (StartDir + StrPas (Dirinfo.name) + '\');
>               end
>               else
>                   writeln (startdir+strpas (dirinfo.Name));
>                   Findnext(Dirinfo);
>          end;
>     Freemem (s,255);
>     end;
>begin
>     Showallfilesin ('C:\');
>end.

You've got a logic problem with the handling of the '.' directory
which is causing you to get stuck in an endless recursion loop causing
the stack overflow.

if Dirinfo.Name[0] <> '.' then
  Showallfilesin (StartDir + StrPas (Dirinfo.name) + '\');

If you change your code to check for the '.' directories as above
things should be OK.

Michael

____________________________________________________________________
  Michael Phillips                            Tel: +61-2-6281-1980
  mphil...@pcug.org.au                        Fax: +61-2-6281-1980

Re:Runtme error 202: Liast all files in TPW 1.5


Hi !

Quote
Brvhart662 wrote:

> It has been a while but I ran into anther problem the program is listed below.

What about '..' and FindClose() ?

Recursion is a wrong way for that things. (Stack, memory, etc...) Use
iteration.

--
With best regards,
        Alexander "Novik" Moskalets.

Re:Runtme error 202: Liast all files in TPW 1.5


On Thu, 16 Apr 1998 12:48:20 +0400, Novik <no...@referent.ropnet.ru>
wrote:

Quote
>What about '..' and FindClose() ?

'..' will be taken care of by the same line that takes care of '.' :
if first character <> '.' then findallfilesin etc.

and what about FindClose? BP does not support such a function. What
does it do?

Quote
>Recursion is a wrong way for that things. (Stack, memory, etc...) Use
>iteration.

Of course you can use iteration, if only to simulate recursion, but in
this particular case I think recursion is the perfect solution. It
generates nice, clean and short code. Recursion is a good way of doing
lots of things (see for example the maze solving thread in this NG a
while ago), and is this case, stack usage is not as extreme as it may
seem. On my C:-drive, the maximum nesting level is 9, which means 9
times the size of the local variables, plus maybe some space to save
registers. Not really a problem, I'd say.

Regards,
Klaas
------
this sigfile intentionally left blank

Re:Runtme error 202: Liast all files in TPW 1.5


On Mon, 20 Apr 1998 12:00:11 +0400, Novik <no...@referent.ropnet.ru>
tried to make sense of my posting:

Quote
>Hi !

>Klaas de Jong wrote:

>> On Thu, 16 Apr 1998 12:48:20 +0400, Novik <no...@referent.ropnet.ru>
>> wrote:

>> >What about '..' and FindClose() ?

>> '..' will be taken care of by the same line that takes care of '.' :
>> if first character <> '.' then findallfilesin etc.

>But, from source article:
>> >           begin
>> >                if Dirinfo.Name {0} <> '.' then
>                                   ^^^
>This is comment, not [0].

You are right, this _is_ comment, and that is exactly why the program
did not work. [0] comes from the revised versin of the program, that
does work (without RTE 202).

Quote
>But runtime error 202 - Stack overflow error.
>SizeOf(Tsearchrec)+SizeOf(Integer)+SizeOf(pChar)+SizeOf(string)
>(temporary storage) per call.

You are right again, but the stack overflow was caused by the faulty
line above:

{ Now without the comment: }
        If Dirinfo.Name <> '.' Then
{that was what it says there. }

What happens here is that the '.' entry in the dirctory is handled
correctly (ignored, that is), but since '..' does not equal '.',
SearchAllFilesIn is called with argument '..'.
What happens on my drive is this:

First Directory is  c:\ddata. First entry in that one is '.'
(ignored), then '..' (selected, we're back on C:/). First entry we see
is ddata (selected), then '..' again, etcetera. Just trace it, and
watch the value for startdir:
c:\ddata\..\ddata\..\ddata\..\ etcetera ad infinitum, or at least ad
RTE 202.

Quote
>--
>With best regards,
>    Alexander "Novik" Moskalets.

Regards,
Klaas de Jong
------
this sigfile intentionally left blank

Re:Runtme error 202: Liast all files in TPW 1.5


Hi !

Quote
Klaas de Jong wrote:

> On Thu, 16 Apr 1998 12:48:20 +0400, Novik <no...@referent.ropnet.ru>
> wrote:

> >What about '..' and FindClose() ?

> '..' will be taken care of by the same line that takes care of '.' :
> if first character <> '.' then findallfilesin etc.

But, from source article:
Quote
> >           begin
> >                if Dirinfo.Name {0} <> '.' then

                                   ^^^
This is comment, not [0].

Quote
> and what about FindClose? BP does not support such a function. What

FindClose need for work under Win32. If you use Win16, it's don't need.
This is my mistake.

Quote
> seem. On my C:-drive, the maximum nesting level is 9, which means 9
> times the size of the local variables, plus maybe some space to save
> registers. Not really a problem, I'd say.

But runtime error 202 - Stack overflow error.
SizeOf(Tsearchrec)+SizeOf(Integer)+SizeOf(pChar)+SizeOf(string)
(temporary storage) per call.

--
With best regards,
        Alexander "Novik" Moskalets.

Re:Runtme error 202: Liast all files in TPW 1.5


Re:Runtme error 202: Liast all files in TPW 1.5


Can anybody help ??

I want to know if its possible to do a screen dump straight to a printer
when in graphics window ???? have tried print screen button and alt
print screen button .. also ive looked at some picture grabbers but they
dont seem to like it ????

any help muchly appreciated !!!

Other Threads