Instantiation problem

Hi All,

Currently I am researching the possibilities with FastScript.
The problem I'm running in to is the following.

I have a Class (which is not a default delphi component)
And that said Class is for the ease of this example now named TAp and is added by the following code:
with fsGlobalUnit.AddClass(TAp, 'TObject') do
   begin
   { functions & procedures }
       AddMethod('function FindSAP(DevName: String)', CallTapMethod);
   end;
fsGlobalUnit.AddObject('App', TAp.NewInstance);
fsGlobalUnit.AddType('App', fvtClass);

with fsGLobalUnit.AddClass(TSap, 'TSObject') do
   begin
   { functions & procedures }
       AddMethod('function DoSomething():Boolean', CallYMethod);
   end;
fsGlobalUnit.AddObject('TSap', TSap.NewInstance);
fsGlobalUnit.AddType('TSap', fvtClass);

my CallTapMethod is implemented like this.
function TScriptHelper.CallTapMethod(Instance: TObject; ClassType: TClass;
                                     const MethodName: String; var Params: Variant): Variant;
begin
if (MethodName = 'FindSAP') then
    begin
      result := Integer(_uAp.TAp.Create().FindSAP(AnsiString(params)));
    end
end;
Which points to the function that should be called.
When calling the function FindSAP from the FScript with the given parameter like this.
var
    x: TSap;
begin
    x:=App.FindSAP('value');
end;
Where value is just a normal string. I receive a message from FastScript. Stating that I have incompatible types.
Lets make it clear that the function FindSAP should return an instantiated object. (which it does when normally calling the function straight from delphi).
And ofcourse that fact that i Add the fsGlobalUnit to the FScript component via fsScript1.Parent := fsGlobalUnit;

The message i receive is the following: Incompatible types TSap, String.

I am unsure whats going on here. As far as I know I have implemented everything necessary and would like to have some help or at least a push in the right direction

Comments

  • Problem is solved.

    I forgot to add the return type in the function:
    function FindSAP(DevName: String)
    
    function FindSAP(DevName: String): TSAP;
    

    did the trick

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.