<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="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 class="im">
<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>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><br></div>-- <br>
Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>