You are not logged in.
Pages: 1
Hello
I'm trying to use TSMEngineManager as an engine to run a JavaScript in Delphi application.
It works fine but I want to put it inside a closed DLL module and run it with a JavaScript as an method argument. But I have encountered a problem. When I create an instance of TSMEngineManager inside a DLL method and free it, then my application crashes after about 5 seconds after the FreeLibrary().
I have reduced my test application to the absolute minimum and it still crashes everytime. Now it doesn't do anything beside creating and freeing the TSMEngineManager. When I remove the creation of TSMEngineManager, it doesn't crash.
Am I doing something wrong?
Delphi version used: XE 10.1 Berlin
Tested on the newest mORMot from here https://github.com/synopse/mORMot (master).
DLL files needed to run the project: libnspr4.dll and mozjs-24.dll (I have both from 2017 - are they the most recent ones?).
Maybe I use wrong version of mozjs-24.dll? I know it's pretty old SM implementation but I'm not sure how to use SM45 or SM52 and where to find new DLLs for it.
Here's the example. It has 2 DPR files only:
---------------------------------------------------------------
DLL file
---------------------------------------------------------------
library JavaScriptRunnerLib;
uses
SynSM,
SynCommons;
{$R *.res}
procedure RunMethodTest(); stdcall;
var
SMEngineManager: TSMEngineManager;
begin
SMEngineManager := TSMEngineManager.Create;
// SMEngineManager.ReleaseCurrentThreadEngine; // < it doesn't help at all
SMEngineManager.Free;
end;
exports
RunMethodTest;
begin
end.
---------------------------------------------------------------
Host application
---------------------------------------------------------------
program JavaScriptRunnerExample;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Winapi.Windows,
System.SysUtils;
type
TRunMethodTestProc = procedure (); stdcall;
const
ScriptRunnerLibFileName = 'JavaScriptRunnerLib.dll';
function LoadScriptRunnerLibrary: THandle;
begin
result := LoadLibrary(ScriptRunnerLibFileName);
// result := SafeLoadLibrary(ScriptRunnerLibFileName, SEM_FAILCRITICALERRORS); // < it doesn't help
if result = 0 then
raise exception.CreateFmt('Error loading library %s', [ScriptRunnerLibFileName]);
end;
procedure Test2;
var
LibHandle: THandle;
RunMethodTestProc: TRunMethodTestProc;
begin
LibHandle := LoadScriptRunnerLibrary;
try
RunMethodTestProc := GetProcAddress(LibHandle, 'RunMethodTest');
RunMethodTestProc();
finally
FreeLibrary(LibHandle); // < after this command the application will crash within about 5 seconds
// If I don't use the FreeLibrary() it won't crash but I need to it
end;
end;
begin
ReportMemoryLeaksOnShutdown := true;
try
writeln('start');
Test2;
writeln('sleep');
sleep(5000);
writeln('after sleep - press enter');
//probably it will crash before this line
Readln;
writeln('ok');
except
on E: exception do
begin
writeln(E.ClassName, ': ', E.Message);
readln;
end;
end;
end.
Thank you for any help.
I can see that. Is there any chance that feature will be made in a near future? I think it shouldn't be very hard to made because I didn't change much and it partially works. But I'm not sure if I can finish it alone.
Hello
I tried to use SQLite3i18n.pas in a simple Firemonkey application but it looks like it doesn't support FMX. I made a few changes in SQLite3i18n and it compiled. But still not everything works now.
The project compiled with EXTRACTALLRESOURCES extracted some resourcestrings and a few properties (TForm.Caption, TMemo.Lines.Text) but it hasn't extracted all captions from FMX controls (i.e. TButton.Text). Probably some more changes are needed to find all FMX controls and get all strings.
Now, the procedure i18nAddLanguageCombo works fine and I can change the language but when I change it, not all strings are translated.
Did anyone try it before me and succeded?
I can share my changed version of mORMoti18n.pas to show my changes for FMX.
Pages: 1