Custom report components and GetData

In my evaluation of FR 4.9.2, I am creating a custom report component (based on TfrxView) and cannot get it to Draw() using data that is retrieved in the GetData() method.

To simplify the problem, I have also tried this with the TfrxCheckBoxView example - which uses the GetData method to assign a value to the FChecked member variable. My version of this component is exactly like the example, except the example doesn't reveal the details of the DrawCheck(ARect: TRect) method.

Here's mine:
<!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->procedure TfrxCheckBoxView.DrawCheck(ARect: TRect);
begin
if FChecked then begin
FCanvas.Brush.Color := clRed;
FCanvas.Ellipse(ARect);
end;
end;<!--fontc--></span><!--/fontc-->

Also, I replaced the GetData code with the following:
<!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->procedure TfrxCheckBoxView.GetData;
begin
inherited;
FChecked := True;
end;<!--fontc--></span><!--/fontc-->

In the report designer, the component works as expected. I can set the published Checked property to True or False and the red ellipse will appear and disappear as expected. When I preview the report, the ellipse is never drawn. Based on the GetData code, I would expect it to always be drawn.

With my own component, I also overrode the Create and Destroy methods - so I was able to follow the component's life cycle. Here's what I found:

Open the designer with a report containing my component:
- ComponentA is created

Preview the report:
- ComponentB is created and GetData() is called. The correct data (a non-zero integer value) is pulled from the connected dataset and assigned to the member variable.
- ComponentC is created and Draw() is called. The data (integer value) for this component is 0.

Close the preview:
- Component B is destroyed. Its member data still contains the correct data.
- Component D is created.

Exit my application:
- Components A, C, and D are destroyed.


When I preview the report, two instances of my custom component is created. The first gets its data as expected, but isn't asked to Draw(). The second is the one that is drawn, but is never asked to GetData and therefore doesn't draw correctly.

Am I missing something?

-Aaron

Comments

  • edited 6:19PM
    H!

    I have similar problem!

    here is my code for dummy component:
    unit frxDummy;

    interface

    {$I frx.inc}

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls, Menus, frxClass, ExtCtrls, frxDsgnIntf, frxRes;


    type

    TfrxDummy = class(TfrxView)
    private
    FText: String;
    public

    procedure Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX, OffsetY: Extended); override;
    procedure GetData; override;
    class function GetDescription: String; override;
    published
    end;

    implementation

    class function TfrxDummy.GetDescription: String;
    begin
    Result := 'Dummy object';
    end;

    procedure TfrxDummy.Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX,
    OffsetY: Extended);
    begin
    BeginDraw(Canvas, ScaleX, ScaleY, OffsetX, OffsetY);
    Canvas.textout(fx,fy, FText);
    Canvas.textout(fx,fy+40, 'bbb');
    end;

    procedure TfrxDummy.GetData;
    begin
    FText:='aaa';
    end;


    initialization
    frxObjects.RegisterObject1(TfrxDummy, nil, '', 'Other', 0, 23);

    finalization
    frxObjects.UnRegister(TfrxDummy);


    end.



    And I never see 'aaa' on the screen..... >

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.