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 FileSize
declared in another unit or part of your code, something like
function FileSize(const f : WideString):integer;
begin
//
end;
to resolve the issue, add the unit name of the function (in this case System
) before the function name to explicitly call the FileSize
function.
SetLength(Items, System.FileSize(F));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.