DBGrid의 내용이 아래와 같다면,
PartNumber PartName PartImage
10-00001-00 test1 test1.jpg
10-00002-00 test2 test2.jpg
....
이것을 다음과 같이 파일명 대신 그림을 직접 프린터하고 싶습니다.
PartNumber PartName PartImage
10-00001-00 test1 test1.jpg그림
10-00002-00 test2 test2.jpg그림
....
델은 초보라 DBGrid의 내용을 프린터하는 방법은 Delphi3000에서 받아 사용하고 있는데 일부수정했지만 똑같은 그림(test1.jpg)만 그려집니다. 어디에 문제가 있는지 아래의 소스를 살펴주십시오.
//////////////////////////////////////////////////////////////////
procedure ?????.Preview(Grid: TDBGrid);
var
i, CurrentLeft, CurrentTop : integer;
str : string;
begin
QuickRep1.Dataset:=Grid.DataSource.DataSet;
if not QuickRep1.Bands.HasColumnHeader then
QuickRep1.Bands.HasColumnHeader:=true;
if not QuickRep1.Bands.HasDetail then
QuickRep1.Bands.HasDetail:=true;
QuickRep1.Bands.ColumnHeaderBand.Height:=Abs(Grid.TitleFont.Height) + 10;
QuickRep1.Bands.DetailBand.Height:=Abs(Grid.Font.Height) + 100;
CurrentLeft := 12;
CurrentTop := 6;
{Don't let the grid flicker while the report is running}
Grid.DataSource.DataSet.DisableControls;
try
for i:=0 to Grid.FieldCount - 2 do
begin
if (CurrentLeft + Canvas.TextWidth(Grid.Columns[i].Title.Caption)) >
(QuickRep1.Bands.ColumnHeaderBand.Width) then
begin
CurrentLeft := 12;
CurrentTop := CurrentTop + Canvas.TextHeight('A') + 6;
QuickRep1.Bands.ColumnHeaderBand.Height := QuickRep1.Bands.ColumnHeaderBand.Height +
(Canvas.TextHeight('A') + 10);
QuickRep1.Bands.DetailBand.Height := QuickRep1.Bands.DetailBand.Height +
(Canvas.TextHeight('A') + 10);
end;
{Create Header with QRLabels}
with TQRLabel.Create(QuickRep1.Bands.ColumnHeaderBand) do
begin
Parent := QuickRep1.Bands.ColumnHeaderBand;
Color := QuickRep1.Bands.ColumnHeaderBand.Color;
Left := CurrentLeft;
Top := CurrentTop;
Caption:=Grid.Columns[i].Title.Caption;
end;
{Create Detail with QRDBText}
with TQRDbText.Create(QuickRep1.Bands.DetailBand) do
begin
Parent := QuickRep1.Bands.DetailBand;
Color := QuickRep1.Bands.DetailBand.Color;
Left := CurrentLeft;
Top := CurrentTop;
Alignment:=Grid.Columns[i].Alignment;
AutoSize:=true;
AutoStretch:=true;
Width:=Grid.Columns[i].Width;
Dataset:=QuickRep1.Dataset;
DataField:=Grid.Fields[i].FieldName;
CurrentLeft:=CurrentLeft + (Grid.Columns[i].Width) + 15;
end;
end;
//편집시작
i := Grid.FieldCount - 1;
with TQRImage.Create(QuickRep1.Bands.DetailBand) do
begin
Parent := QuickRep1.Bands.DetailBand;
Color := QuickRep1.Bands.DetailBand.Color;
Left := CurrentLeft;
Top := CurrentTop;
Height := 105;
Left := 872;
Top := 1;
Width := 161;
Size.Height := 25;
Size.Left := 200;
Size.Top := 1;
Size.Width := 34;
Stretch := true;
AutoSize:=false;
str := Grid.Fields[i].AsString;
str := 'c:picture' + str
Picture.LoadFromFile(str);
end;
//편집 끝.
{After all, call the QuickRep preview method}
QuickRep1.PreviewModal; {or Preview if you prefer}
finally
with Grid.DataSource.DataSet do
begin
EnableControls;
end;
end;
end;