Solved

problems with splitting a large unit into 2 units

Posted on 1999-01-16
6
288 Views
Last Modified: 2010-04-06

Hi experts,

I have created this unit:


unit Global;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, FileCtrl, StdCtrls, ExtCtrls, clipbrd, Buttons;

 function EnumFiles(path: string; findFile: string) : string;
 function findFileOnAllHarddisks(fileName: string) : string;

implementation

{$R *.DFM}

 function EnumFiles(path: string; findFile: string) : string;
      var fd1 : TWin32FindData;
          c1  : cardinal;
          s1  : string;
      begin
        if fileExists(path+findFile) then begin
          result:=path+findFile;
          exit;
        end;
        c1:=FindFirstFile(PChar(path+'*.*'),fd1);
        if c1<>INVALID_HANDLE_VALUE then
          try
            repeat
              s1:=string(fd1.cFileName);
              if (s1<>'.') and (s1<>'..') and (fd1.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY<>0) then
      begin
                result:=EnumFiles(path+s1+'\',findFile);
                if result<>'' then break;
              end;
            until not FindNextFile(c1,fd1);
          finally Windows.FindClose(c1) end;
      end;


function findFileOnAllHarddisks(fileName: string) : string;
      var c1,c2 : cardinal;
          ch1   : char;
      begin
        result:='';
        c2:=GetLogicalDrives;
        for ch1:='A' to 'Z' do
          if odd(c2 shr (ord(ch1)-ord('A'))) then begin
            c1:=GetDriveType(PChar(ch1+':\'));
            if c1=DRIVE_FIXED then begin
              result:=EnumFiles(ch1+':\',fileName);
              if result<>'' then break;
            end;
          end;
      end;


end.

Unfortunately in the line:

 finally Windows.FindClose(c1) end;

Delphi says:

"record,object or class-type is needed".

I don't understand why this happens. In former times,
the functions

 function EnumFiles(path: string; findFile: string) : string;
 function findFileOnAllHarddisks(fileName: string) : string;

were part of a single major unit, and everyting worked very well. As this
major untit became too large to have a good overview, I decided to split this
major unit and move


 function EnumFiles(path: string; findFile: string) : string;
 function findFileOnAllHarddisks(fileName: string) : string;

to the new created unit "global". and now suddenly I get this strange error message,
although all worked very welll earlier, when everything was in one big unit.


Can you please tell me what is wrong here?

With kind regards

Mathes


0
Comment
Question by:mathes
  • 3
  • 3
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1356873
Hi Mathes,

FindClose, wants a TSearchRec as Parameter not a typ Cardinal

meikl
0
 

Author Comment

by:mathes
ID: 1356874
hi meikl,

you are probably right, but why does this happen only after I splitted the large unit,
whereas everything worked bugfree when it was one single unit.

with kind regards

mathes
0
 

Author Comment

by:mathes
ID: 1356875
hi meikl,

you are probably right, but why does this happen only after I splitted the large unit,
whereas everything worked bugfree when it was one single unit.

with kind regards

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

 
LVL 27

Expert Comment

by:kretzschmar
ID: 1356876
Hi Mathes

try to add the Unit Windows in the unit-Clause,

then should error solved and the FindClose from Windows-API will used.

meikl
0
 

Author Comment

by:mathes
ID: 1356877
Dear meikl,

thank you for your help.

Yes, you were right. As soon as I added the "windows" unit, everything
worked very well.

With kind regards

Mathes
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 10 total points
ID: 1356878
Hi Mathes,

well then, can i get some points?

meikl
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 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