<div dir="ltr">2013/9/16 silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">2013/9/16 Martin <span dir="ltr"><<a href="mailto:lazarus@mfriebe.de" target="_blank">lazarus@mfriebe.de</a>></span><br><div class="gmail_extra"><div class="im"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"><div>
<div><span style="color:rgb(34,34,34)">Ok, found the answer in the lpr.</span><br></div></div>
<br>
I would not expect that to work, after all you cant do it in normal
pascal either?<br>
<br>
the main begin end is a program does not belong to a class.</div></blockquote></div><div><br></div></div><div>Writeln was only by way of illustration, it could be anything else. :)<br></div><div><br></div><div>Problem solved with:</div>
<div><br></div><div><div>program project1;</div><div><br></div><div>{$mode objfpc}{$H+}</div><div><br></div><div>uses</div><div> uPSComponent, myclass, uPSI_myclass;</div><div><br></div><div>type</div><div> TApp = class</div>
<div> private</div><div> Fobj: TMyClass;</div><div> Fps: TPSScript;</div><div> public</div><div> constructor Create;</div><div> destructor Destroy; override;</div><div> procedure OnCompile(Sender: TPSScript);</div>
<div> procedure OnExecute(Sender: TPSScript);</div><div> property ps: TPSScript read Fps;</div><div> property obj: TMyClass read Fobj write Fobj;</div><div> end;</div><div><br></div><div> constructor TApp.Create;</div>
<div> begin</div><div> Fps := TPSScript.Create(nil);</div><div> Fps.OnCompile := @OnCompile;</div><div> Fps.OnExecute := @OnExecute;</div><div> end;</div><div><br></div><div> destructor TApp.Destroy;</div><div>
begin</div><div> Fps.Free;</div><div> inherited Destroy;</div><div> end;</div><div><br></div><div> procedure TApp.OnCompile(Sender: TPSScript);</div><div> begin</div><div> Sender.AddRegisteredVariable('Self', 'TMyClass');</div>
<div> end;</div><div><br></div><div> procedure TApp.OnExecute(Sender: TPSScript);</div><div> begin</div><div> Sender.SetVarToInstance('SELF', Fobj);</div><div> end;</div><div><br></div><div>var</div><div> app: TApp;</div>
<div> i: integer;</div><div> obj: TMyClass;</div><div> pl: TPSImport_myclass;</div><div>begin</div><div> app := TApp.Create;</div><div> pl := TPSImport_myclass.Create(nil);</div><div> obj := TMyClass.Create;</div><div>
try</div><div> app.obj := obj;</div><div> TPSPluginItem(app.ps.Plugins.Add).Plugin := pl;</div><div> app.ps.Script.Text := 'begin Self.WriteLn(''OK''); end.';</div><div> if app.ps.Compile then</div>
<div> app.ps.Execute;</div><div> WriteLn(obj.Data);</div><div> WriteLn('--');</div><div> for i := 0 to Pred(app.ps.Comp.MsgCount) do</div><div> WriteLn(app.ps.Comp.Msg[I].MessageToString);</div>
<div> finally</div><div> obj.Free;</div><div> pl.Free;</div><div> app.ps.Free;</div><div> end;</div><div> ReadLn;</div><div>end.</div></div><div><br></div><div>Thank you very much! (y)</div></div></div></blockquote>
</div><div><br></div><div>Or:</div><div><br></div><div><div>program project1;</div><div><br></div><div>{$mode objfpc}{$H+}</div><div><br></div><div>uses</div><div> uPSCompiler, uPSRuntime, uPSC_std, uPSR_std, myclass, uPSI_myclass;</div>
<div><br></div><div> function ScriptOnUses(Sender: TPSPascalCompiler; const Name: string): boolean;</div><div> begin</div><div> if Name = 'SYSTEM' then</div><div> begin</div><div> SIRegister_Std(Sender);</div>
<div> SIRegister_myclass(Sender);</div><div> AddImportedClassVariable(Sender, 'Self', 'TMyClass');</div><div> Result := True;</div><div> end</div><div> else</div><div> Result := False;</div>
<div> end;</div><div><br></div><div> procedure ExecuteScript(const Script: string);</div><div> var</div><div> Compiler: TPSPascalCompiler;</div><div> Exec: TPSExec;</div><div> Data: string;</div><div> CI: TPSRuntimeClassImporter;</div>
<div> obj: TMyClass;</div><div> begin</div><div> Compiler := TPSPascalCompiler.Create;</div><div> Compiler.OnUses := @ScriptOnUses;</div><div> if not Compiler.Compile(Script) then</div><div> begin</div><div>
Compiler.Free;</div><div> Exit;</div><div> end;</div><div> Compiler.GetOutput(Data);</div><div> Compiler.Free;</div><div> CI := TPSRuntimeClassImporter.Create;</div><div> RIRegister_Std(CI);</div>
<div> RIRegister_myclass(CI);</div><div> Exec := TPSExec.Create;</div><div> RegisterClassLibraryRuntime(Exec, CI);</div><div> if not Exec.LoadData(Data) then</div><div> begin</div><div> Exec.Free;</div>
<div> Exit;</div><div> end;</div><div> obj := TMyClass.Create;</div><div> SetVariantToClass(Exec.GetVarNo(Exec.GetVar('SELF')), obj);</div><div> Exec.RunScript;</div><div> WriteLn(obj.Data);</div>
<div> Exec.Free;</div><div> obj.Free;</div><div> CI.Free;</div><div> end;</div><div><br></div><div>begin</div><div> ExecuteScript('begin Self.WriteLn(''OK'') end.');</div><div> ReadLn;</div>
<div>end.</div></div><div><br></div>-- <br>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>