Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting access violation error on script execute time. #248

Open
relativ opened this issue May 21, 2021 · 18 comments
Open

getting access violation error on script execute time. #248

relativ opened this issue May 21, 2021 · 18 comments

Comments

@relativ
Copy link

relativ commented May 21, 2021

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.
@relativ relativ changed the title getting access violation error in script execute. getting access violation error on script execute time. May 21, 2021
@pult
Copy link

pult commented May 25, 2021

? failed event wrapper for OnStatus ?
read this: #230

@relativ
Copy link
Author

relativ commented May 25, 2021

yes and ichecked out code everything normal as #230

@relativ
Copy link
Author

relativ commented May 29, 2021

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

@pult
Copy link

pult commented May 29, 2021

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

@relativ
Copy link
Author

relativ commented May 29, 2021

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
Copy link

pult commented May 29, 2021

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:

  • need to see:
procedure SIRegister_TFTP(CL: TPSPascalCompiler);
  for property TFTP.OnStatus

  with CL.AddClassN(CL.FindClass('TFTP'),'TComponent') do
    RegisterProperty('OnStatus', 'TOnStatusEvent', iptrw);
  • need to see:
procedure RIRegister_TFTP(CL: TPSRuntimeClassImporter);

  with CL.Add(TFTP) do
    RegisterPropertyHelper(@TFTP_OnStatus_R,@TFTP_OnStatus_W,'OnStatus');
  • need to see:
procedure TFTP_OnStatus_W(Self: TFTP; const T: TOnStatusEvent);
begin Self.OnStatus := T; end;

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

@relativ
Copy link
Author

relativ commented May 30, 2021

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
Copy link

pult commented May 30, 2021

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
Copy link
Author

relativ commented Jun 2, 2021

Still did not work and what is rps ?

@pult
Copy link

pult commented Jun 2, 2021

rps - remobject pascal script

@relativ
Copy link
Author

relativ commented Jun 3, 2021

@carlokok help Carlo we haven't solve problem .

@pult
Copy link

pult commented Jun 3, 2021

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

@relativ
Copy link
Author

relativ commented Jun 3, 2021

example : extension link

@pult
Copy link

pult commented Jun 3, 2021

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
Copy link
Author

relativ commented Jun 3, 2021

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

@pult
Copy link

pult commented Jun 3, 2021

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
Copy link
Author

relativ commented Jun 3, 2021

is there any progress about problem ?

@pult
Copy link

pult commented Jun 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants