I’m writing an application to log microscope usage but the following piece of code generates an error E2010 incompatible types “WideString’ and “TDataFile” at the line that reads: SetLength(Items, FileSize(F)); I have narrowed down the problem to FileSize(F), just a number instead gives no error and trying to assign i := fileSize(F); where i is an integer gives the same error.
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;
I’m using delphi 2010 on Win7 64bit. Does anyone know why this is happening? Writing a small console app just to test i := FileSize(F); works without a problem….
It seems that you have a function called
FileSizedeclared in another unit or part of your code, something liketo resolve the issue, add the unit name of the function (in this case
System) before the function name to explicitly call theFileSizefunction.