Solved

problems with splitting a large unit into 2 units

Posted on 1999-01-16
6
284 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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