Всем привет! Не знал, где создать тему, создал в данной ветке.
Вопрос в следующем: на форме есть 2 StringGrid-а у которых одинаковая процедура OnDrawCell, различия только в названиях таблиц. Что-то мне подсказывает

, что можно одну процедуру прикрутить к двум таблицам, чтобы не "плодить" лишнего кода. Вот код самой процедуры:
Код:
procedure TForm.StringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
Format: Word;
C : array[0..255] of Char;
temp, max, i, j : integer;
begin
Format := DT_Center OR DT_WORDBREAK;
(Sender as TStringGrid).Canvas.FillRect(Rect);
StrPCopy(C, (Sender as TStringGrid).Cells[ACol, ARow]);
WinProcs.DrawText((Sender as TStringGrid).Canvas.Handle, C, StrLen(C), Rect, Format);
for I := 0 to StringGrid1.ColCount - 1 do
begin
max:= 0;
for J := 0 to StringGrid1.RowCount - 1 do
begin
temp := StringGrid1.Canvas.TextWidth(StringGrid1.Cells[i, j]);
if temp > max then
max:=temp;
end;
StringGrid1.ColWidths[i] := max + StringGrid1.GridLineWidth + 10;
end;
end;
Пробовал делать так:
Код:
.....
private
procedure TForm.GridsDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
......
procedure TForm.GridsDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
Format: Word;
C : array[0..255] of Char;
temp, max, i, j : integer;
begin
Format := DT_Center OR DT_WORDBREAK;
(Sender as TStringGrid).Canvas.FillRect(Rect);
StrPCopy(C, (Sender as TStringGrid).Cells[ACol, ARow]);
WinProcs.DrawText((Sender as TStringGrid).Canvas.Handle, C, StrLen(C), Rect, Format);
with Sender as TStringGrid do
for I := 0 to StringGrid.ColCount - 1 do
begin
max:= 0;
for J := 0 to StringGrid.RowCount - 1 do
begin
temp := StringGrid.Canvas.TextWidth(StringGrid.Cells[i, j]);
if temp > max then
max:=temp;
end;
StringGrid.ColWidths[i] := max + StringGrid.GridLineWidth + 10;
end;
end;
Но не получается, выбивает с ошибкой, что-то с памятью
Помогите пожалуйста, оптимизировать код для личного так сказать роста

. Спасибо.