Share Declarations

edited 1:15AM in FastScript
;)
Hi, FastReport rocks but still there are many non-registered classes, consts and vars with the installation. Lets use this thread to post Registrations of Delphi classes, consts, types, enums, etc. This will easy the developers to include our achievements in the next releases instead everyone to try to port the code by himself.

I am currently strating to port the Delphi "guts" with the mostly used constant in my source code

EmptyStr and TStringStream
unit unt_ScriptObjects;

interface

uses
  { VCL }
  SysUtils,
  Classes,
  { Fast Script }
  fs_iinterpreter;

implementation

type
  TFunctions = class(TObject)
  private
    function CallMethod(Instance: TObject; ClassType: TClass;
      const MethodName: String; var Params: Variant): Variant;
    function GetProp(Instance: TObject; ClassType: TClass;
      const PropName: String): Variant;
    procedure SetProp(Instance: TObject; ClassType: TClass;
      const PropName: String; Value: Variant);
  public
    constructor Create;
    destructor Destroy; override;
  end;

var
  Functions: TFunctions;


{ TFunctions }

function TFunctions.CallMethod(Instance: TObject; ClassType: TClass;
  const MethodName: String; var Params: Variant): Variant;
var
  _TSttringStream: TStringStream;  
begin
  if ClassType = TStringStream then
    if MethodName = 'CREATE' then
      Result := Integer(TStringStream(Instance).Create(Params[0]))
    else if MethodName = 'FREE' then
    begin
      fsEventList.FreeObjectEvents(Instance);
      Instance.Free;
    end;
end;

constructor TFunctions.Create;
begin
  with fsGlobalUnit do
  begin
    AddedBy := Self;
    AddConst('EmptyStr', 'string', EmptyStr);
    with AddClass(TStringStream, 'TStream') do
    begin
      AddConstructor('constructor Create(DataString: string)', CallMethod);
      AddProperty('DataString', 'string', GetProp, nil);
    end;

    AddedBy := nil;    
  end;
end;

destructor TFunctions.Destroy;
begin
  if fsGlobalUnit <> nil then
    fsGlobalUnit.RemoveItems(Self);
  inherited;
end;

function TFunctions.GetProp(Instance: TObject; ClassType: TClass;
  const PropName: String): Variant;
begin
  Result := 0;

  if ClassType = TStringStream then
  begin
    if PropName = 'DATASTRING' then
      Result := TStringStream(Instance).DataString;
  end;
end;

procedure TFunctions.SetProp(Instance: TObject; ClassType: TClass;
  const PropName: String; Value: Variant);
begin

end;

initialization

  Functions := TFunctions.Create;

finalization

  Functions.Free;

end.

Post your work, please. Share you knowledge.

Leave a Comment