TStringGrid cannot display very long (6K) strings

I want to load some text into a TStringGrid. The lines are short except for the column where the line is over 100K. It seems that TStringGrid is not dealing with this. The text doesn't appear in the cell until I double-clicked the cell to edit it. Even then, the behavior is unstable.

Replay: put the grid on the form, set goEdit = true. Run the application and double-click the cell. Paste in some text (shouldn't contain input) and press Enter to finish editing. The text disappears.

In the text I made, the limit is around 6208 ASCII characters.
Any quick fix / workaround for this?

+3


source to share


2 answers


The text is colored in ExtTextOut

. This has been known to fail for very long lines. For example: ExtTextOut does not work on very long lines unless a lower font quality is specified . From what I can tell, it is difficult to determine what length of the string is causing the crash.



I suggest that if you need to support such long strings, you draw them yourself by implementing an event handler OnDrawCell

. Don't draw the whole line because after the user won't be able to see anything outside the cell rectangle. This way, you can avoid the problem of sending a ExtTextOut

string that is too long to process.

+9


source


you need to use Word break. of course without Word break nothing will be displayed. and couse your text must contain spaces.



const
  N = 16000;
var
  R: TRect;
  s: String;
  i: Integer;
begin
  R := ClientRect;
  SetLength(s, N);
  for i := 1 to N do
    if Random(10) = 0 then
      s[i] := ' '
    else
      s[i] := Char(65 + Random(26));
  Canvas.Font.Color := clBlack;

  Canvas.TextRect(R, s, [tfCenter, tfVerticalCenter, tfWordBreak]);
end;

      

+1


source







All Articles