Sharing Images Among Reports

You can place logos and other images in a report by using only the PRINT-IMAGE command. However, the DECLARE-IMAGE command is useful if you want several programs to share the definition of an image.

The ex12c.sqr program prints a simple form letter. It shows how to print a logo by using the DECLARE-IMAGE and PRINT-IMAGE commands and how to print a signature by using only PRINT-IMAGE.

Because the image is shared among several reports, the DECLARE-IMAGE command is contained in the acme.inc file:

File acme.inc 
declare-image acme_logo
       type=bmp-file
       image-size=(30,7)
       source='acmelogo.bmp'
end-declare

This file declares an image with acme-logo as the name. It specifies the logo that is used in the previous sample program. The declaration includes the type and source file for the image. When the image is printed, you do not need to specify these attributes again.

Multiple programs can share the declaration and include the acme.inc file. If you later need to change an attribute, such as the source, you need to change it in only one place. The image size is specified and provides the default.

To change the size of an image in a particular report, use the IMAGE-SIZE argument of the PRINT-IMAGE command. It overrides the image size that is specified in DECLARE-IMAGE.

Program ex12c.sqr
begin-setup
#include 'acme.inc'
end-setup
begin-program
  do main
end-program
begin-procedure main
begin-select
name
addr1
addr2
city
state
zip
phone
  do write_letter
from customers
order by name
end-select
end-procedure ! main
begin-procedure write_letter
move &city to $csz
concat ', ' with $csz
concat &state with $csz
concat ' ' with $csz
move &zip to $zip xxxxx-xxxx
concat $zip with $csz 
move &phone to $phone_no (xxx)bxxx-xxxx   ! Edit phone number.
begin-document (1,1,0)
&name                                            @logo
&addr1
&addr2
$csz
.b
.b
.b
                                                $current-date
Dear &name
.b
     Thank you for your inquiry regarding Encore, Maestro!!, our revolutionary
teaching system for piano and organ. If you've always wanted to play an 
instrument but felt you could never master one, Encore, Maestro!! is made for 
you.
.b
     Now anyone who can hum a tune can play one too. Encore, Maestro!! begins 
with a step-by-step approach to some of America's favorite songs. You'll learn
the correct keyboarding while hearing the sounds you make through the 
headphones provided with the Encore, Maestro!! system. From there, you'll  
advance to intricate compositions with dazzling melodic runs. Encore, Maestro!!
can even teach you to improvise your own solos.
.b
     Whether you like classical, jazz, pop, or blues, Encore, Maestro!! is the 
music teacher for you.
.b
     A local representative will be calling you at $phone_no 
to set up an in-house demonstration, so get ready to play your favorite tunes!!
.b
                                Sincerely,
                                @signature
.b
.b
                                Clark Axelotle
end-document
position () @logo
print-image acme-logo ()
  image-size=(16,4)
position () @signature
print-image ()
  type=bmp-file
  image-size=(12,3)
  source='clark.bmp'   
new-page
end-procedure ! write_letter

The #INCLUDE command, which is performed at compile time, gets text from another file. In this program, the #INCLUDE 'acme.inc' command includes the code from the acme.inc file.

The document paragraph begins with a BEGIN-DOCUMENT command and ends with an END-DOCUMENT command. It uses variables and document markers to print inside the letter. The program uses variables for the name and address, the date, and the phone number. It uses document markers for the logo and signature.

Document markers are placeholders in the letter. The program uses the @logo and @signature document markers in a POSITION command before printing each image. The document markers make unnecessary specifying the position of these items in the PRINT-IMAGE command. Instead, you print to the current position.

The date is prepared with the $current-date reserved variable. It is printed directly in the document paragraph without issuing a PRINT command.

The program uses the CONCAT command to put together the city, state, and zip code. In the document paragraph, variables retain their predefined sizes. A column variable, for example, remains the width of the column as defined in the database. You can print the date and phone number directly, however, because they occur at the end of a line, without any following text.