Forum > Linux

How to show TForm from Qt by calling it from BESEN scripting?

(1/2) > >>

AFFRIZA 亜風実:
I have a boring project to call Form with script, here's I am using BESEN to do that. But, I have a trouble to run that on Linux, in Windows just fine.

So, here's the code for Windows:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,  ComCtrls, SynEdit, SynHighlighterJScript, Besen, BESENValue, BESENObject,  BESENErrors, BESENObjectPrototype, BESENNativeObject, BESENConstants, template_form; type  { TForm1 }   TForm1 = class(TForm)    btnExec: TButton;    codeEditor: TSynEdit;    lbMessages: TListBox;    SynJScriptSyn1: TSynJScriptSyn;    procedure btnExecClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    myForm: TTemplateForm;    BesenInst: TBesen;  public    procedure Info(const ThisArgument:TBESENValue;Arguments:PPBESENValues;CountArguments:integer;var AResult:TBESENValue);    procedure RunScript(const Lines: String);  end procedure TForm1.btnExecClick(Sender: TObject);begin  RunScript(codeEditor.Text);end; procedure TForm1.Info(const ThisArgument: TBESENValue; Arguments: PPBESENValues;  CountArguments:integer;var AResult:TBESENValue);begin  myForm := TTemplateForm.Create(nil);  myForm.Show;end; procedure TForm1.RunScript(const Lines: String);begin   try      BesenInst.Execute(Lines);   except      on e: EBESENError do        lbMessages.Items.Add(Format('(%s) Syntax error on line %d: %s', [e.Name,          TBESEN(BesenInst).LineNumber, e.Message]));       on e: exception do        lbMessages.Items.Add(Format('(%s) Exception error on line %d: %s', ['Exception',          TBESEN(BesenInst).LineNumber, e.Message]));   end;end procedure TForm1.FormCreate(Sender: TObject);begin  BesenInst := TBesen.Create;  TBESEN(BesenInst).ObjectGlobal.RegisterNativeFunction('info', @Info, 0, []);end;  
So, when I execute "info()" in the RunScript, it will show the TTemplateForm.

Then I made this for Linux, I need to change slightly to make it work on GTK2 and GTK3 by adding Application.QueueAsyncCall.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TForm1 = class(TForm)    btnExec: TButton;    codeEditor: TSynEdit;    lbMessages: TListBox;    SynJScriptSyn1: TSynJScriptSyn;    procedure btnExecClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    myForm: TTemplateForm;    BesenInst: TBesen;  public    procedure Info(const ThisArgument:TBESENValue;Arguments:PPBESENValues;CountArguments:integer;var AResult:TBESENValue);    procedure RunScript(const Lines: String);    procedure ShowFormASync(Data: ptrInt);  end procedure TForm1.btnExecClick(Sender: TObject);begin  RunScript(codeEditor.Text);end; procedure TForm1.ShowFormASync(Data: ptrInt);begin  myForm := TTemplateForm.Create(nil);  myForm.Show;end; procedure TForm1.Info(const ThisArgument: TBESENValue; Arguments: PPBESENValues;  CountArguments:integer;var AResult:TBESENValue);begin  // I have no idea why but this is work with GTK2 and GTK3  Application.QueueAsyncCall(@ShowFormASync, 0);  end; procedure TForm1.RunScript(const Lines: String);begin   try      BesenInst.Execute(Lines);   except      on e: EBESENError do        lbMessages.Items.Add(Format('(%s) Syntax error on line %d: %s', [e.Name,          TBESEN(BesenInst).LineNumber, e.Message]));       on e: exception do        lbMessages.Items.Add(Format('(%s) Exception error on line %d: %s', ['Exception',          TBESEN(BesenInst).LineNumber, e.Message]));   end;end procedure TForm1.FormCreate(Sender: TObject);begin  BesenInst := TBesen.Create;  TBESEN(BesenInst).ObjectGlobal.RegisterNativeFunction('info', @Info, 0, []);end;  
But it doesn't work in Qt. I always got a Run Error message from debugger. I'll attach the picture here.

AFFRIZA 亜風実:
I just moved to KDE Neon and I found this in the Call Stack, previously it didn't show in CutefishOS:

zeljko:
Seem that QApplication does not exist ?

dbannon:

--- Quote from: Dio Affriza on May 17, 2022, 06:58:03 pm ---I just moved to KDE Neon and I found this in the Call Stack, previously it didn't show in CutefishOS:

--- End quote ---

I have had two separate users complain my app, running under Qt5 on KDE Neon has problems. Both have moved to my GTK2 version and don't want to pursue it so I intend, time permitting, to do some testing in a VM. Neon claims to be the 'newest' KDE around, that may well be the "least tested".

Davo

zeljko:
@dbannon, what problems exactly ?

Navigation

[0] Message Index

[#] Next page

Go to full version