Using IOUtils.pas in Scripter give "EInvalidCast"

Hello,

One of the more useful Delphi library is IOUtils.pas. Because it contain a lot of multiplatform file function.
The big problem it is that it doesn't use Class but Record with method : I don't understand why !?

Bad luck Record are difficult to use with scripter. I have tried to manually add method but I have problem using you sample in another thread for TStopWatch.
But I have an "EInvalidCast" error when I try to use TDirectory.getFiles.

With this script :

Var
  MyDirectory:Tdirectory;
 // ListeFichier: array[0..255] of string;
  i:integer;
  ListeFichieText:string;
begin
 MyDirectory:= Tdirectory.create;
 try
    ListeFichier :=['','','','','','',''];
    ListeFichier:=MyDirectory.getfiles(  'C:\Users');
    
 finally
   MyDirectory.free;
 end;    

end;

See my ap_IOUtils.pas attachment ap_IOUtils.pas (6.1 KB)

Indeed I would suggest avoiding the record and just manually create a virtual class in scripter. For example:

  atClass:=Scripter.DefineClass(TObject, 'TDirectory');
  atClass.DefineMethod('GetFiles',4,tkClass,TGenericRecordWrapper,__TDirectoryGetFiles,true,3,'');

Implementation:

procedure TatIOUtilsLibrary.__TDirectoryGetFiles(AMachine: TatVirtualMachine);
var
  Resultat:TStringDynArray;
  I: Integer;
  V: Variant;
begin
   case AMachine.InputArgCount of
   1:  Resultat := TDirectory.GetFiles(AMachine.GetInputArgAsString(0));
   end;


  V := VarArrayCreate([0, Length(Resultat)], 12);
  for I := 0 to Length(Resultat) -1 do
    V[I] := Resultat[I];
  AMachine.ReturnOutputArg(V);
end;

Then your script could be as simple as this:

Var
  ListeFichier;
  I;
begin     
  ListeFichier:=TDirectory.getfiles(  'C:\Users');
  for i := 0 to Length(ListeFichier) - 1 do
    ShowMessage(ListeFichier[I]);
end;