AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi FastScript - dem Script ein Interface hinzufügen
Thema durchsuchen
Ansicht
Themen-Optionen

FastScript - dem Script ein Interface hinzufügen

Ein Thema von geskill · begonnen am 29. Dez 2009 · letzter Beitrag vom 31. Dez 2009
Antwort Antwort
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#1

FastScript - dem Script ein Interface hinzufügen

  Alt 29. Dez 2009, 22:19
Hallo,
kurz vorweg, ich bin gerade am Testen dieser Komponente, eigentlich gefällt sie mir ganz gut, da der Hersteller auch ein Rabatt für seine Komponenten übers neue Jahr gibt, wäre es ein guter Kaufgrund.

Leider, aber auch verständlich da gerade Feiertage, sind ist in dem Support Forum nicht viel los.

Mein Problem besteht darin, dass ich im Programm einige Interfaces habe, die ich auch direkt dem User des Scripts zur Verfügung stellen möchte.

Aus der Dokumentation konnte ich hier entnehmen:
Zitat:
Adding an object to the script
To add an object to a script, call the TfsScript.AddObject method. The first parameter
is the name of the object, the second one is the object itself.
fsScript1.AddObject('Button1', Button1); If object has an unregistered type, you have to register it before calling AddObject:
Delphi-Quellcode:
fsScript1.AddClass(TForm1, 'TForm');
fsScript1.AddObject('Form1', Form1);
[...]

Adding a class to the script
To add a class to a script, call the TfsScript.AddClass method. The first parameter is
the class type, the second one is the name of the parent class.
Delphi-Quellcode:
type
TMyClass = class(TObject)
...
end;

fsScript1.AddClass(TMyClass, 'TObject');
This will make all the published properies of this class available. If you want to make
this class available for all the scripts, it is recommended to add this class to the
fsGlobalUnit which is a global ancestor of all the scripts.
Vielleicht hat ja jemand schon derartiges Vorgehabt und hätte eine Idee für mich. Alternativen wüsste ich auch nicht, würde auch gerne bei dieser bleiben; benutze den JScript Dialekt.

Grüße
Sebastian
  Mit Zitat antworten Zitat
Benutzerbild von RWarnecke
RWarnecke

Registriert seit: 31. Dez 2004
Ort: Stuttgart
4.408 Beiträge
 
Delphi XE8 Enterprise
 
#2

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 29. Dez 2009, 22:39
So erstelle ich doch ein Interface :
Delphi-Quellcode:
type
  TApplicationImpl = class(TInterfacedObject, IApplication)
  private
  {...}
  protected
  {...}
  public
  {...}
  end;
Wenn Du das ganze jetzt so versucht wie es für die Klasse beschrieben ist, sollte man über das Interface auf den Scriptbereich von FastReport zugreifen können. So würde ich es probieren.
Rolf Warnecke
App4Mission
  Mit Zitat antworten Zitat
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#3

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 29. Dez 2009, 22:58
Hallo,
genau, dass mit dem AddClass kann man ja so machen, jedoch wenn man dann die Instanz vom laufenden Programm dem Script übergeben will weiß ich nicht weiter:

IProgrammVariable ist jetzt in dem Beispiel vom Typ IApplication.
AddObject('ScriptVariable',IProgrammVariable); Geht nicht, da etwas von "TObject" erwartet wird :(
Sebastian
  Mit Zitat antworten Zitat
Benutzerbild von RWarnecke
RWarnecke

Registriert seit: 31. Dez 2004
Ort: Stuttgart
4.408 Beiträge
 
Delphi XE8 Enterprise
 
#4

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 29. Dez 2009, 23:07
Der Teil aus Beitrag #2 steht ja in Deinem Programm. Derjenige der über das Interface auf die Anwendung zugreift, greift ja über diesen Teil auf die Funktionen Deines Programm zu :
Delphi-Quellcode:
type
  IApplication = interface(IInterface)['{E770EE0C-05F3-4CC5-AF02-497F968287EA}']
    function xy:integer;
  end;
Die Funktione XY wird dann in dem Object TApplicationImpl deklariert und aufgerufen. Dieses Object solltest Du dann an FastScript übergeben können.
Rolf Warnecke
App4Mission
  Mit Zitat antworten Zitat
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#5

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 29. Dez 2009, 23:24
Dieses Objekt von dem du sprichst verwende ich im ganzen Programm nicht. (Hoffe ich weiß was du meinst)

Ums ein bisschen zu verdeutlichen:
Also die Instanz von TApplicationImpl merke ich mir nur als Inteface.
Delphi-Quellcode:
var
  IProgrammVariable: IApplication;

procedure Erstellen;
begin
  IProgrammVariable := TApplicationImpl.Create();

  IProgrammVariable.xy;
end;
Später will ich das dann dem Script hinzufügen:
Delphi-Quellcode:
procedure Hinzufügen;
begin
  with FfsScript do
  begin
    with AddClass(TApplicationImpl, 'TApplicationImpl') do
    begin
      AddMethod('procedure xy', CallMethod);
    end;
    AddObject('ScriptVariable', IProgrammVariable);
  end;
end;
Sebastian
  Mit Zitat antworten Zitat
Benutzerbild von RWarnecke
RWarnecke

Registriert seit: 31. Dez 2004
Ort: Stuttgart
4.408 Beiträge
 
Delphi XE8 Enterprise
 
#6

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 30. Dez 2009, 02:12
Ja und nein. Ich schreibe es nochmal etwas ausführlicher. Um die Basis eines Interface für ein Programm zur Verfügung zu stellen, brauchst Du zum Beispiel diese Klasse :
Delphi-Quellcode:
  TApplicationImpl = class(TInterfacedObject, IApplication)
  private
    FAppIntf: TApplicationImpl;
  public
    constructor Create(aAppIntf: TApplicationImpl);
    // overrides
    function Test_1: WideString;
    function Test_2: Integer;
  end;
Diese Klasse führt Operationen im Programm aus, wie zum Beispiel Daten aus einer Datenbank auslesen. Diese Daten werden nun dem Interface zur Verfügung gestellt und können abgerufen werden. Es geht natürlich auch der Weg rückwärts, also das Schreiben. In dem Sourcecode vom PlugIn hast Du dann folgendes deklariert um auf die Funktionen der Klasse zuzugreifen :
Delphi-Quellcode:
  IApplication = interface(IInterface)['{1C851830-2F05-434F-A4DC-A46482B8332F}'] // <-- Mit STRG+SHIFT+G erstellen
    function Test_1: WideString;
    function Test_2: Integer;
  end;
Über das Interface gereifst Du nun auf die Klasse zu und liest oder schreibst Werte. Zusätzlich sollte es doch möglich sein, dass das Object TApplicationImpl an FastScript übergeben wird mit :
faScript1.AddClass(TApplicationImpl, 'TInterfacedObject'); Jetzt könnte zum Beispiel die Funktion Test_1 irgendeinen Wert von FastScript bekommen und an das Interface weitergeben.
Rolf Warnecke
App4Mission
  Mit Zitat antworten Zitat
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#7

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 30. Dez 2009, 12:07
Das ist soweit ja möglich. Aber wenn man jetzt im Script ist und der Anwender schreibt so was:

Code:
ScriptVariable.Test_1;
Dann dafür müsste man ja FastScript diese Befehle übergeben:

Delphi-Quellcode:
#
  with AddClass(TApplicationImpl, 'TApplicationImpl') do
  begin
    AddMethod('procedure Test_1', CallMethod);
  end;
    
  AddObject('ScriptVariable', IProgrammVariable);
================================================== ==========
Wäre da nur diese eine Prozedur könnte ich gleich die ganze Klasse weglassen und nur die Prozedur hinzufügen. Habe hier mal das aktuelle Interface.

http://img5.imagebanana.com/img/4oqi.../Interface.jpg

So soll der User z.b. diesen Script Code benutzen können:
Code:
for(var i = 0; i < ScriptVariable.MirrorCount; i++)
  for(var j = 0; j < ScriptVariable.Mirror[I].DirectlinksMirrorCount; j++)
    ShowMessage(ScriptVariable.Mirror[I].DirectlinksMirror[J]);
Miniaturansicht angehängter Grafiken
interface_181.jpg  
Sebastian
  Mit Zitat antworten Zitat
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#8

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 30. Dez 2009, 17:36
Aber egal wie ich es drehe:
Programm kommt nicht mal in GetProp :(

Delphi-Quellcode:
function TTemplateParser.GetProp(Instance: TObject; ClassType: TClass; const PropName: String): Variant;
begin
  Result := 0;
  if PropName = 'MirrorCountthen
    Result := IMirrorController(Instance as TMirrorController).MirrorCount;
end;

function TTemplateParser.Exec(s: string): string;
begin
  Result := '';

  with FfsScript do
  begin
    with AddClass(TMirrorController, 'TMirrorController') do
    // with AddClass(TMirrorController, 'TInterfacedObject') do // geht genauso wenig
    begin
      AddProperty('MirrorCount', 'Integer', GetProp, nil);
    end;

    AddObject('IMirrorController', FITabSheetController.MirrorController as TMirrorController);
ScriptCode z.b.:
Code:
ShowMessage(IntToStr(IMirrorController.MirrorCount));
Sebastian
  Mit Zitat antworten Zitat
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#9

Re: FastScript - dem Script ein Interface hinzufügen

  Alt 31. Dez 2009, 14:58
ups, da hatte ich mir wohl ein Eigentor geschossen, ein paar Zeilen später im Code hatte ich ein clear Befehl, der alle hinzugefügten Objekte wieder gelöscht hat.
Somit geht es soweit. Habe mir die Komponenten jetzt gekauft.


Falls irgendwann jemand einen Lösungsansatz braucht:
Delphi-Quellcode:
function TTemplateParser.GetProp(Instance: TObject; ClassType: TClass; const PropName: String): Variant;
begin
  Result := 0;
  if PropName = 'MIRRORCOUNTthen
    Result := IMirrorController(Instance as TMirrorController).MirrorCount
  else if PropName = 'DIRECTLINKSMIRRORCOUNTthen
    Result := IMirrorControl(Instance as TMirrorControl).DirectlinksMirrorCount
  else if PropName = 'CRYPTERCOUNTthen
    Result := IMirrorControl(Instance as TMirrorControl).CrypterCount
  else if PropName = 'NAMEthen
    Result := ICrypterPanel(Instance as TCrypterPanel).Name
  else if PropName = 'LINKthen
    Result := ICrypterPanel(Instance as TCrypterPanel).Link;
end;

function TTemplateParser.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String;
  var Params: Variant): Variant;
begin
  Result := 0;
  if MethodName = 'MIRROR.GETthen
    Result := Integer(IMirrorController(Instance as TMirrorController).Mirror[Params[0]] as TMirrorControl)
  else if MethodName = 'DIRECTLINKSMIRROR.GETthen
    Result := IMirrorControl(Instance as TMirrorControl).DirectlinksMirror[Params[0]]
  else if MethodName = 'CRYPTER.GETthen
    Result := Integer(IMirrorControl(Instance as TMirrorControl).Crypter[Params[0]] as TCrypterPanel)
end;

function TTemplateParser.Exec(s: string): string;
var
  I: Integer;
begin
  Result := '';

  with FfsScript do
  begin
    Clear;
    Lines.Text := s;
    Parent := fsGlobalUnit;

    with AddClass(TCrypterPanel, 'TCrypterPanel') do
    begin
      AddProperty('Name', 'string', GetProp, nil);
      AddProperty('Link', 'string', GetProp, nil);
    end;

    with AddClass(TMirrorControl, 'TMirrorControl') do
    begin
      AddIndexProperty('DirectlinksMirror', 'Integer', 'string', CallMethod);
      AddProperty('DirectlinksMirrorCount', 'Integer', GetProp, nil);

      AddIndexProperty('Crypter', 'Integer', 'TCrypterPanel', CallMethod);
      AddProperty('CrypterCount', 'Integer', GetProp, nil);
    end;

    with AddClass(TMirrorController, 'TMirrorController') do
    begin
      AddIndexProperty('Mirror', 'Integer', 'TMirrorControl', CallMethod);
      AddProperty('MirrorCount', 'Integer', GetProp, nil);
    end;
    AddObject('IMirrorController', FITabSheetController.MirrorController as TMirrorController);

    if Compile then
      Execute;
    else
      Error(ErrorMsg);

  end;
end;
Sebastian
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:32 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz