Solved

problems with splitting a large unit into 2 units

Posted on 1999-01-16
6
283 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Thread safe  opinion 7 126
How to fill array with TArray.Create? 14 79
code issue 8 99
Strange behavior when a form is closed 6 51
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

22 Experts available now in Live!

Get 1:1 Help Now