Delphi – E2024 Invalid function result type

The use of file types as function result types is not permitted in Delphi.

program Produce;

function OpenFile(Name: string): File;
begin
end;

begin
end.

A file cannot be returned from a function.

program Solve;

procedure OpenFile(Name: string; var F: File);
begin
end;

begin
end.

The file can be ‘returned’ as a variable parameter. You can allocate a file dynamically and return a pointer to it as an alternative.