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:
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.
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.