Custom control

I have a TfrxPictureView object that uses some custom logic in the OBP event to obtain a picture from a file based on a value passed in another field of the database. This works well.

However, I would like to give my users the option of designing their own reports and want to hide this logic from them so they can just drag a modfied/descendant of PictureView onto their report.

Rather than write a custom control from scratch is there an example of modifying a control just to include some logic in an event such as this?

Comments

  • gpigpi
    edited 7:08AM
    See a Developer's manual "Custom Report Components Writing" chapter for more info
  • I've seen that thanks gpi - I am looking for a simpler example though. I dont need to write a control from scratch, I just need a minor modification to an existing control.
  • edited February 2013
    Hi,

    I have something similar but is personalized for my application and I need to work a little to extract.
    If you have sources look a little to TfrxPictureView and TfrxPictureView.GetData.
    Copy all TfrxPictureView object and modify it to your needs. I deleted more than half from TfrxPictureView.
    In GetData you need to call your procedure to get the image.
    You can pass an ID into the table field and your function will fill FPicture accordingly.

    If you want to add a new property to the component do not forget to write into TfrxPictureView.Diff(). For me it was a pain to understood why I loos the values.
    Something like:
    function TfrxMyImage.Diff(AComponent: TfrxComponent): String;
    begin
      Result := inherited Diff(AComponent);
      Result := Result + ' MyProperty="' + FMyProperty + '"';
    end;
    

    Best Regards,
    Cristian Peta
  • Thanks Peta - I need to get a new release out without user report customisation so I need to concentrate on testing that for a while. I'll be revisiting this in a week or so.
  • I have had a look though the manual and to be honest I am not much the wiser. For instance I have a tfrcMemoView component that holds a string that I then format using a custom function in the OBP event. This works great.

    I want to create a descendant of tfrcMemoView that automatically does the above and hides it from my users. I can't see which files I need to edit, or whether I need to edit any files but rather create new ones. I cant see how FR will know where/how to pick up my custom component once I have written it.

    I assume that I need to write in Pascal/Delphi rather than C++

    Does anyone have an idiots guide (preferably a very small example of a similarly modified component - rather than creating a component from a base class) with step by step instructions of which files to edit and why?

    I have read the following in the developers manual
    FastReport Class Hierarchy
    Writing Custom Report Components

    Thanks
  • edited 7:08AM
    Hallo,

    I attached an example of bitmap component that print the bitmap from a TBitmap array named MyImageList.
    Simply add FastReport_Comp to your uses clause and you have the component that print an image from your list. The image index is from DataField.
    With C++ you know the best what you need to do more.
    There is a resource identifier frxWA_MyBmpImage that you need to have it into the project resources.

    I have not tested this component because this is a light version of my image component.

    Best Regards,
    Cristian Peta
  • That is very helpful Christian, Thank You.

  • Ahh failed at first hurdle

    I add your component to my project and try to compile ag get the error below. I am using C++ Builder XE3 (I dont have Delphi - although clearly the compiler seems to be there)

    I am wondering whether this is a fundamental flaw in my understanding of what goes on here - do I need to recompile fastreports to make the component 'visible', can I actually recompile fast reports?

    [DCC Fatal Error] fastreport_mycomp.pas(1): F1027 Unit not found: 'System.pas' or binary equivalents (.dcu)

    Does anyone else on here actually write custom components in using Builder rather than Delphi?
  • edited 7:08AM
    Hallo,

    try to search google with "Mixing C++Builder and Delphi code"
    Or maybe is easy to translate pascal to C.
    Recompiling FR is not necessary from what I know.

    Best Regards,
    Cristian Peta
  • edited 7:08AM
    Cristian, could you explain me how to use "Diff" function?

    In my custom component, i override Diff but it is never used so I loose my own properties.

    I've made a simple arrow (like in Developer Manual) with an integer property.
  • edited 7:08AM
    VictorV wrote: »
    Cristian, could you explain me how to use "Diff" function?

    Hello

    If you post your component here I can take a look.

    Best Regards,
    Cristian Peta
  • edited 7:08AM
    Peta wrote: »
    Hello

    If you post your component here I can take a look.

    Best Regards,
    Cristian Peta


    Thanks for your answer.
    Here it is a test project that I'm using to test custom components.
    Anyway, I have advanced on my problem and now I think I know why it doesn't work but I don't know how to fix it.

    What I want is to pass some parameters to my component on the event OnBeforePrint. I successed with it but when the Report is drawn, a totally new instance of my component is created and this instance doesn't shoot any event so I have not access to give it these parameters.
    How can I dinamically modify a custom component? Is it normal what happened in my project? The new instance should have exactly the same values on all properties that the instance that shoot the OnBeforePrint, isn't it?

    I hope you could help me.
    Thanks in advance.
  • edited March 2013
    Hello,

    I used C++ more than ten years ago and now I am a Delphi guy... but I hope I can help you.

    1. Diff() works well with public properties. You must have a public property numero so FastReport can write into.
    __property int numero = {read=fnumero, write=fnumero};
    

    2. I use only Diff() and do not use AllDiff()

    Best Regards,
    Cristian Peta
  • edited March 2013
    Hello Cristian,

    I used AllDiff() to see if it work but it doesn't.
    I made a public property but I see that Diff() method is never called, maybe that is my problem. When has FastReport to call Diff() method?

    Thanks again!
  • edited March 2013
    Hello,

    actually my properties are published. Maybe is not enough to be public. I know, the user will see them.
    And Diff() is called only to store values after prepare the report. The FastReport store your values caling Diff(). And when show the report, RTTI is used to restore values in newly created objects.

    And one more thing. You must override Diff() function in your object and not declare it virtual. Because this your Diff is not called.

    Best Regards,
    Cristian Peta
  • Hello ,
    I created my component, I registered It but I can't see it in designer ?

    Forgot something?

    Join my component here...


    Thx a lot.
    Christof

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.