Solved

QRDBImage print multiple records

Posted on 2008-10-19
7
1,240 Views
Last Modified: 2013-11-23
Hello,
I have an application connected with ado to an access database, in the database I have a blob field for pictures. I want to print with quickreports the 4 first records of the field on the same page but I can only print 4 times the same record on the quickrep page.
if clientdataset3.RecordCount >= 4 then
begin
form19.qrdbimage2.DataSet.RecNo := 1;
form19.qrdbimage3.DataSet.RecNo := 2;
form19.qrdbimage4.DataSet.RecNo := 3;
form19.qrdbimage5.DataSet.RecNo := 4;
form19.QuickRep1.Preview
end
else
showmessage('error there are not enough records')

Open in new window

0
Comment
Question by:kyriakos70
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 22757152
One way to do this would be to use a TQuickAbstractRep (I think this is only avail in the pro version). The advantage to using a TQuickAbstractRep is that it is not tied to a dataset therefore you can fashion a set of data and process it in any way that suits your need.

Do you have this component available?

If so, I will provide details on how I would approach this.
0
 

Author Comment

by:kyriakos70
ID: 22759130
SteveBay,
I have this component if you can tell me a way to do it.

Kyriakos
0
 

Author Comment

by:kyriakos70
ID: 22759142
SteveBay,
I have this component, if you can tell me a way to do it.

Kyriakos
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:SteveBay
ID: 22760060
It will take me a little while to put together an example. I will try to post later this evening.
0
 

Author Comment

by:kyriakos70
ID: 22760192
OK,
0
 
LVL 14

Accepted Solution

by:
SteveBay earned 500 total points
ID: 22761523
There are a lot of different ways to do this I am just showing a way that I have found that will work.
Start By:
- Creating a form and putting a TQuickAbstractRep on it.
- Place a TQRStringsBand on the TQuickAbstractRep.
- Stretch the TQRStringsBand so that it takes up the entire TQuickAbstractRep
- Place 4 TQRImage(s) on the  TQRStringsBand.
(See DFM for Form2 in the code)
- Create a BeforePrint handler for the TQRStringsBand  (See Unit2 Source)
Note that none of these QR components are data-aware. All of the data gathering and display is handled in the BeforePrint event.

Before you print you will need to populate a List of the IDs of every fourth Item in your Table. You then assign that list to the TQRStringsBand.Items property on Form2.
(see btnPreviewClick below)
Simular to the way a TQRBand prints a band for each record in a DB, the TQRStringsBand prints a band for each item in the List.

After you have a list of every forth ID the pictures will be found and loaded in the BeforePrint Event handler. (See Unit2 Source)

If this doesn't make sense let me know and will try to explain it better.

Steve


 

procedure TForm1.btnPreviewClick(Sender: TObject);
var n : Integer;
begin
     IdList := TStringList.Create;
     try
     ADOQuery1.Close;
     ADOQuery1.SQL.Clear;
     ADOQuery1.SQL.Add('SELECT ID FROM [Table1] ORDER BY ID');
     ADOQuery1.Active := True;
     n := 0;
     while not ADOQuery1.Eof do
          begin
          if (n + 4) mod 4 = 0 then
               IdList.Add(ADOQuery1.FieldByName('ID').AsString);
          ADOQuery1.Next;
          Inc(n);
          end;
     Form2.ADOQuery2 := ADOQuery2;
     form2.QRStringsBand1.Items := IdList;
     Form2.QuickAbstractRep1.Preview;
     finally
          IdList.Free;
     end;
end;
// Unit2 Source -------
 
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, QuickRpt, QRCtrls, ExtCtrls, ADODB, DB, Jpeg ;
 
type
  TForm2 = class(TForm)
    QuickAbstractRep1: TQuickAbstractRep;
    QRStringsBand1: TQRStringsBand;
    QRImage1: TQRImage;
    QRImage2: TQRImage;
    QRImage3: TQRImage;
    QRImage4: TQRImage;
    procedure QRStringsBand1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
  private
    { Private declarations }
  public
     ADOQuery2 : TADOQuery;
     IdList : TStringList;
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.QRStringsBand1BeforePrint(Sender: TQRCustomBand;  var PrintBand: Boolean);
var n : Integer;
    ms : TMemoryStream;
     procedure BlobToImage(Blob : TBlobField; Image : TQRImage);
     var jpg : TJpegImage;
     begin
          // Assumes the images are JPG 
          ms.Clear;
          Blob.SaveToStream(ms);
          ms.Position := 0;
          jpg := TJPEGImage.Create;
          jpg.LoadFromStream(ms) ;
          Image.Picture.Bitmap.Assign( jpg );
          jpg.Free;
     end;
begin
     ms := TMemoryStream.Create;
     ADOQuery2.Close;
     ADOQuery2.SQL.Clear;
     ADOQuery2.SQL.Add('SELECT TOP 4 [id],[Image] FROM [Table1]');
     ADOQuery2.SQL.Add(' WHERE [ID] >=' + TQRStringsBand(Sender).Item );
     ADOQuery2.SQL.Add('ORDER BY [ID]');
     ADOQuery2.Active := True;
     n := 0;
     QRImage1.Picture.Assign(NIL);
     QRImage2.Picture.Assign(NIL);
     QRImage3.Picture.Assign(NIL);
     QRImage4.Picture.Assign(NIL);
 
     while not ADOQuery2.Eof do
          begin
          case n of
          0: BlobToImage(TBlobField(ADOQuery2.FieldByName('Image')), QRImage1 );
          1: BlobToImage(TBlobField(ADOQuery2.FieldByName('Image')), QRImage2 );
          2: BlobToImage(TBlobField(ADOQuery2.FieldByName('Image')), QRImage3 );
          3: BlobToImage(TBlobField(ADOQuery2.FieldByName('Image')), QRImage4 );
               end; //case
          ADOQuery2.Next;
          Inc(n);
          end;
     ms.Free;
end;
 
end.
 
 
// DFM Form2 ---------- 
object Form2: TForm2
  Left = 231
  Top = 192
  Width = 870
  Height = 640
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Scaled = False
  PixelsPerInch = 96
  TextHeight = 13
  object QuickAbstractRep1: TQuickAbstractRep
    Left = 20
    Top = 8
    Width = 816
    Height = 1056
    Frame.Color = clBlack
    Frame.DrawTop = False
    Frame.DrawBottom = False
    Frame.DrawLeft = False
    Frame.DrawRight = False
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Arial'
    Font.Style = []
    Functions.Strings = (
      'PAGENUMBER'
      'COLUMNNUMBER'
      'REPORTTITLE'
      'QRSTRINGSBAND1')
    Functions.DATA = (
      '0'
      '0'
      ''''''
      '''''')
    Options = [FirstPageHeader, LastPageFooter]
    Page.Columns = 1
    Page.Orientation = poPortrait
    Page.PaperSize = Letter
    Page.Values = (
      127.000000000000000000
      2794.000000000000000000
      127.000000000000000000
      2159.000000000000000000
      127.000000000000000000
      127.000000000000000000
      0.000000000000000000)
    PrinterSettings.Copies = 1
    PrinterSettings.OutputBin = Auto
    PrinterSettings.Duplex = False
    PrinterSettings.FirstPage = 0
    PrinterSettings.LastPage = 0
    PrinterSettings.ExtendedDuplex = 0
    PrinterSettings.UseStandardprinter = False
    PrinterSettings.UseCustomBinCode = False
    PrinterSettings.CustomBinCode = 0
    PrinterSettings.UseCustomPaperCode = False
    PrinterSettings.CustomPaperCode = 0
    PrinterSettings.PrintMetaFile = False
    PrintIfEmpty = True
    Units = Inches
    Zoom = 100
    object QRStringsBand1: TQRStringsBand
      Left = 48
      Top = 48
      Width = 720
      Height = 957
      Frame.Color = clBlack
      Frame.DrawTop = False
      Frame.DrawBottom = False
      Frame.DrawLeft = False
      Frame.DrawRight = False
      AlignToBottom = False
      BeforePrint = QRStringsBand1BeforePrint
      Color = clWhite
      ForceNewColumn = False
      ForceNewPage = False
      Size.Values = (
        2532.062500000000000000
        1905.000000000000000000)
      Master = QuickAbstractRep1
      PrintBefore = False
      object QRImage1: TQRImage
        Left = 8
        Top = 28
        Width = 333
        Height = 389
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          1029.229166666667000000
          21.166666666666670000
          74.083333333333340000
          881.062500000000000000)
        Stretch = True
      end
      object QRImage2: TQRImage
        Left = 356
        Top = 28
        Width = 349
        Height = 385
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          1018.645833333333000000
          941.916666666666700000
          74.083333333333340000
          923.395833333333400000)
        Stretch = True
      end
      object QRImage3: TQRImage
        Left = 8
        Top = 432
        Width = 333
        Height = 521
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          1378.479166666667000000
          21.166666666666670000
          1143.000000000000000000
          881.062500000000000000)
        Stretch = True
      end
      object QRImage4: TQRImage
        Left = 356
        Top = 432
        Width = 349
        Height = 517
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          1367.895833333333000000
          941.916666666666700000
          1143.000000000000000000
          923.395833333333400000)
        Stretch = True
      end
    end
  end
end

Open in new window

0
 

Author Closing Comment

by:kyriakos70
ID: 31507568
Very good and understanding,excelent.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java class in read only mode in eclipse 2 168
Eclipse XML hightlightning 5 60
Delphi : could not find program, '...exe' 2 212
installing and using WTP plugin eclipse MARS 3 134
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question