remobjects / pascalscript

pascalscript
Other
452 stars 183 forks source link

getting access violation error on script execute time. #248

Open relativ opened 3 years ago

relativ commented 3 years ago

hello,

i am getting acces violation error on script execute time . compiling is normal but when i calling execute method , it make access violation error.

Program IFSTest;

    procedure OnStatus (ASender: TObject;  const AStatusText: string);
    begin
        //Memo1.Lines.Add(AStatusText);
    end;

var
    ftp: TFTP;
    sStatus: TStringList;
    i: integer;

Begin
    ftp:= TFTP.Create();
    ftp.OnStatus := @OnStatus;
    ftp.Host := '94.73.148.47';
    ftp.Port:=21;
    ftp.Username := 'root';
    ftp.Password := 'test';
    ftp.Connect;
    ftp.Login;
    ftp.List;

    for i:= 0 to ftp.ListResult.Count -1 do
    begin
        Memo1.Lines.Add(ftp.ListResult[i]);
    end;

    ftp.Disconnect;
    ftp.free;

End.
pult commented 3 years ago

? failed event wrapper for OnStatus ? read this: https://github.com/remobjects/pascalscript/issues/230

relativ commented 3 years ago

yes and ichecked out code everything normal as #230

relativ commented 3 years ago

i don't understand solving with reading #230 can you explain ?

pult commented 3 years ago

There is not enough information in your question to answer. No wrapper code showed for "TFTP.OnStatus".

relativ commented 3 years ago

wrapper code; i cut just some where for you . actually i implement with imp.exe in pascalscipt.

thanks

procedure RIRegister_Socket(CL: TPSRuntimeClassImporter);
begin
  RIRegister_TSocketIOHandler(CL);
  RIRegister_TTCPClient(CL);
  RIRegister_TUDPClient(CL);
  RIRegister_THttpClient(CL);
  RIRegister_TEmail(CL);
  RIRegister_TFTP(CL);
end;
procedure SIRegister_Socket(CL: TPSPascalCompiler);
begin
  SIRegister_TSocketIOHandler(CL);
  SIRegister_TTCPClient(CL);
  SIRegister_TUDPClient(CL);
  SIRegister_THttpClient(CL);
  SIRegister_TEmail(CL);
  CL.AddTypeS('TOnStatusEvent', 'Procedure ( ASender : TObject; AStatusText : string)');
  SIRegister_TFTP(CL);
end;
pult commented 3 years ago

This is not enough. It is unclear whether all the necessary wrappers have been created. Wrappers are conveniently done using the "unit-importing/imp.dpr" tool. Need to see type declarations, method signatures, and some implementations:

procedure TFTP_OnStatus_R(Self: TFTP; var T: TOnStatusEvent); begin T := Self.OnStatus; end;

relativ commented 3 years ago
procedure RIRegister_TFTP(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TFTP) do
  begin
    RegisterConstructor(@TFTP.Create, 'Create');
    RegisterMethod(@TFTP.Abort, 'Abort');
    RegisterMethod(@TFTP.ChangeDir, 'ChangeDir');
    RegisterMethod(@TFTP.ChangeDirUp, 'ChangeDirUp');
    RegisterMethod(@TFTP.Connect, 'Connect');
    RegisterMethod(@TFTP.Delete, 'Delete');
    RegisterMethod(@TFTP.Get, 'Get');
    RegisterMethod(@TFTP.List, 'List');
    RegisterMethod(@TFTP.Login, 'Login');
    RegisterMethod(@TFTP.MakeDir, 'MakeDir');
    RegisterMethod(@TFTP.Put, 'Put');
    RegisterMethod(@TFTP.PutStream, 'PutStream');
    RegisterMethod(@TFTP.RemoveDir, 'RemoveDir');
    RegisterMethod(@TFTP.Rename, 'Rename');
    RegisterMethod(@TFTP.Status, 'Status');
    RegisterMethod(@TFTP.Connected, 'Connected');
    RegisterMethod(@TFTP.Disconnect, 'Disconnect');
    RegisterMethod(@TFTP.Size, 'Size');
    RegisterPropertyHelper(@TFTPHost_R,@TFTPHost_W,'Host');
    RegisterPropertyHelper(@TFTPPassive_R,@TFTPPassive_W,'Passive');
    RegisterPropertyHelper(@TFTPPassword_R,@TFTPPassword_W,'Password');
    RegisterPropertyHelper(@TFTPUsername_R,@TFTPUsername_W,'Username');
    RegisterPropertyHelper(@TFTPPort_R,@TFTPPort_W,'Port');
    RegisterPropertyHelper(@TFTPListResult_R,nil,'ListResult');
    RegisterPropertyHelper(@TFTPOnStatus_R,@TFTPOnStatus_W,'OnStatus');
  end;
end;
(* === run-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure TFTPOnStatus_W(Self: TFTP; const T: TOnStatusEvent);
begin Self.OnStatus := T; end;

(*----------------------------------------------------------------------------*)
procedure TFTPOnStatus_R(Self: TFTP; var T: TOnStatusEvent);
begin T := Self.OnStatus; end;

(*----------------------------------------------------------------------------*)
procedure TFTPListResult_R(Self: TFTP; var T: TStrings);
begin T := Self.ListResult; end;

(*----------------------------------------------------------------------------*)
procedure TFTPPort_W(Self: TFTP; const T: integer);
begin Self.Port := T; end;

(*----------------------------------------------------------------------------*)
procedure TFTPPort_R(Self: TFTP; var T: integer);
begin T := Self.Port; end;

(*----------------------------------------------------------------------------*)
procedure TFTPUsername_W(Self: TFTP; const T: string);
begin Self.Username := T; end;

(*----------------------------------------------------------------------------*)
procedure TFTPUsername_R(Self: TFTP; var T: string);
begin T := Self.Username; end;

(*----------------------------------------------------------------------------*)
procedure TFTPPassword_W(Self: TFTP; const T: string);
begin Self.Password := T; end;

(*----------------------------------------------------------------------------*)
procedure TFTPPassword_R(Self: TFTP; var T: string);
begin T := Self.Password; end;

(*----------------------------------------------------------------------------*)
procedure TFTPPassive_W(Self: TFTP; const T: boolean);
begin Self.Passive := T; end;

(*----------------------------------------------------------------------------*)
procedure TFTPPassive_R(Self: TFTP; var T: boolean);
begin T := Self.Passive; end;

(*----------------------------------------------------------------------------*)
procedure TFTPHost_W(Self: TFTP; const T: string);
begin Self.Host := T; end;

(*----------------------------------------------------------------------------*)
procedure TFTPHost_R(Self: TFTP; var T: string);
begin T := Self.Host; end;
procedure SIRegister_TFTP(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'TFTP') do
  with CL.AddClassN(CL.FindClass('TObject'),'TFTP') do
  begin
    RegisterMethod('Constructor Create');
    RegisterMethod('Procedure Abort');
    RegisterMethod('Procedure ChangeDir( ADirname : string)');
    RegisterMethod('Procedure ChangeDirUp');
    RegisterMethod('Procedure Connect');
    RegisterMethod('Procedure Delete( AFilename : string)');
    RegisterMethod('Procedure Get( Afilename : string; ADest : TStream)');
    RegisterMethod('Procedure List');
    RegisterMethod('Procedure Login');
    RegisterMethod('Procedure MakeDir( ADirname : string)');
    RegisterMethod('Procedure Put( AsourceFile : string; ADestFile : string)');
    RegisterMethod('Procedure PutStream( ASource : TStream; ADeestFile : string)');
    RegisterMethod('Procedure RemoveDir( ADirname : string)');
    RegisterMethod('Procedure Rename( AsourceFile : string; AdestFile : string)');
    RegisterMethod('Procedure Status( AStatus : TStrings)');
    RegisterMethod('Function Connected : boolean');
    RegisterMethod('Procedure Disconnect');
    RegisterMethod('Function Size( AFilename : string) : integer');
    RegisterProperty('Host', 'string', iptrw);
    RegisterProperty('Passive', 'boolean', iptrw);
    RegisterProperty('Password', 'string', iptrw);
    RegisterProperty('Username', 'string', iptrw);
    RegisterProperty('Port', 'integer', iptrw);
    RegisterProperty('ListResult', 'TStrings', iptr);
    RegisterProperty('OnStatus', 'TOnStatusEvent', iptrw);
  end;
end;
pult commented 3 years ago

Signature not shown for TOnStatusEvent.

There is a signature mismatch in your examples (see const AStatusText):

declaration:

CL.AddTypeS('TOnStatusEvent', 'Procedure ( ASender : TObject; AStatusText : string)');

script:

procedure OnStatus (ASender: TObject;  const AStatusText: string);
begin
//Memo1.Lines.Add(AStatusText);
end;

Rarely: Also there may be a mismatch between the "string" type of the compiler and the rps-engine.

relativ commented 3 years ago

Still did not work and what is rps ?

pult commented 3 years ago

rps - remobject pascal script

relativ commented 3 years ago

@carlokok help Carlo we haven't solve problem .

pult commented 3 years ago

Try to make an example so that we can see all your code.

relativ commented 3 years ago

example : extension link

pult commented 3 years ago

Your code fragments:

ClientSockets.dpr
library ClientSockets;
exports PSPluginCreate;

uPSI_Socket.pas
function PSPluginCreate(): TPSPlugin; stdcall;
var
  Import: TPSImport_Socket;
begin
  Import:= TPSImport_Socket.Create(nil);
  Result := Import;
end;

TPSImport_Socket = class(TPSPlugin)

A class cannot be passed to a DLL as a parameter and an ordinary string (instead of string, you need WideString or Variant). In Package (BPL instead DLL) you can, but EXE and BPL must be compiled in the same Delphi version.

relativ commented 3 years ago

No not i guess old version of delphi cannot passed a class to a dll but this is working good.

pult commented 3 years ago

In some particular case, this may work, but in the general case it is not true: it will fail/AV or there will be memory leaks ...

relativ commented 3 years ago

is there any progress about problem ?

pult commented 3 years ago

rps not have problebs. problem is in your code...