Exposing Custom Classes in Fast Reports

Hi,

I am attempting to expose custom Classes in Fast reports (for coding / scripting purposes during report design).

Herewith a sample of my implementation on my application's source side:

I Create a new Module for Class Exposure, and publish a "Objectnew" function.
TMyObject and TMyOtherObject are both declared elsewhere in my source.
TMyObject and TMyOtherObject are both exposed in the report designer.

Within the report designer I create TMyObject as

TMyObject.Create
and then call objectnew (as its member function)

The code below indicates what happens in the callback.
wrote:
TMyClasses = Class(TfsRTTIModule)
Private
Protected
function CallMethod(Instance: TObject; ClassType: TClass;
const MethodName: String; Caller: TfsMethodHelper): Variant;
function GetProperty(Instance: TObject; ClassType: TClass;
const PropName: String): Variant;
procedure SetProperty(Instance: TObject; ClassType: TClass;
const PropName: String; Value: Variant);
Public
constructor Create(AScript: TfsScript); override;
Published
End;


function TIQReportAPIClasses.CallMethod(Instance: TObject;
ClassType: TClass; const MethodName: String;
Caller: TfsMethodHelper): Variant;
var
FMyObject: TMyObject;
FMyOtherObject: TMyOtherObject;
begin
If ClassType = TMyObject Then
Begin
FXML := TMyObject(Instance);

If AnsiCompareText(MethodName,'Objectnew') = 0 Then
Begin
FMyOtherObject := TMyOtherObject.Create; //Ignore Owner for now, actual implementation handlers owner and freeing
FMyOtherObject.Dataname := Caller.Params[0];
Result := PointerToVariant(FMyOtherObject);
End;
End;
end;

constructor TIQMyClasses.Create(AScript: TfsScript);
begin
inherited;
With AScript Do
Begin
With AddClass(TMyObject, 'TObject') Do
Begin
AddMethod('Function Objectnew(aName:String): TMyOtherObject', CallMethod);
End;
AddClass(TMyOtherObject, 'TObject');
End;
end;

Initialization
fsRTTIModules.Add(TIQMyClasses);

Finalization
If fsRTTIModules<>Nil Then fsRTTIModules.Remove(TMyClasses);

Fast reports example code interaction with objects / classes
wrote:
var
F: TMyObject;
F2 : TMyOtherObject;
begin
F := TMyObject.Create;
F2 := TMyOtherObject(F.ObjectNew);

{
more code accessing f2 member functions
}

end;

Now, in the first section of source you'll notice that I have a Pointer to Variant function
which simply cast the object as an Integer and returns it to Fast Reports as a Variant

In Fast Reports, I just cast it back to TMyOtherObject

Now, when accessing functions from F2, I tend to get a number of access violations, which shouldn't occur in normal circumstances.

Are there things that I have missed / misunderstood with the exposure of classes into fast reports designer?

Many thanks

Comments

  • I believe Im closer to my problem. The TMyOtherObject must also be an TfsRTTIModule object (to be available in the reportwriter design section) and it is defined as such.

    However for me to create it on the sourcecode side, I need to call its Create constructor and send it a script. From what I understand I must send it FSGLobalUnit (a global script object). Is this correct?

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.