unit GLSI_DataModule;
interface
uses
SysUtils, Classes, JvComponent, JvInterpreter_all, JvInterpreter;
type
TInterpreterhread =
class(TThread)
protected
procedure Execute;
override;
private
PSender: TObject;
PIdentifier:
String;
PValue: Variant;
PArgs: TJvInterpreterArgs;
PDone: Boolean;
public
Interpreter: TJvInterpreterProgram;
procedure InterpreterGetValue(Sender: TObject; Identifier:
String;
var Value: Variant; Args: TJvInterpreterArgs;
var Done: Boolean);
procedure SyncGetValue();
destructor Destroy;
override;
end;
type
TGLSInterpreterModule =
class(TDataModule)
Interpreter: TJvInterpreterProgram;
procedure InterpreterGetUnitSource(UnitName:
String;
var Source:
String;
var Done: Boolean);
procedure InterpreterGetValue(Sender: TObject; Identifier:
String;
var Value: Variant; Args: TJvInterpreterArgs;
var Done: Boolean);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Thread: TInterpreterhread;
Lines: TStringList;
procedure CompileCode;
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
end;
var
GLSInterpreterModule: TGLSInterpreterModule;
implementation
{$R *.dfm}
{ TInterpreterhread }
procedure TInterpreterhread.Execute;
begin
Interpreter.Compile;
Interpreter.CallFunction('
main',
nil, []);
end;
{ TGLSInterpreterModule }
procedure TGLSInterpreterModule.CompileCode;
begin
Thread:= TInterpreterhread.Create(True);
Thread.Interpreter:= TJvInterpreterProgram.Create(
nil);
Thread.Interpreter.Pas.Clear;
Thread.Interpreter.Pas.AddStrings(Lines);
Thread.Interpreter.OnGetValue := Thread.InterpreterGetValue;
Thread.Execute;
end;
procedure TInterpreterhread.InterpreterGetValue(Sender: TObject;
Identifier:
String;
var Value: Variant; Args: TJvInterpreterArgs;
var Done: Boolean);
begin
if (AnsiSameText(Identifier, '
delay'))
or
(AnsiSameText(Identifier, '
sleep'))
then
begin
sleep(Args.Values[0]);
Done := true;
exit;
end else begin
PSender := Sender;
PIdentifier := Identifier;
PValue := Value;
PArgs := Args;
PDone := Done;
Synchronize(SyncGetValue);
Done := PDone;
Value := PValue;
end;
end;
procedure TInterpreterhread.SyncGetValue();
begin
GLSInterpreterModule.InterpreterGetValue(
PSender, PIdentifier, PValue, PArgs, PDone);
end;
procedure TGLSInterpreterModule.InterpreterGetValue(Sender: TObject;
Identifier:
String;
var Value: Variant; Args: TJvInterpreterArgs;
var Done: Boolean);
begin
//
end;