Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 29.02.2012, 15:28   #1
SPD
Пользователь
 
Регистрация: 30.11.2009
Сообщений: 41
Радость печать из StrinGrid

вот возникла необходимость распечатать StrinGrid
Код:
unit GrdPrn3;
interface
uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, xmldom, XMLIntf, msxmldom, XMLDoc, Menus, ExtCtrls, Printers, ComObj, ActiveX, AxCtrls, OleCtrls, VCF1, Grids;
const
 OrdinaryLineWidth: Integer = 2;
 BoldLineWidth: Integer = 4;
procedure PrintStringGrid(Grid: TStringGrid; Scale: Double; LeftMargin,
TopMargin, BottomMargin:
Integer);
function DrawStringGridEx(Grid: TStringGrid; Scale: Double; FromRow,
LeftMargin, TopMargin, Yfloor: Integer; DestCanvas: TCanvas): Integer;
implementation
procedure PrintStringGrid(Grid: TStringGrid; Scale: Double; LeftMargin,
TopMargin, BottomMargin: Integer);
var NextRow: Integer;
begin
 //Printer.BeginDoc;
 if not Printer.Printing then raise Exception.Create('function  PrintStringGrid must be called between Printer.BeginDoc  and Printer.EndDoc');

 NextRow := 0;
 repeat
  NextRow := DrawStringGridEx(Grid, Scale, NextRow, LeftMargin, TopMargin,
   Printer.PageHeight - BottomMargin, Printer.Canvas);
  if NextRow <> -1 then Printer.NewPage;
 until NextRow = -1;

 //Printer.EndDoc;
end;
function DrawStringGridEx(Grid: TStringGrid; Scale: Double; FromRow,
LeftMargin, TopMargin, Yfloor: Integer; DestCanvas: TCanvas): Integer;
 // возвращает номер строки, которая не поместилась до Y = Yfloor
var
 i, j, d, TotalPrevH, TotalPrevW, CellH, CellW, LineWidth: Integer;
 R: TRect;
 s: string;


  procedure CorrectCellHeight(ARow: Integer);
  // вычисление правильной высоты ячейки с учетом многострочного текста
  // Текст рабивается только по словам слишком длинное слово обрубается
  var
   i, H: Integer;
   R: TRect;
   s: string;
  begin
   R := Rect(0, 0, CellH*2, CellH);
   s := ':)'; // Одинарная высота строки
   CellH := DrawText(DestCanvas.Handle, PChar(s), Length(s), R,
     DT_LEFT or DT_TOP or DT_WORDBREAK or DT_SINGLELINE or
     DT_NOPREFIX or DT_CALCRECT) + 3*d;
   for i := 0 to Grid.ColCount-1 do
   begin
    CellW := Round(Grid.ColWidths[i]*Scale);
    R := Rect(0, 0, CellW, CellH);
    //InflateRect(R, -d, -d);
    R.Left := R.Left+d;
    R.Top := R.Top + d;


    s := Grid.Cells[i, ARow];
    // Вычисление ширины и высоты
    H := DrawText(DestCanvas.Handle, PChar(s), Length(s), R,
     DT_LEFT or DT_TOP or DT_WORDBREAK or DT_NOPREFIX or DT_CALCRECT);
//текста
    if CellH < H + 2*d then CellH := H + 2*d;
    // if CellW < R.Right - R.Left then Слишком длинное слово -
    // не помещается в одну строку; Перенос слов не поддерживается
   end;
  end;

begin
 Result := -1; // все строки уместились между TopMargin и Yfloor
 if (FromRow < 0)or(FromRow >= Grid.RowCount) then Exit;

 DestCanvas.Brush.Style := bsClear;
 DestCanvas.Font := Grid.Font;
//  DestCanvas.Font.Height := Round(Grid.Font.Height*Scale);
 DestCanvas.Font.Size := 10;

 Grid.Canvas.Font := Grid.Font;
 Scale := DestCanvas.TextWidth('test')/Grid.Canvas.TextWidth('test');

 d := Round(2*Scale);
 TotalPrevH := 0;

 for j := 0 to Grid.RowCount-1 do
 begin
  if (j >= Grid.FixedRows) and (j < FromRow) then Continue;
  // Fixed Rows рисуются на каждой странице

  TotalPrevW := 0;
  CellH := Round(Grid.RowHeights[j]*Scale);
  CorrectCellHeight(j);

  if TopMargin + TotalPrevH + CellH > YFloor then
  begin
   Result := j; // j-я строка не помещается в заданный диапазон
   if Result < Grid.FixedRows then Result := -1;
   // если фиксированные строки не влезают на страницу -
   // это тяжёлый случай...
   Exit;
  end;

  for i := 0 to Grid.ColCount-1 do
  begin
   CellW := Round(Grid.ColWidths[i]*Scale);

   R := Rect(TotalPrevW, TotalPrevH, TotalPrevW + CellW, otalPrevH + CellH);
   OffSetRect(R, LeftMargin, TopMargin);

   if (i < Grid.FixedCols)or(j < Grid.FixedRows) then
     LineWidth := BoldLineWidth
   else
     LineWidth := OrdinaryLineWidth;

   DestCanvas.Pen.Width := LineWidth;
   if LineWidth > 0 then
    DestCanvas.Rectangle(R.Left, R.Top, R.Right+1, R.Bottom+1);

   //InflateRect(R, -d, -d);
   R.Left := R.Left+d;
   R.Top := R.Top + d;

   s := Grid.Cells[i, j];
   DrawText(DestCanvas.Handle, PChar(s), Length(s), R,
    DT_LEFT or DT_TOP or DT_WORDBREAK or DT_NOPREFIX);

   TotalPrevW := TotalPrevW + CellW; // Общая ширина всех предыдущих колонок
  end;

  TotalPrevH := TotalPrevH + CellH;  // Общая высота всех предыдущих строк
 end;
end;

end.
помогите пож исправить ошибку выдает

Код:
CellW := Round(Grid.ColWidths[i]*Scale);
R := Rect(TotalPrevW, TotalPrevH, TotalPrevW + CellW, otalPrevH + CellH);
OffSetRect(R, LeftMargin, TopMargin);
[Error] GrdPrn3.pas(123): Undeclared identifier: 'otalPrevH'


помогите пож а то всюду етот код выдают как робочий.

Ну или мож если кто знает какой то вариант попроще для распечатки спринга с кучей страниц...

Заранее благодарен...
SPD вне форума Ответить с цитированием
Старый 29.02.2012, 15:32   #2
Hacker19_90
Delphi Warrior
Старожил
 
Аватар для Hacker19_90
 
Регистрация: 15.08.2008
Сообщений: 2,502
По умолчанию

Перевожу
Undeclared identifier: 'otalPrevH' = неизвестный идентификатор 'otalPrevH'!
А всё потому что у вас есть переменная
Цитата:
Код:
TotalPrevH, TotalPrevW, CellH, CellW, LineWidth: Integer;
Короче опечатка у вас!
Mess with the best, die like the rest. (с) Hackers
Лабораторные, курсовые на Delphi\Pascal\C++
ya.flex-freelance@yandex.ru Icq - 636-954-303
Hacker19_90 вне форума Ответить с цитированием
Старый 29.02.2012, 16:34   #3
SPD
Пользователь
 
Регистрация: 30.11.2009
Сообщений: 41
По умолчанию

очень благодарен...
SPD вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Stringrid и Listbox ytl09 Помощь студентам 0 30.01.2011 20:06
объясните StrinGrid magnat1991 Общие вопросы C/C++ 9 26.04.2010 14:50
StrinGrid Настенька..Блонди Общие вопросы Delphi 2 15.08.2009 16:45
Печать Stringrid в FastReport LIEN Компоненты Delphi 2 25.05.2009 11:18