Hello,
I use TMS Scripter since a long time it's work like a charm.
I use single script *.psc (without Unit2.sfm) stored in a single table of a database so I only use on TatPascalScripter.
But now I would like to add visual design at run time (so with projet, unit + form etc.) using an TIDEScripter to allows my end users to design visual interfaces.
I have read "TMS Scripter Manual.pdf" and search sample every where.
There is a sample to load and execute a single unit "ShowIDEWithSimpleUnit;"
But how to load and execute a full project by code using ?
- Project *.ssprog
- Multiple Unit *.psc with them form *.sfm
What can really help me to load and execute a full projet (multi unit / form) where unit and form are stored in Tmemo (not from file).
The other problem it is that my TatPascalScripter handle more then one script at same time and it's work fine. I use TatPascalScripter.Scripts.Items[indexOfMyScript] so how to do the same with an TIDEEngine ?
I have 40 libraries and a lot of method (Tatpascalscripter.systemLibray.defineMethod) /object imported with Import Tool...
Best regards,
Fabrice
Hello Fabrice,
Hello Wagner,
But I don't know how to load more one unit + dfm in a TatPascalScripter.
I only know how to load a single script without dfm like this :
IDEScripter1.Scripts[IndexSimpleScript].SourceCode.assign(MemoSimpleScript.lines);
IDEScripter1.Scripts[IndexSimpleScript].Scripter.Execute;
How to load more than one "unit" and it's dfm ?
Best regards,
Fabrice
I have done something like that :
With :
- MemoUnit1 = A TMemo which contain my main unit (unit1.psc)
- MemoUnit2 = A TMemo which contain my unit2 (Unit2.psc)
- MemoUnitDfm2 = The DFM of my unit2 (.sfm)
- MemoUnit3 = A TMemo which contain my unit2 (Unit3.psc)
- MemoUnitDfm3 = The DFM of my unit3 (.sfm)
Where I set DFM (*.sfm) of each unit because DesignFormResource doesn't work ?
procedure TForm47.loadScript;
var
AUnit1,AUnit1Form,Aunit2,AUnit2Form,Aunit3,AUnit3Form: TIDEProjectFile;
begin
// IDEEngine1.Scripter :=IDEScripter1.Scripts[IndexProject1Script].Scripter;
IDEEngine1.NewProject;
IDEEngine1.Scripter:=IDEScripter1;
AUnit1 := IDEEngine1.NewUnit(slPascal);
AUnit1.Script.SourceCode.Assign(MemoUnit1.lines);
AUnit2 := IDEEngine1.NewFormUnit(slPascal);
AUnit2.Script.SourceCode.Assign(MemoUnit2.lines);
AUnit2.Script.DesignFormResource:=MemoUnitDfm2.lines.Text;
{ AUnit2Form := IDEEngine1.NewFormUnit(slPascal);
AUnit2Form.Script.SourceCode.Assign(MemoUnitDfm2.lines);
}
//AUnit2Form.IsForm:=true;
AUnit3 := IDEEngine1.NewFormUnit(slPascal);
AUnit3.Script.SourceCode.Assign(MemoUnit3.lines);
AUnit3.Script.DesignFormResource:=MemoUnitDfm3.lines.Text;
{
AUnit3Form := IDEEngine1.NewFormUnit(slPascal);
// AUnit3Form.IsForm:=true;
AUnit3Form.Script.SourceCode.Assign(MemoUnitDfm3.lines);
}
end;
I can send you my full project.
My full project :
Unit47.pas
unit Unit47;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IDEDialog, atScript, atScripter, IDEMain;
type
TForm47 = class(TForm)
IDEEngine1: TIDEEngine;
IDEScripter1: TIDEScripter;
MemoUnit1: TMemo;
MemoUnit2: TMemo;
MemoUnitDfm2: TMemo;
MemoUnit3: TMemo;
MemoUnitDfm3: TMemo;
IDEDialog1: TIDEDialog;
b_execute: TButton;
b_design: TButton;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
MemoSimpleScript: TMemo;
Button1: TButton;
procedure b_designClick(Sender: TObject);
procedure b_executeClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Déclarations privées }
IndexSimpleScript,IndexProject1Script:integer;
public
{ Déclarations publiques }
procedure loadScript;
end;
var
Form47: TForm47;
implementation
uses
ap_classes,ap_graphics,ap_controls,ap_forms,ap_dialogs,ap_StdCtrls,ap_ExtCtrls,ap_buttons;
{$R *.dfm}
procedure TForm47.Button1Click(Sender: TObject);
begin
IDEScripter1.Scripts[IndexSimpleScript].SourceCode.assign(MemoSimpleScript.lines);
//IDEScripter1.Scripts[0].Scripter.Execute;
IDEScripter1.Scripts[IndexSimpleScript].Scripter.ExecuteSubroutine('Example');
end;
procedure TForm47.b_designClick(Sender: TObject);
begin
LoadScript;
IDEDialog1.Execute;
end;
procedure TForm47.b_executeClick(Sender: TObject);
begin
LoadScript;
IDEScripter1.Execute;
end;
procedure TForm47.FormShow(Sender: TObject);
begin
IndexSimpleScript:=IDEScripter1.AddScript(slPascal).Index-1;
IndexProject1Script:=IDEScripter1.AddScript(slPascal).Index-1;
end;
procedure TForm47.loadScript;
var
AUnit1,AUnit1Form,Aunit2,AUnit2Form,Aunit3,AUnit3Form: TIDEProjectFile;
begin
// IDEEngine1.Scripter :=IDEScripter1.Scripts[IndexProject1Script].Scripter;
IDEEngine1.NewProject;
IDEEngine1.Scripter:=IDEScripter1;
AUnit1 := IDEEngine1.NewUnit(slPascal);
AUnit1.Script.SourceCode.Assign(MemoUnit1.lines);
AUnit2 := IDEEngine1.NewFormUnit(slPascal);
AUnit2.Script.SourceCode.Assign(MemoUnit2.lines);
AUnit2.Script.DesignFormResource:=MemoUnitDfm2.lines.Text;
{ AUnit2Form := IDEEngine1.NewFormUnit(slPascal);
AUnit2Form.Script.SourceCode.Assign(MemoUnitDfm2.lines);
}
//AUnit2Form.IsForm:=true;
AUnit3 := IDEEngine1.NewFormUnit(slPascal);
AUnit3.Script.SourceCode.Assign(MemoUnit3.lines);
AUnit3.Script.DesignFormResource:=MemoUnitDfm3.lines.Text;
IDEEngine1.MainUnit:= AUnit1;
{
AUnit3Form := IDEEngine1.NewFormUnit(slPascal);
// AUnit3Form.IsForm:=true;
AUnit3Form.Script.SourceCode.Assign(MemoUnitDfm3.lines);
}
end;
end.
Unit47.dfm
object Form47: TForm47
Left = 309
Top = 220
Caption = 'Form47'
ClientHeight = 553
ClientWidth = 1015
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object b_execute: TButton
Left = 608
Top = 224
Width = 75
Height = 25
Caption = 'Execute'
TabOrder = 0
OnClick = b_executeClick
end
object b_design: TButton
Left = 608
Top = 264
Width = 75
Height = 25
Caption = 'Design'
TabOrder = 1
OnClick = b_designClick
end
object GroupBox1: TGroupBox
Left = 136
Top = 8
Width = 457
Height = 522
Caption = 'Project 1'
TabOrder = 2
object MemoUnit1: TMemo
Left = 32
Top = 18
Width = 185
Height = 145
Lines.Strings = (
'uses'
' Classes, Graphics, Controls, '
'Forms, Dialogs, Unit2;'
''
'var'
' MainForm: TForm2;'
'begin'
' MainForm := TForm2.Create'
'(Application);'
' MainForm.Show;'
'end;')
TabOrder = 0
end
object MemoUnit2: TMemo
Left = 32
Top = 169
Width = 185
Height = 162
Lines.Strings = (
'{$FORM TForm2, Unit2.sfm} '
' '
''
'uses'
' Classes, Graphics, Controls, '
'Forms, Dialogs, StdCtrls,unit3;'
''
'procedure Button1Click(Sender: '
'TObject); '
'var'
' AForm3:Tform3; '
' ModalResult:integer;'
'begin'
' AForm3:=Tform3.create(self);'
' try '
' '
'ModalResult:=AForm3.showmodal; '
' if ModalResult=Mrok then'
' showmessage('#39'You click on ok '
'and select :'#39'+#13#10+ '
'AForm3.memo1.lines.text)'
' else showmessage('#39'You click on '
'cancel'#39') '
' finally '
' AForm3.free;'
' end;'
' '
'end;'
''
'begin'
'end;')
TabOrder = 1
end
object MemoUnit3: TMemo
Left = 32
Top = 337
Width = 185
Height = 161
Lines.Strings = (
'{$FORM TForm3, Unit3.sfm} '
''
'uses'
' Classes, Graphics, Controls, '
'Forms, Dialogs, StdCtrls, '
' Buttons, ExtCtrls; '
' '
'var'
' AtextResult:string;'
''
'procedure Button1Click(Sender: '
'TObject);'
'begin'
' AtextResult:=Memo1.Lines.text;'
'end; '
''
'procedure Button2Click(Sender: '
'TObject);'
'begin'
' AtextResult:='#39#39';'
'end;'
''
'begin'
'end;')
TabOrder = 2
end
object MemoUnitDfm2: TMemo
Left = 232
Top = 169
Width = 185
Height = 162
Lines.Strings = (
'object Form2: TScriptForm'
' Caption = '#39'Form2'#39
' ClientHeight = 201'
' ClientWidth = 304'
' Color = clBtnFace'
' Font.Charset = '
'DEFAULT_CHARSET'
' Font.Color = clWindowText'
' Font.Height = -11'
' Font.Name = '#39'Tahoma'#39
' Font.Style = []'
' OldCreateOrder = False'
' Position = poDesigned'
' SaveProps.Strings = ('
' '#39'Visible=False'#39')'
' SaveEvents.Strings = ('
' '#39'Button1.OnClick=Button1Click'#39')'
' PixelsPerInch = 96'
' TextHeight = 13'
' object Button1: TButton'
' Left = 80'
' Top = 88'
' Width = 145'
' Height = 25'
' Caption = '#39'Show dialog box'#39
' TabOrder = 0'
' end'
'end')
TabOrder = 3
end
object MemoUnitDfm3: TMemo
Left = 232
Top = 337
Width = 185
Height = 161
Lines.Strings = (
'object Form3: TScriptForm'
' Caption = '#39'Form3'#39
' ClientHeight = 201'
' ClientWidth = 304'
' Color = clBtnFace'
' Font.Charset = '
'DEFAULT_CHARSET'
' Font.Color = clWindowText'
' Font.Height = -11'
' Font.Name = '#39'Tahoma'#39
' Font.Style = []'
' OldCreateOrder = False'
' Position = poDesigned'
' SaveProps.Strings = ('
' '#39'Visible=False'#39')'
' SaveEvents.Strings = ('
' '#39'Button1.OnClick=Button1Click'#39
' '#39'Button2.OnClick=Button2Click'#39')'
' PixelsPerInch = 96'
' TextHeight = 13'
' object Memo1: TMemo'
' Left = 48'
' Top = 24'
' Width = 185'
' Height = 89'
' Lines.Strings = ('
' '#39'Memo1'#39')'
' TabOrder = 0'
' end'
' object Button1: TButton'
' Left = 32'
' Top = 152'
' Width = 75'
' Height = 25'
' Caption = '#39'Ok'#39
' ModalResult = 1'
' TabOrder = 1'
' end'
' object Button2: TButton'
' Left = 184'
' Top = 152'
' Width = 75'
' Height = 25'
' Caption = '#39'Cancel'#39
' ModalResult = 2'
' TabOrder = 2'
' end'
'end')
TabOrder = 4
end
end
object GroupBox2: TGroupBox
Left = 634
Top = 8
Width = 343
Height = 129
Caption = 'Project 2'
TabOrder = 3
object MemoSimpleScript: TMemo
Left = 24
Top = 18
Width = 185
Height = 89
Lines.Strings = (
'procedure example;'
'begin'
' showmessage('#39'ok from procedure '
'example'#39');'
'end;'
''
'begin'
'showmessage('#39'ok'#39');'
'end;'
'')
TabOrder = 0
end
end
object Button1: TButton
Left = 704
Top = 146
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 4
OnClick = Button1Click
end
object IDEEngine1: TIDEEngine
Options.AutoHideTabControl = True
FileExtPascalUnit = '.psc'
FileExtForm = '.sfm'
FileExtBasicUnit = '.bsc'
AutoStyler = True
Left = 88
Top = 144
end
object IDEScripter1: TIDEScripter
DefaultLanguage = slPascal
SaveCompiledCode = False
ShortBooleanEval = True
LibOptions.SearchPath.Strings = (
'$(CURDIR)'
'$(APPDIR)')
LibOptions.UseScriptFiles = False
CallExecHookEvent = False
Left = 88
Top = 192
end
object IDEDialog1: TIDEDialog
Engine = IDEEngine1
Title = 'Scripter Studio Pro IDE - %s'
IDECloseAction = icaCloseAll
Left = 88
Top = 248
end
end
ok now it's work with :
procedure TForm47.loadScript;
var
AUnit1,Aunit2,Aunit3: TIDEProjectFile;
begin
IDEEngine1.NewProject;
IDEEngine1.Scripter:=TIDEScripter(IDEScripter1.Scripts[IndexProject1Script].Scripter); // Can I cast like this ?
AUnit1 := IDEEngine1.NewUnit(slPascal);
AUnit1.Script.SourceCode.Assign(MemoUnit1.lines);
AUnit2 := IDEEngine1.NewFormUnit(slPascal);
AUnit2.Script.SourceCode.Assign(MemoUnit2.lines);
AUnit2.LoadFormFromString( MemoUnitDfm2.lines.Text);
AUnit3 := IDEEngine1.NewFormUnit(slPascal);
AUnit3.Script.SourceCode.Assign(MemoUnit3.lines);
AUnit3.LoadFormFromString( MemoUnitDfm3.lines.Text);
IDEEngine1.MainUnit:= AUnit1;
end;
But does it correct to use :
IDEEngine1.Scripter:=TIDEScripter(IDEScripter1.Scripts[IndexProject1Script].Scripter);
with :
procedure TForm47.FormShow(Sender: TObject);
begin
IndexSimpleScript:=IDEScripter1.AddScript(slPascal).Index-1;
IndexProject1Script:=IDEScripter1.AddScript(slPascal).Index-1;
end;
procedure TForm47.b_designClick(Sender: TObject);
begin
LoadScript;
IDEDialog1.Execute;
end;
procedure TForm47.b_executeClick(Sender: TObject);
begin
LoadScript;
IDEEngine1.RunScript();
end;
If you have a place where data i saved, it's best you use events for loading the scripts/form from a different place than files. There is a chapter in the manual about it, basically you need to use events OnLoadFile and OnCheckValidFile (to inform is a script has a form associated or not).In this case you must provide a "fake" project file so the engine can know what files are associated with the project.
What I want is simple, I thin ;-).
I use TMSScripter in my software since 2002 (I was register to TPascalSCripter by Automa before TMS scripter).
In my software end user can click on button which execute pascal script.
All is saved to a Firebird Database. End user can edit/add/delete script.
But now I would like to add Visual Design because it's very hard to handle Form with visual component only by code.
So now in 2014 I want when my user want visual design to open you Scripter Studio Pro IDE.
But all must be saved to a database.
I don't need a external IDE because all libraries are in my software.
So I will have a button to start your Scripter Studio Pro IDE.
But I need to store all file in my database.
I would like to do like this :
procedure TForm47.b_designClick(Sender: TObject);
var
i:integer;
begin
LoadScript;
IDEEngine1.IDECloseAction:=icaNothing; // this option is nice for my case !
IDEDialog1.Execute;
// now save all to database
for I := 0 to IDEEngine1.Files.Count-1 do
begin
Memo1.Lines.Add('Unitname n°'+inttostr(i)+'='+IDEEngine1.Files.UnitName);
Memo1.Lines.Add('===============START.PAS ');
IDEEngine1.Files.Script.SourceCode.Text; <= PROBLEM nothing here
Memo1.Lines.Add('===============END.PAS'); }
Memo1.Lines.Add('===============START DFM ');
Memo1.Lines.Add(IDEEngine1.Files.FormResource ); // this work fine
Memo1.Lines.Add('===============END DFM');
end;
But how to get unit code after execute ?
If I can get it all is have to do after it to store it in my database !
Sorry Wrong copy/paste in my code sample :
procedure TForm47.b_designClick(Sender: TObject);
var
i:integer;
begin
LoadScript;
IDEEngine1.IDECloseAction:=icaNothing; // this option is nice for my case !
IDEDialog1.Execute;
for I := 0 to IDEEngine1.Files.Count-1 do
begin
Memo1.Lines.Add('Unitname n°'+inttostr(i)+'='+IDEEngine1.Files.UnitName);
Memo1.Lines.Add('===============START OF .PAS ');
IDEEngine1.Files.Script.SourceCode.Text; // <= PROBLEM nothing here How to get source code of eahc unit ?
Memo1.Lines.Add('===============END OF .PAS');
Memo1.Lines.Add('===============START OF DFM ');
Memo1.Lines.Add(IDEEngine1.Files.FormResource ); // this work fine
Memo1.Lines.Add('===============END OF DFM');
end;
end;
I thought you mentioned it's working now (4 posts above)