Home Component Writing
New Blog Posts: Merging Reports - Part 1 and Part 2

Need a ppCustomShape component

edited August 2002 in Component Writing
Hi!
I neet a special CustomComponente, something like a ppShape but DataAware,
so it will be painted with the color assigned to the Fieldname.
This is what I'm trying to do:

If FieldName.AsString = 'clRed' then the shape will print in red.

Do you have some example of creating a ppcomponent from a ppShape control?
Where in code have I to write the algorithm?
Please, forgive my poor english

Comments

  • edited August 2002
    You have to create a custom shape component descendent. Overriding
    IsDataAware won't work because the deisgner is coded to try to show the
    possible shapetypes in the toolbar and not show the data pipeline and
    datafield boxes. So, you'll have to create a dialog from the popup menu for
    htis component. I have a demo which shows a dialog for a shape component to
    edit another property, but you can use it as a starting point to set teh
    data pipeline and data fields to be used by the shape. Now that you have
    the datapipeline and data field, you can get this value and set it in the
    overriden public PropertiesToDrawcommand routine to configure the draw
    command brush color.

    procedure TmyShape.PropertiesToDrawCommand(aDrawCommand: TppDrawCommand);
    begin

    inherited PropertiesToDrawCommand(aDrawCommand);

    if CheckForPipelineData and
    (DataPipeline.GetFieldValue(DataField).AsDouble < 5000.0) then
    TppDrawShape(aDrawCommand).Brush.Color := clRed
    else
    TppDrawShape(aDrawCommand).Brush.Color := clGreen;

    end;

    I'll email you the other project in zip format.

    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited August 2002
    Instead of creating a component, why don't you use the TWPaintbox component
    and in the OnDrawPaintbox event, fill the ClipRect with the color of the field
    value.

    OnDrawPaintbox (aCanvas : TCanvas; ClipRect : TRect)
    begin
    if FieldName.AsString = 'clRed' then
    aCanvas.Brush.Color := clRed
    else
    if FieldName.AsString = 'clBlue' then
    aCanvas.Brush.Color := clBlue;

    aCanvas.FillRect(ClipRect);
    end;

    --
    Daniel Lemire
    Programmeur,
    Conception Design Ware Inc.
    Tél.: 819-868-8853
    Fax : 819-868-8855
  • edited August 2002
    Because I want end-users to use the component in the designer, not by code,
    but thanks for the suggestion!!

    "cdware" escribi? en el mensaje
This discussion has been closed.