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

Need to "shift right relative to" in RAP

edited August 2004 in RAP
Dear Sirs,
I need a lable or variable to shift right within a report template
not connected to a form. So, this would have to happen in the RAP
somewhere.

The code provide in the General news group works in a form, since the
TCanvas is not available in RAP. Tried using the
TppDBtext.Region.DesignControl.Canvas.TextWidth(), but it will not
compile in RAP.

Is there any Tpp component with a canvas that can be used to get the
text width?


procedure SetLabelLeftValue(aLabel1, aLabel2: TppDBText; aCanvas: TCanvas);
var
liLabelWidth: Integer;
begin
aCanvas.Font := aLabel1.Font;
liLabelWidth := aCanvas.TextWidth(aLabel1.Text);
aLabel2.Left := aLabel1.Left + liLabelWidth + 16;
end;


Thanks,
Dave

Comments

  • edited August 2004
    Hi Dave,

    The TextWidth method is not available in RAP. You will need to create a
    passthru function to gain access to the TextWidth method.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2004
    This will get you the right end of any control:

    HTH bernd

    type
    TComponentGetRightEnd = class(TraSystemFunction)
    public
    procedure ExecuteFunction(aParams: TraParamList); override;
    class function GetSignature : string; override;
    end;

    class function TComponentGetRightEnd.GetSignature : string;
    begin
    Result:='function ComponentGetRightEnd(aComponent:TComponent): Integer;';
    end;

    procedure TComponentGetRightEnd.ExecuteFunction(aParams: TraParamList);
    var
    lCustomText: TppCustomText;
    lBitmap : TBitmap;
    aComponent : TComponent;
    liTextWidth: Integer;
    liPosition : Integer;
    begin
    // use spLeft:=GetRightEnd instead of Left:= !!
    GetParamValue(0,aComponent);
    lCustomText:=TppCustomText(aComponent);
    lBitmap:=TBitmap.Create;
    lBitmap.Canvas.Font:=lCustomText.Font;
    liTextWidth:=lBitmap.Canvas.TextWidth(lCustomText.Text);
    liPosition:=lCustomText.spLeft+liTextWidth;
    lBitmap.Free;
    SetParamValue(1,liPosition);
    end;

    initialization
    raRegisterFunction('ComponentGetRightEnd',TComponentGetRightEnd);

    finalization
    raUnRegisterFunction('ComponentGetRightEnd');



  • edited August 2004
    Good stuff. Thanks for the info :).

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.