Hi All,
Just wanted to point out a minor bug or problem with Delphi that I recently
discovered incase you haven't found this one or a workaround yet. It involves
the use of the FindFirst,FindNext and FindClose functions in Delphi's object
pascal. First, in the 16 bit version if you use just FindFirst and FindNext,
everything works fine using FindFirst and FindNext. FindCose is not used in
the 16 bit version of windows so if you use it is ignored. If you port to 32
bit windows using Delphi 2.0 and forget to use the FindClose procedure, and
if you run the process several times, you start using up the heap until you
run out of space...this makes sense because the FindClose is needed after a
FindFirst/FindNext sequence to clean-up.
Now for the bug/problem or whatever you wish to call it. Delphi has a
FindClose in the Object Pascal library. The Windows API has a FindClose in it
which Delphi has included in the WINDOWS unit added to your projects by
default. The problem I observed was that my code made a call to the API call
when I needed it to call the pascal function. This caused it to fail a syntax
check because the API call requires a handle as input and returns a boolean
value. The pascal function requires an input of type TSearchRec. I had to
explicitly call the pascal function from the unit in order to correct the
problem in my program, no big deal there. I fact if you have other
suggestions Id like to them too. But for those that want to see the fixed
code, I have included it here. This is just a simple file count routine to
check the number of files in a directory.
function FileCount(PathString : string) : integer;
var
SearchRec : TSearchRec;
Ctr : integer;
RetCode : integer;
begin
Ctr:=-1; {subtract Directory count from number}
RetCode := FindFirst(PathString + '\*.*',FaAnyFile,SearchRec);
While FindNext(SearchRec) = 0
do begin
Application.ProcessMessages;
Ctr:=Ctr+1;
end;
SysUtils.FindClose(SearchRec);
FileCount:=Ctr;
end;
On other thing that eludes me at this point is that the 16 bit version
required me to subtract 2 from Ctr in the line following begin to account for
the directory references "." and ".." to show 0 if now files were in the
directory. In the 32 bit version, I had to only subtract 1 from Ctr to
accomplish the same effect. Maybe I overlooked something, but I didn't see
any mention of this in the Delphi docs...is this a Win32 issue?
Well, I hope this helps someone.
Steve
--- FreeMail 1.07b
(1:203/21)
---------------
* Origin: The Visual Programmer's Workshop - N.H., Ca (916)338-3230 *
|