Здравствуйте!
Понадобилось, чтобы результаты поиска выводились в stringgrid. Причем надо, чтобы ячейки были многострочными. Покопавшись в советах Валентина Озерова нашел этот код:
unit WrapGrid;
interface
uses
SysUtils, WinTypes, WinProcs, Messages,
Classes, Graphics, Controls,
Forms, Dialogs, Grids;
type
TWrapGrid = class(TStringGrid)
protected
procedure DrawCell(ACol, ARow : Longint; ARect : TRect; AState : TGridDrawState); override;
public
constructor Create(AOwner : TComponent); override;
end;
procedure Register;
implementation
constructor TWrapGrid.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
DefaultDrawing := False;
end;
procedure TWrapGrid.DrawCell(ACol, ARow : Longint; ARect : TRect; AState : TGridDrawState);
var
Sentence, CurWord : String;
SpacePos,
CurX,
CurY : Integer;
EndOfSentence : Boolean;
begin
Canvas.Font := Font;
with Canvas do
begin
if gdFixed in AState then
begin
Pen.Color := FixedColor;
Brush.Color := FixedColor;
end
else
begin
Pen.Color := Color;
Brush.Color := Color;
end;
Rectangle(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
end;
CurX := ARect.Left;
CurY := ARect.Top;
Sentence := Cells[ACol, ARow];
EndOfSentence := False;
while (not EndOfSentence) do
begin
SpacePos := Pos(' ', Sentence);
if SpacePos > 0 then
begin
CurWord := Copy(Sentence, 0, SpacePos);
Sentence := Copy(Sentence, SpacePos + 1, Length(Sentence) - SpacePos);
end
else
begin
EndOfSentence := True;
CurWord := Sentence;
end;
with Canvas do
begin
if (TextWidth(CurWord) + CurX) > ARect.Right then
begin
CurY := CurY + TextHeight(CurWord);
CurX := ARect.Left;
end;
TextOut(CurX, CurY, CurWord);
CurX := CurX + TextWidth(CurWord);
end;
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [TWrapGrid]);
end;
end.
Все прерасно, все работает. А вопрос собственно вот в чем: как сделать, чтобы высота ячейки автоматически изменялась так, чтобы текст в ячейке был виден полностью? Попробовал через массив RowHeights, но либо у меня руки кривые, либо одно из двух

Впринципе я решил этот вопрос другим путем: в модуле, где использую этот компонент, после выводов результата поиска, пробегаю по ячейкам, опять вычисляю высоту текста и в этом цикле устанавливаю высоты строк. Но хотелось бы эту задачу реализовать в компоненте.
Заранее благодарю