5

I'm trying to create a modal form with dwscript. Im registering the form with the ExposeRtti, then execute the script but it fails on a "Stack overflow" during the Script.Compile. Does anybody have a solution for this error.

I surely hope i dont have to register all the TForm properties and functions manually like we have to with remobjects PascalScript, it would we ugly in this era, like to avoid that..

Can dwscript do this, or are forms simply beyond the scope of dwscript (at this stage?)?

procedure TMainForm.Button1Click(Sender: TObject);
var AdwsProgramExecution: IdwsProgramExecution;
  ADelphiWebScript: TDelphiWebScript;
  AdwsProgram: IdwsProgram;
  AdwsUnit: TdwsUnit;
begin
  AdwsUnit := TdwsUnit.Create(nil);
  ADelphiWebScript := TDelphiWebScript.Create(nil);
  try
    AdwsUnit.UnitName := 'ShowModalTest';
    AdwsUnit.Script := ADelphiWebScript;
    AdwsUnit.ExposeRTTI(TypeInfo(TObject)); //Otherwise GetOnAlignInsertBefore error when 'compiling'
    AdwsUnit.ExposeRTTI(TypeInfo(TForm)); //Want t ocreate a form
    AdwsProgram := ADelphiWebScript.Compile('procedure TestShowModal; begin TForm.Create(nil).ShowModal; end; end.'); //Stack overflow
    if AdwsProgram.Msgs.Count = 0 then 
    begin
      AdwsProgramExecution := AdwsProgram.Execute;
      MEResult.Lines.Text := AdwsProgramExecution.Result.ToString;
    end
    else 
      MEResult.Lines.Text := AdwsProgram.Msgs.AsInfo;
  finally
    ADelphiWebScript.Free;
    AdwsUnit.Free;
  end;
end;
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
Marius
  • 51
  • 1
  • 3
  • 1
    not sure if you can use a TForm, it has properties which themselves needs to be exposed before the TForm class, why don't you simply create a more lightweight version of TForm inside a TdwsUnit's classes collection? –  May 15 '12 at 22:39
  • Is the error actually occurring during the compile, or is it during the `ExposeRTTI` call immediately before it? That seems more likely. – Mason Wheeler May 15 '12 at 23:00
  • The SO has nothing to do with the TForm. It even happens if you only do the ExposeRTTI from TObject and have an empty script. – Stefan Glienke May 16 '12 at 06:47
  • Thanks Dorin, but like i said, i would like to avoid that kind of efforts as much as possible. After the TForm i also need the whole set of VCL controls (and then ~1000 of application classes) so you can understand i'm really reluctant to go on this path, unless its absolutely unavoidable. Using extended rtti (yes, with its current limits) would solve the MEGA scripts i'm now using in pascalscript. For the record, how would you register the form? I',, still having lots of trouble finding my way in dwscript and severly hindered by the lack of documentation.. – Marius May 16 '12 at 07:14
  • @Mason: Yes it is (its also in the comments but you have to scroll lots to the right, sorry about that). If i dont register the TObject i'm getting a GetOnAlignInsertBefore error – Marius May 16 '12 at 07:15
  • @Stefan: It indeed looks dwscript has its share of problems, i'm getting a GetOnAlignInsertBefore on an empty cript (and that function is not even in the VCL or dwscript, or at least i was unable to find it there) – Marius May 16 '12 at 07:15
  • My guess after testing around a bit is that the ExposeRTTI cannot handle overridden methods correctly because if you expose TComponent for example it complains about GetNamePath. – Stefan Glienke May 16 '12 at 07:40
  • Are you using the latest svn sources (i'm on revision 1460) or the latest stable 2.2 release? (i guess the 2.2 since i'm getting completely other errors) – Marius May 16 '12 at 07:52
  • Always using latest revision. Edit: strange, seems my Delphi still had some old dcus in the cache. Now it does not complain anymore with TComponent. – Stefan Glienke May 16 '12 at 11:51
  • 2
    If you'll need ~1000 of application classes, a better route might be to go with the RTTI environment instead, it'll avoid parsing 1000's of RTTI data structures. – Eric Grange May 16 '12 at 12:22
  • 1
    @Eric; Do you have some quick pointers or example for me to get on the RTTI route? The only thing i have found sofar is a TRTTIEnvironment but me (and google) have no idea how to get it to work. – Marius May 16 '12 at 19:40

1 Answers1

0

Apparently dwscript cannot register anything properly via extended RTTI unless it are simple classes. That is not what i had in mind for a script engine, so (for now) dwscript is completely of the chart unless it can rtti register complicated stuctures. It is very promising but still has along way to go before this package is complete and usable.

For now back to pascalscript, paxcompiler or tmsscript

Marius
  • 51
  • 1
  • 3