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

A small 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
>              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

        The findfirst sentence must be before while Doserror=0 do sentence i.e.

findfirst (parameters);
while doserror = 0 do
  begin
    assign (parameters);
    reset (parameters)
 findnext (parameters)
end;

                 Br. Marcos Enrique Yanes Ceballos
                      Administracion de Redes
             Direccion General de Servicios de Computo
                  UNIVERSIDAD AUTONOMA DE CAMPECHE
                  E-Mail: maeya...@jaina.uacam.mx

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


Quote
a...@earthmail.net (ANB Corp.) wrote:
> 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.

You didn't mention which version of Delphi you were using, but if it is
Delphi 2.0, you're problem is most likely that FindFirst is both a Delphi
function, and a Windows API function.  Dot notation will solve the problem:

  SysUtils.FindFirst(path, srcrc);

Regards,
Brad
bstow...@pobox.com
Free Delphi Stuff:  http://www.pobox.com/~bstowers/delphi/

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


Hi all

On 23 June 1996 Vadim Cherni wrote:

Quote
>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

(etc. etc.)

The problem is that FINDFIRST expects one more argument:

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

The argument ATTR, of type WORD, represents the file attributes (e.g.
faHidden, faReadOnly, etc) you want to be searched for.

Votis

-----------------------------------------------------------------------------
Votis Kokavessis
Mathematics teacher & pascal programmer
Thessaloniki, Greece
E-mail address: paratiritis.the.forthnet...@popper.forthnet.gr (votis)
-----------------------------------------------------------------------------

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


Quote
ANB Corp. wrote:

> 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

I have in mind that the correct syntax of FindFirst (Unit DOS) should be:

      FindFirst(Path,Attr,SrchRec);

where

  Path - File name to find, including '*' and '?'
  Attr - Files attributes
  SrchRec - a structure of the type SearchRec

I think it's the same using the Unit WinDOS. For a better reference
you should use the help.

Hartmut.
--
e-mail  : kue...@student.tu-freiberg.de
homepage: http://www.geo.tu-freiberg.de/~kuehne/index.htm

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


Quote
On Sun, 23 Jun 96 06:55:11 GMT, a...@earthmail.net (ANB Corp.) wrote:

~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:

Hi,

I was also playing around with the FindFirst and FindNext commands
just a few days ago.

Your problems lies with the
        path: Pchar;

It should be
        Path: String;

For your information, it is defined that way in the help files...

HTH

Finest Regards,
Sam

         \||||||||/
          | \  / |
         (| @  @ |)
*****oOOo***(__)***oOOo********

From the desk of Song Weng Sam

Email : son...@pacific.net.sg
Pager : 9-492-4014

*****oOOo**********oOOo********

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


In <4qiq0r$...@chile.it.earthlink.net> a...@earthmail.net (ANB Corp.)
writes:

Quote

>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

>A small 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}

Quote
>             assign(F,srchrc1.name);
>             reset(F);
>END -- Cut Here -- cut here

There is no such thing as finfirst.  Use Findkey or FindNearest.
Ben

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


Quote
arr...@ix.netcom.com(Arrow) wrote:

    >
    >There is no such thing as finfirst.  Use Findkey or FindNearest.
    >Ben
    >

Duh,

There may not be such a thing as finfirst, but there *is* a FindFirst function
in Delphi. You are using Delphi, aren't you?

Ian Piper
---
Mail address:   i...@monty.demon.co.uk

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


Quote
>ANB Corp. wrote:

>> 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 !

Why this Windoze question is in comp.lang.pascal.misc I dunno, but...

I have had this problem, and the solution involves reordering your UNITS.
There's a duplicate definition somewhere (I forget exactly).  Try moving
WinDOS to the end of the UNITS statement.

______________________________________________________________
Paul Rodman              iLanga, Inc.        rod...@ilanga.com
______________________________________________________________

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


Quote
ANB Corp. wrote:

> 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

This is your problem: 1. get rid of the TSearchRec TYPE
declaration...you don't need it.  Then, the var is SUPPOSED to be
defined as JUST "SearchRec" NO T!!!!

Looks like this:

VAR
 path : String;
 FileInfo : SearchRec;

Begin
 FindFirst(Path,AnyFile,FileInfo);
End.

Have fun!
ViPeR

P.S. -  The middle term can be : HIDDEN, ANYFILE, ARCHIVE, SYSTEM,      
        READONLY, or DIRECTORY.

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


Quote
In article <31D010CD.4...@magicnet.com>, HomeShow <homes...@magicnet.com> wrote:
>This is your problem: 1. get rid of the TSearchRec TYPE
>declaration...you don't need it.  Then, the var is SUPPOSED to be
>defined as JUST "SearchRec" NO T!!!!

From what I remember, TSearchRec is correct for Windoze apps (WinDOS
unit), and SearchRec for DOS apps (DOS unit).

______________________________________________________________
Paul Rodman              iLanga, Inc.        rod...@ilanga.com
______________________________________________________________

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


And if you put the cursor on FindFirst and press CTRL-F1, the help for it will
pop up along with sample code for DOS and Windows...

--
BCNU
Daniel J. Wojcik
http://147.35.241.5/mindless/mindless.htm
--
Latest news:  Termite Chat v2.3 for Windows-based HTTP Servers
                    Lots of neat-o features!
                    ftp://147.35.241.5/pub/www/termite.zi

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


Quote
In article <31D010CD.4...@magicnet.com>, HomeShow <homes...@magicnet.com> wrote:
>This is your problem: 1. get rid of the TSearchRec TYPE
>declaration...you don't need it.  Then, the var is SUPPOSED to be
>defined as JUST "SearchRec" NO T!!!!

From what I remember, TSearchRec is correct for Windoze apps (WinDOS
unit), and SearchRec for DOS apps (DOS unit).

______________________________________________________________
Paul Rodman              iLanga, Inc.        rod...@ilanga.com
______________________________________________________________

Other Threads