Solved

problems with splitting a large unit into 2 units

Posted on 1999-01-16
6
282 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

13 Experts available now in Live!

Get 1:1 Help Now