Recent

Author Topic: wordwrap failing on extra parameter  (Read 1657 times)

janvb

  • Jr. Member
  • **
  • Posts: 76
wordwrap failing on extra parameter
« on: July 30, 2014, 11:10:59 pm »
The proc below will draw a symbol with wordwrap if I remove the z:Double parameter, but wordwrap fail with the parameter precent?

Can anyone explain this to me?

procedure TSymbol.Draw(acanvas:TCanvas;z:Double);
var
    rect : TRect;
    txt : String;
    flags : TTextStyle;
    zx,zy:Double;
begin
    zx:=X*z;
    zx:=Y*z;
    acanvas.Pen.Color:=clBlue;
    acanvas.Brush.Color:=clYellow;
    acanvas.RoundRect(X,Y,X+100,Y+50,10,10);
    rect.Left:=X+2;
    rect.Top:=Y+1;
    rect.Right:=X+98;
    rect.Bottom:=Y+48;
    acanvas.Font.Color:=clBlue;
    acanvas.Font.Height:=12;
    txt := 'Override TSymbol.Draw to avoid this example text.';

    flags.Wordbreak:=true;
    flags.Alignment:=TAlignment.taCenter;

    acanvas.TextRect(rect,X,Y,txt,flags);
end;

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: wordwrap failing on extra parameter
« Reply #1 on: July 30, 2014, 11:57:13 pm »
Difficult to say from an uncompilable code snippet, but it probably has less to do with the z parameter, and more to do with the fact that you don't initialize many fields of the flags variable, so you present lots of random data to the TextRect method.

janvb

  • Jr. Member
  • **
  • Posts: 76
Re: wordwrap failing on extra parameter
« Reply #2 on: July 30, 2014, 11:59:47 pm »
    flags.SingleLine:=false;

Yes adding that line fixed it. flags was obviously not initialized and picked up the random setting at it's location. adding a parameter on the stack changed the location.

 

TinyPortal © 2005-2018