[SOLVED] TextRect and ListBox issues lazarus / 39-Graphics ---------------------------------------------------------------------- lainz · 2021-04-22 16:03 Hi, I have this code, that draws the listbox rows. The problem is that the numbers are moved to the Right (I'm using Lazarus and FPC trunk). See attached screenshot. The product in the Object of TProductos says: Quote1 KG HELADO and when drawn it shows QuoteKG HELADO 1 Any ideas? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TPOSBerryLiteSearch.ListBoxDraw(Control: TWinControl;  Index: integer; ARect: TRect; State: TOwnerDrawState);   procedure DrawListItemBackground();  begin    if (Index mod 2 = 0) then    begin      FListBox.Canvas.Pen.Color := TPOSBerryTheme.getTheme.rowEvenColor;      FListBox.Canvas.Brush.Color := TPOSBerryTheme.getTheme.rowEvenColor;    end    else    begin      FListBox.Canvas.Pen.Color := TPOSBerryTheme.getTheme.rowOddColor;    FListBox.Canvas.Brush.Color := TPOSBerryTheme.getTheme.rowOddColor;  end;    FListBox.Canvas.Rectangle(ARect);  end;   procedure DrawListItemSelection();  begin    FListBox.Canvas.Pen.Color := TPOSBerryTheme.getTheme.rowSelectedBorderColor;    FListBox.Canvas.Brush.Color := TPOSBerryTheme.getTheme.rowSelectedColor;    FListBox.Canvas.Rectangle(ARect);  end;   procedure DrawListItemProductos();  var    p: TProductos;    ts: TTextStyle;  begin    p := TProductos(FListBox.Items.Objects[Index]);    if (p.bfavorito.IsNull) or (p.bfavorito.Value = 'F') then      FIcons.Draw(0, 1, FListBox.Canvas, 5, ARect.Top, Scale96ToForm(50),      ARect.Height, False, 255)    else      FIcons.Draw(1, 1, FListBox.Canvas, 5, ARect.Top, Scale96ToForm(50),        ARect.Height, False, 255);    ts.Alignment := taLeftJustify;    ts.Layout := tlCenter;    ts.SystemFont := False;    ts.Clipping := True;    ts.SingleLine := True;    ts.Wordbreak := False;    ts.EndEllipsis := False;     FListBox.Canvas.TextRect(Rect(ARect.Left + 50, ARect.Top,    Scale96ToForm(250), ARect.Bottom), Scale96ToForm(60),      0, p.scodproducto.Value, ts);    FListBox.Canvas.TextRect(Rect(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom),      Scale96ToForm(260), 0, p.snombre.Value, ts);  end;   procedure DrawListItemClientes();  var    p: TClientes;    ts: TTextStyle;  begin    p := TClientes(FListBox.Items.Objects[Index]);  if (p.bfavorito.IsNull) or (p.bfavorito.Value = 'F') then      FIcons.Draw(2, 1, FListBox.Canvas, 5, ARect.Top, Scale96ToForm(50),      ARect.Height, False, 255)    else      FIcons.Draw(1, 1, FListBox.Canvas, 5, ARect.Top, Scale96ToForm(50),        ARect.Height, False, 255);    ts.Alignment := taLeftJustify;    ts.Layout := tlCenter;    ts.SystemFont := False;    ts.Clipping := True;    ts.SingleLine := True;    ts.Wordbreak := False;    ts.EndEllipsis := False;     FListBox.Canvas.TextRect(Rect(ARect.Left + 50, ARect.Top,    Scale96ToForm(250), ARect.Bottom), Scale96ToForm(60),      0, p.scodcliente.Value, ts);    FListBox.Canvas.TextRect(Rect(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom),      Scale96ToForm(260), 0, p.srazonsocial.Value, ts);  end; begin  FListBox.Canvas.Font := Parent.Font;  if (odSelected in State) then    DrawListItemSelection()  else    DrawListItemBackground();   case SearchKind of    skProductos: DrawListItemProductos();    skClientes: DrawListItemClientes();  end;end; ---------------------------------------------------------------------- howardpc · 2021-04-22 18:02 You don't explicitly set Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ts.RightToLeft so it takes a value you may not expect? ---------------------------------------------------------------------- lainz · 2021-04-22 20:18 Quote from: howardpc on April 22, 2021, 08:02:36 pmYou don't explicitly set Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ts.RightToLeft so it takes a value you may not expect? Thanks!! Setting it to False does the trick. ---------------------------------------------------------------------- flowCRANE · 2021-04-23 16:44 The easiest way is just to initialize the variable, and then, set only those properties that should have non-default values. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ts := Default(TTextStyle); ts.Layout := tlCenter;ts.Clipping := True;ts.SingleLine := True; Full confidence, less code. ---------------------------------------------------------------------- wp · 2021-04-24 21:19 Quote from: furious programming on April 23, 2021, 06:44:36 pmThe easiest way is just to initialize the variable, and then, set only those properties that should have non-default values. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ts := Default(TTextStyle); ts.Layout := tlCenter;ts.Clipping := True;ts.SingleLine := True;But this overwrites TextStyle elements that may have been set before. To avoid this I usually initialize the record as ts := Canvas.TextStyle and then apply my changes.