TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
TWAIN Support in ObjectPAL, Part 4: Samples, Advanced Techniques, and Appendices
 
   
by Paul Cronk 
 Posted: 1 July 2001
 
   
 
 Applies to: Paradox 10
 
   
 
Audience: Developers
 
       
   

Note: This is Part 4 of 4. You can also:

Sample Project

The sample files described in this section are available here.

Picture Saver

The Picture Saver application mimics a photo-album. It contains thumbnails of all the pictures stored in a table. The table has two fields, the first the key field, and the second a path and filename of the graphic. Graphics are generally not stored in tables since the BDE expands graphic files into bitmaps before storing the graphic. Graphics may have been acquired into a .jpg or .gif format, and thus, the difference in file size warrants special handling of the graphics. In the Picture Saver application, we store the graphic outside of the table, and store the filename in the table.

Picture Saver Startup Script

Abstract: The Picture Saver script sets the alias for the application and calls the main form. Use the startup script to ensure that the 'PictureSaver' alias is set before reviewing the samples.

Uses: nothing

Picture Saver Dialog

Abstract: The Picture Saver dialog contains a thumbnail view of the pictures in the photo album. To accomplish the thumbnail view, we place the key field and a graphic object in a multi-record object. On the newvalue() event of the key field, we load the appropriate graphic from the file, and assign it to the graphic object.

The dialog has one button, labeled Add, which calls the Add Picture dialog.

Uses: isTwainAvailable()

Add Picture Dialog

Abstract: The Add Picture Dialog is used to acquire images from a data source, or to import images into the table. The Select Source button brings up the Picture Saver Select Source dialog.

Uses: open(), close(), setSource(), acquire()

Select Source Dialog

Abstract: Our Select Source dialog mimics the behavior and operations of the Select Source dialog displayed by source manager. In this dialog, we ask the source manager for a list of data sources, and populate a list box with them. The code has an OK and a Cancel button, and returns the name of the data source selected.

Uses: open(), close(), enumSourceNames(), getSourceCount(), getDefaultSource()

Advanced Techniques

The samples in this article use some advanced techniques which should be explored while designing a TWAIN implementation. These techniques are not mandatory for any TWAIN enabled application. If the application does not employ the advanced techniques, the application will still function.

Saving the Application Default Source

Code should never rely on the system default source for acquisition. A straight acquire() could acquire from a different source than expected, and thus yield unexpected results. By creating and maintaining the default source for the application, this prevents users from acquiring from unwanted or unsupported sources. This concept can be expanded to include user default sources as well.

Handling Graphics

Graphics require special handling. When a graphic is read from a file, the file is converted from its original format to a native bitmap form. This is typical in other applications. In Paradox 10, graphics can be exported to disk in more compressed formats, such as GIF, and JPEG. The largest advantage by leveraging the new graphic features in Paradox 10 is size.

Graphics are generally not stored in tables since the BDE expands graphic files into bitmaps before storing the graphic. Thus, if a developer reads an item into a graphic object, and places the graphic object into the table, the internal format of the file is not preserved. This causes the table to grow increasingly large with each graphic. By storing the filename of the graphic object as a reference to the graphic, the size of the table is reduced, and the number of entries is only limited to the size of the drive where the table is located.

Setting the System Default Source

One trick to get the default TWAIN source without showing the Select Source dialog is to read the profile entries that correspond to the default data source. The filename is stored in the 'Default Source' entry of 'TWAIN' section of in the 'win.ini' file.

strDSFileName =
   readProfileString( "win.ini", "TWAIN", "Default Source" )

returns the complete path and filename of the system default data source. It is then left up to the developer to equate the friendly name displayed in the Select Source dialog to the filename returned from the above function.

Conversely, the code

writeProfileString( "win.ini", "TWAIN",
                    "Default Source", "digicam.ds")

writes the filename of a data source to the windows profile. The onus is on the developer to ensure the filename exists on the local machine.

The TWAIN Working Group does not support these methods of getting and setting the default data source. If the system data source changes in the midst of a twain session, it is conceivable that the user could acquire from a different data source than the one selected. Thus, the only supported means of setting and getting the system data source is through the source manager.

Caveats with TWAIN support in ObjectPAL

With the current implementation of Paradox 10 SP1, the function twain.acquire( var gr graphic, var bShow Logical) does not work as documented. However, one could acquire to a file, then perform a graphic.readFromFile() method after the acquisition was complete to achieve the same results.

The table view has no user interface for acquiring images. This appears to be an oversight in the original implementation.

The function twain.isAssigned() is not documented in the help.

The documentation for TWAIN support is quite limited, and in most cases incorrect. Most of the arguments are actually of const type, not var. The help does not automatically point to the correct help panel from the source code window.

Paradox is not capable of handling 32bit graphic images to graphic objects, or graphic field objects. If a 32bit image is acquired to one of these objects, the image will appear slanted, or distorted. 32bit images can be acquired to a file successfully. In general, applications should not acquire images greater than 24bits to adhere to the limitations of Paradox.

Paradox can only receive one image per acquisition. Acquiring multiple images, such as time-lapsed stills, or a roll of film on a digital camera cannot be performed using the Paradox TWAIN implementation. This is working as designed. To acquire time-lapsed stills, perform an acquire with no UI, sleep for a period of time, and acquire the next image. This gives the flexibility of posting a record, or storing the image on disk before the next acquisition takes place.

Where can I find more information about TWAIN?

The TWAIN working group can be found on the web, at www.twain.org.

Appendices

Revision History

DateVersionAuthorDescription
01-July-20011.2Paul Cronk2nd revision
28-June-20011.1Paul Cronk1st revision
07-June-20011.0Paul CronkInitial draft

Reviewers

  • Dennis Santoro, Resource Development Associates
  • Steve Caple, AT&T
  • Oak Hall, NeuMedia
  • Tony McGuire, DirectConnect

Return to Index

Previous: Part 3: TWAIN Function Reference

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 05 June 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]