Board index » delphi » Some simple problem with FindFirst - pc1.pas [01/01]

Some simple problem with FindFirst - pc1.pas [01/01]

I have some problem with FindFirst which should be very simple but
which I can't solve for almost 2 days already.
In one of my programs I use FindFirst(path,srchrc), where
path:PChar, srcgrc: TSearchRec. Uses WinDOS is defined.
Now, the problem is that it gives me Error 26: Type mismatch,
placing cursor after srchrc. I have no idea why it's so.
To test, I substitute with FindNext(srchrc) and it was compiled
succesfully.
Any help would be greatly appreciated !

Thanks,
Vadim Cherni
Campbell CA USA

That short piece of program is attached for your reference.
BEGIN -- Cut Here -- cut here
program USENET;
        uses Strings, Windos;
        type
        TSearchRec=record
                        Fill:array[1..21] of Byte;
                        Attr:Byte;
                        Time:Longint;
                        Size:Longint;
                        Name:{PChar}array[0..12{0}] of Char;
        end;
        var
           F, F_OUT: Text;
           S: array[0..255] of Char;
           SrchRC1: TSearchRec;
           Name_o: array[0..fsPathname] of Char;
           {Dir: array[0..fsDirectory] of Char;}
           Name1:array[0..fsFileName] of Char;
           Ext:array[0..fsExtension] of Char;
           Dir:array[0..(fsDirectory+6)] of Char;
           DirPChar:PChar;
           N, N1, N2, N3:Integer;
        begin
             writeln ('Please input an output file name');
             readln (name_o);
             assign (F_out,name_o);
             append (F_out);
             filesplit (name_o, Dir, Name1, Ext);
             strecopy(dir,'*.txt');
             writeln('Processing file',dir);
             N3:=0;
             dirPChar:=dir; {convertion to PChar format}
             while Doserror=0 do
             begin
!!!          findfirst (dirPChar,srchrc1); {find input files' directory by the one of output file}
             assign(F,srchrc1.name);
             reset(F);
END -- Cut Here -- cut here

 

Re:Some simple problem with FindFirst - pc1.pas [01/01]


Quote
In article <4qipkq$...@chile.it.earthlink.net> a...@earthmail.net (ANB Corp.) writes:
>I have some problem with FindFirst which should be very simple but
>which I can't solve for almost 2 days already.
>In one of my programs I use FindFirst(path,srchrc), where
>path:PChar, srcgrc: TSearchRec. Uses WinDOS is defined.
>Now, the problem is that it gives me Error 26: Type mismatch,
>placing cursor after srchrc. I have no idea why it's so.
>To test, I substitute with FindNext(srchrc) and it was compiled
>succesfully.
>Any help would be greatly appreciated !

Two problems here.  First. . . .

Quote
>Thanks,
>Vadim Cherni
>Campbell CA USA
>[...]
>        TSearchRec=record
>                        Fill:array[1..21] of Byte;
>                        Attr:Byte;
>                        Time:Longint;
>                        Size:Longint;
>                        Name:{PChar}array[0..12{0}] of Char;
>        end;

Why are you redeclaring TSearchRec?  It's already declared in the WinDos
unit.  It doesn't seem to be the real root of your problem, but it *is*
unnecessary.

Quote
>[...]
>!!!          findfirst (dirPChar,srchrc1); {find input files' directory by

the>one of output file}

Quote
>[...]

The problem is that you haven't read your manual closely enough.  The full
declaration of FindFirst (in WinDos) is:

procedure FindFirst(Path: PChar; Attr: Word; var S:TSearchRec);
                                 ^^^^^^^^^^^

See, there are *three* parameters necessary, and you missed the second
parameter.  Attr and TSearchRec are definitely not type compatible!  The
values for Attr must be one of, or a combination of, the following:

Constant      Value
----------------------------
faReadOnly    $01
faHidden      $02
faSysFile     $04
faVolumeID    $08
faDirectory   $10
faArchive     $20
faAnyFile     $3f

Once you specify your file attributes, you shouldn't have any problems.

--
Scott Earnest          | We now return you to our regularly scheduled |
siny...@{*word*104}space.org | chaos and mayhem. . . .                      |

Other Threads