1

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....

2
  • and FileSize(F) is retuning a big value no? Commented Sep 23, 2011 at 14:29
  • 1
    What are the declarations of TTEM, TSEM, TFIB? Commented Sep 23, 2011 at 14:36

1 Answer 1

5

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));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Not sure how I missed that but yes I had another function with the same name hahahaha. Changed my functions name and everything works again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.