E2010 Incompatible types: ‘Cardinal’ and ‘TSearchRec’

在编写一个非常简单的Delphi程序时,遇到一个奇怪的问题

[DCC Error] Project2.dpr(25): E2010 Incompatible types: ‘Cardinal’ and ‘TSearchRec’

var
  searchResult : TSearchRec;

begin
  // Try to find regular files matching Unit1.d* in the current dir
  if FindFirst('Unit1.d*', faAnyFile, searchResult) = 0 then
  begin
    repeat
      ShowMessage('File name = '+searchResult.Name);
      ShowMessage('File size = '+IntToStr(searchResult.Size));
    until FindNext(searchResult) <> 0;

    // Must free up resources used by these successful finds
    FindClose(searchResult);
  end;
end;

 

上述代码来自【参考1】

错误始终指向 FindClose(searchResult); 这一句,百思不得其解,后来搜索到了一个解释【参考2】,调换 uses 中的 windows和 sysutils 位置即解决……

参考:

1.http://www.delphibasics.co.uk/RTL.asp?Name=FindFirst FindFirst Function

2.http://www.delphipages.com/forum/showthread.php?t=145983

发表评论

电子邮件地址不会被公开。 必填项已用*标注