I am having a problem with the example from this article. The article explains how to import your own classes so they can be called from a Pascal Script. I am importing my custom class but cannot get Pascal Script to recognize the 'Create' and 'Free' functions.
My plugin:
TMyPsPlugin = class
public
procedure PrintMessage(const AMessage: String);
end;
procedure TMyPsPlugin.PrintMessage(const AMessage: String);
begin
ShowMessage(AMessage);
end;
My app:
procedure TForm1.FormCreate(Sender: TObject);
var
Plugin: TPSPlugin;
begin
Plugin := TPSImport_MyPsPlugin.Create(Self);
TPSPluginItem(ps.Plugins.Add).Plugin := Plugin;
end;
procedure TForm1.bCompileClick(Sender: TObject);
begin
ps.Script.Text := mScript.Text;
if ps.Compile then
begin
if ps.Execute then
ShowMessage('Done.')
else
ShowMessage('Execution Error: ' + Ps.ExecErrorToString);
end
else
HandleError;
end;
My Script:
program test;
var
Plugin: TMyPsPlugin;
begin
Plugin := TMyPsPlugin.Create;
Plugin.PrintMessage('Hello');
Plugin.Free;
end.
Error Messages:
[Error] (5:25): Unknown identifier 'Create'
[Error] (7:10): Unknown identifier 'FREE'
You didn't follow directions correctly from the article you cited.
It specifically says to run the unit importer, which generates two additional files (from MyClass.pas it creates MyClass.int and
uPSI_MyClass.pas
). You need to use theuPSI_MyClass.pas
(using, of course, the proper filename for your unit), and use the proper methods from that unit.Assuming that your source for TMyPSPlugin is in MyPSPlugin.pas, the unit importer would create MyPSPlugin.int and
uPSI_MyPSPlugin.pas
. You'd need to adduPSI_MyPSPlugin
to your uses clause, and then useTPSImport_MyPSPlugin.Create
and the additional code to register the plugin. (See the fourth image from the web page you linked - the image has a caption bar reading "ide_editor.pas".) At that point, Pascal Script is aware of your class and will recognize it's Create and Free methods.Apparently your plugin class descends directly from TObject. Add
uPSC_std
anduPSR_std
to your project and runSIRegisterTObject
andRIRegisterTObject
(C and R being the Compile-time and Runtime versions) before registering your plugin. That'll set up the default constructor and the Free method. If that doesn't work, make sure the unit importer specifically states that you're descending from TObject.