[英]Error when using FileSize(F) in Delphi 2010
我正在编写一个用于记录显微镜使用情况的应用程序,但以下代码段在读取的行上生成了错误的E2010不兼容类型“ WideString”和“ TDataFile”:SetLength(Items,FileSize(F));我缩小了范围问题给FileSize(F),一个数字反而没有给出错误,并尝试分配i:= fileSize(F);其中i是一个整数也给出相同的错误。
type
TData = record
Status : integer; // 0=operational 1=maintenance 2=fault
OperatorName : string[255];
Client : string[255];
Specimen : string[255];
Memo : string[255];
TEM : TTEM;
SEM : TSEM;
FIB : TFIB;
StartTime : string[22]; // YYYY/MM/DD HH:MM:SS AM
FinishTime : string[22];
DataFileName : string[255];
end;
TDataFile = File of TData;
TDataArray = array of TData
function LoadAllData(FileName: string; var Items: TDataArray):boolean;
// Loads contents of Datafile into Items and returns true if successful else false
var
F : TDataFile;
i : integer;
begin
AssignFile(F, FileName);
try
try
Reset(F);
SetLength(Items, FileSize(F)); // This is the problem line
for i := 0 to High(Items) do
Read(F, Items[i]);
LoadAllData := true;
except
LoadAllData := false;
end;
finally
CloseFile(F);
end;
end;
我在Win7 64位上使用了delphi 2010。 有人知道为什么会这样吗? 编写一个小型控制台应用程序只是为了测试i:= FileSize(F); 没问题。...
看来您在另一个单元或代码的一部分中声明了一个名为FileSize
的函数,例如
function FileSize(const f : WideString):integer;
begin
//
end;
要解决此问题,请在函数名称之前添加函数的单元名称(在本例中为System
)以显式调用FileSize
函数。
SetLength(Items, System.FileSize(F));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.