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

How to run Event in PascalScript? #230

Closed
luizluvizutto opened this issue May 22, 2020 · 14 comments
Closed

How to run Event in PascalScript? #230

luizluvizutto opened this issue May 22, 2020 · 14 comments

Comments

@luizluvizutto
Copy link

Hello friends!
I'm having difficulty running an event in PascalScript.
In this example, I have a "type" and a "class".

TEvento = procedure( txt: String );

TClassEvento = class( TComponent )
private
   FEvento: TEvento;
public
   property Evento: TEvento read FEvento write FEvento;
   procedure Executar;
end;

procedure ABC( msg: String );

implementation

procedure ABC( msg: String );
begin
   ShowMessage( msg ); 
end;

{ TClassEvento }

procedure TClassEvento.Executar;
begin
   if Assigned(FEvento) then begin
      FEvento( 'Olá Mundo' );
   end;
end;

procedure test;
var O: TClassEvento; 
begin
   O := TClassEvento.Create(NIL);
   try
      O.Evento := ABC;
      O.Executar;
   finally
      O.Free;
   end;
end;

With TEvento and TClassEvento registered in Pascal Script, as shown below:

procedure ABC( txt: String );
begin
   ShowMessage('Estou no Script: ' + txt);
end;

var O: TClassEvento; 
begin
   O := TClassEvento.Create(NIL);
   try
      O.Evento := @ABC;
      O.Executar;
   finally
      O.Free;
   end;
end.

Comments:
I saw in some grammars that you need to add the "@" O.Evento: = @ABC; when using PascalScript and does not work.
When I try to run without the "@" I get the return: [Error] (10:22): Invalid number of parameters

The link contains the example I set up.

Sorry for my English, I'm from Brazil and my sincere thanks.

@pult
Copy link

pult commented May 23, 2020

? of object ?
TEvento = procedure( txt: String ) of object;

...
procedure SIRegister_TClassEvento(CL: TPSPascalCompiler);
begin
  CL.AddTypeS('TEvento', 'procedure( txt: String )');
  with CL.AddClassN(CL.FindClass('TComponent'),'TClassEvento') do
  begin
    RegisterProperty('Evento', 'TEvento', iptrw);
...

@luizluvizutto
Copy link
Author

I made the change and the same problem.

@pult
Copy link

pult commented May 25, 2020

I have no problems. Not enough information to analyze. Need a complete example, IDE version...

@luizluvizutto
Copy link
Author

Hello, I'm using Delphi 10.3 Community Edition
Follow the link of the example I set up: https://github.com/luizluvizutto/TstPascalScript

@pult
Copy link

pult commented May 26, 2020

Working fine when correct your code:

Un_Evento.pas
TEvento = procedure( txt: String ) of object; // changed declaration to method

Un_Principal.pas

TFrmPrincipal = class(TForm)
    ...
    procedure ProcedureDoEvento( txt: String ); // move to method
  end;
.,.
procedure TFrmPrincipal.ProcedureDoEvento( txt: String ); // implement as method
..

@luizluvizutto
Copy link
Author

My problem is in the Script.

Perhaps I am not able to explain my problem correctly, because my English is weak.

When I run "Run script"
nothing happens.

In this link I uploaded an exe of this example. If you click on "Run Script" the ABC method is not triggered.
https://www.dropbox.com/sh/840au9t57xinvgs/AADxE1yfrlrx8aULBl_RVBtSa?dl=0

@pult
Copy link

pult commented Jun 3, 2020

Detailed:
https://github.com/pult/TstPascalScript/commit/54838fd0c00896018f054d02e5e48e57aa74f649

@luizluvizutto
Copy link
Author

@pult thanks for the concern brother.

I cloned your sources and tested it. Did not work. Clicking the "Executar Script" button nothing happens.

Send me your compiled executable for testing.

@pult
Copy link

pult commented Jun 4, 2020

binary (xe3, dx10.3, dx10.4 x86, x64 ) and full sources with thirdparty...
TstPascalScript-pult-full_v2020.0605.0217.7z

@luizluvizutto
Copy link
Author

luizluvizutto commented Jun 5, 2020

Hello friend, it looks like I'm getting close to the solution!

Your executables worked!

I replaced the "rps" fonts in my source "... \ pascalscript \ Source" and recompiled my system and it worked!

Now my question was, what is different about your sources that you don't have in the main repository?

Or rather, what are the sources with the thirdparty? I think my problem is there.

And again, thanks for the help!

@pult
Copy link

pult commented Jun 5, 2020

@luizluvizutto
Copy link
Author

Hello Friend!
Well, first I want to congratulate you on the fork of remobjects and, above all, to make something that I think is very important for Script work.
Only I had some doubts. I even apologize for meddling.
Wouldn't these adjustments make it legal for RemObjects to implement their sources?

@pult
Copy link

pult commented Jun 10, 2020

No.
The standard(lelag) version RemObj should also work fine. Problems are possible in the latest versions of Delphi and the incomplete implementation of "InvokeCall.inc". I'm just disabling its use.

@relativ
Copy link

relativ commented May 26, 2021

hi,

how you solve the problem ? i had same problem , can describe it ? i don't understand from the reading.

thanks

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

3 participants