Slow Canvas.TextRect (TsWorksheetGrid) lazarus / 39-Graphics ---------------------------------------------------------------------- xinyiman · 2016-10-21 22:18 Hello guys, follow my function that draws on one of the TsWorksheetGrid cells with colored background and a lot of text. If the text is short the program is fast changing in the cell. If the text is long time to change from one cell to another it is long (up to 2 seconds). Can anyone tell me why? 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 TAppuntamentiGiornalieri.InserisciTestoSplittato(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState; stepRow: integer; indice: integer; LarghezzaCella: integer; Shield: boolean);var  i, x, y: Integer;  txtStyle, appStyle : TTextStyle;  Testo: string;begin   //Vado ad inserire il testo  with sender as TsWorksheetGrid do  begin     appStyle := Canvas.TextStyle;    appStyle.Wordbreak:=true;    appStyle.SingleLine:=false;    appStyle.Alignment:=taLeftJustify;     Canvas.Font.Name := 'Courier New';    Canvas.Font.Color := clBlack; //clSilver;    Canvas.Font.Style := [];    Canvas.Font.Height := 12;     y:=aRect.Top;    if LarghezzaCella>20 then       x:=aRect.Left + 20 //il + 20 è lo spazio dal bordo sinistro perchè il testo deve iniziare dopo la barra colorata    else        x:=aRect.Left + 1;     // queste due righe mi permettono di scrivere sul blocco verde senza togliermi gli angoli arrotondati    txtStyle := Canvas.TextStyle;    txtStyle.Opaque:=True;     //Inserisco il testo    Testo:=Self.Dati[indice].TestoAssemblato;    if Shield=true then       Testo := TrasformaTesto(Testo);     Canvas.TextRect(aRect, x, y, Self.GetTesto(indice, Shield), appStyle);     //reimposto lo stile precedente all'inserimento del testo    Canvas.TextStyle := txtStyle;   end;end; ---------------------------------------------------------------------- circular · 2016-10-22 06:25 Maybe Self.GetTesto is slow? ---------------------------------------------------------------------- xinyiman · 2016-10-22 08:09 No! Also this is slow (direct string) Canvas.TextRect(aRect, x, y, 'ciao come stai tante belle parole che non sono coerenti, ciao caio sempronio, servo solo a fare una stringa discretamente lunga...porca paletta', appStyle); ---------------------------------------------------------------------- xinyiman · 2016-10-22 08:23 I understood what makes the slow Canvas.TextRect! It 'option appStyle.Wordbreak:=true; In fact, if the comments performance improves. However, if one needs to go to the head? How can it be done? //appStyle.Wordbreak:=true; ---------------------------------------------------------------------- wp · 2016-10-22 09:53 What I don't understand is why you are working with TextStyle.Wordbreak and Fonts at all? All these are built into the WorksheetGrid, you just have to activate the options for the particular cell (see http://wiki.lazarus.freepascal.org/TsWorksheetGrid#Cell_formatting): 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   WorksheetGrid.WordWrap[gridCol, gridRow] := true;  WorksheetGrid.CellFontName[gridCol, gridRow] := 'Courier'  WorksheetGrid.CellFontSize[gridCol, gridRow] := 12;  WorksheetGrid.CellFontColor[gridCol, gridRow] := clSilver; Could you condense the issue into a simple compilable project so that I can have a look?