Consultancy and Programming
Advice, tips, techniques and downloads for Visual Foxpro developers.
One of the more difficult tasks in a Visual FoxPro development project is keeping track of the many icons, bitmaps and other graphic files that you use in the application. In a typical project, you probably use hundreds - even thousands - of these files. You use them for the Icon property of your forms, for the Picture property of your command buttons, and in many other places where you want to add interest and visual effect to your interface. Some of the files will be ICOs, others will be BMPs, GIFs, JPGs or any other of the 17 graphic formats that VFP natively supports.
Managing these files is a headache. In our own projects, we typically test several different icons for a particular function, then forget to delete the ones we rejected, resulting in unwanted files cluttering the directory. When working in a multi-programmer team, we often find that each programmer chooses his or her own graphics, so we end up with different images being used for the same purpose. And if a graphic file goes missing, we sometimes only find out about it when a user complains.
To help solve these and related problems, we've created a simple Review Bitmaps utility that compares the graphic files in your project directories with those that are actually used in the application. This is a great tool for helping get rid of the unused files that clutter up a typical bitmaps folder. It's also very useful for identifying missing files, and for generally keeping track of which bitmap files contain which images. (We use the term 'bitmaps' here to mean any icon or graphic files, not just those in Windows Bitmap [BMP] format.)
As with all the utilities and components in Foxstuff, the Review Bitmaps tool is completely free. Just follow the link below to download it. Note that Review Bitmaps requires VFP 8.0 or above.
Installing Review Bitmaps is trivial. Just unpack the downloaded file to a suitable directory on your development machine. Once you've done that, proceed as follows:
In order for Review Bitmaps to do anything useful, it has to know which graphic files are referenced from the code in your application. Rather than searching your programs, forms and classes itself for that information, it relies on VFP's Code References tool to do the job.
So the first step in using Review Bitmaps is to launch Code References. You can do that from the VFP Tools menu, but it's easier to do it by clicking the hyperlink near the top of the form. When you do, Review Bitmaps will automatically enter the required search string in the Look For box, as shown in Figure 2.
Next, make the following settings in Code References:
If you launched Code References from the Tools menu, you will also have to enter the search string, which is as follows:
(\.ani)|(\.bmp)|(\.cur)|(\.dib)|(\.emf)|(\.exif)| (\.gif)|(\.gfa)|(\.ico)|(\.jpg)|(\.jpeg)|(\.jpe)| (\.jfif)|(\.png)|(\.tif)|(\.tiff)|(\.wmf)
This is a regular expression that locates filenames with any of the extensions applicable to graphic files. Note that, in this web page, the search string has been split over three lines to improve readability. You should enter it in the Look In box as a single string.
Next, go ahead and run the search.
When the search has finished, export the results to a DBF file of your choice. To do so, click the Export button on the Code References toolbar, select Visual FoxPro Table (DBF) as the output file type, and specify the filename to hold the exported results.
At this point, you can close Code References.
Back in the Review Bitmaps form, enter the path and filename of the export file that you just created, and the path of the directory containing your application's graphics files. Tick the 'Include subfolders' checkbox if applicable.
Review Bitmaps offers three outputs:
To obtain any of the above outputs, just press the appropriate button on the form.
We have found Review Bitmaps to be an enormous help in our own projects, but it's not perfect. In some cases, Code References will fail to identify a graphics file - often because its name is constructed dynamically in the program code. In those cases, Review Bitmaps will incorrectly report that the file in question is unused.
Code References might also flag what it thinks is a graphics file but is in fact something else. For example, if your code refers to an object named Report that has property called BMP, any references to Report.BMP will be treated as a filename. This will lead Review Bitmaps to mistakenly report a missing file.
For these reasons, you should interpret the output from Review Bitmaps with care. In particular, be careful not to permanently delete any file unless you know for sure that it's not needed.
To download the utility, simply click on this link:
The download file is named review_bitmaps.zip, and is just 26 KB.
Mike Lewis Consultants Ltd. June 2006.
FoxStuff is maintained by Mike Lewis Consultants Ltd. as a service to the VFP community. Feel free to download and use any code or components, and to pass around copies of the articles (but please do not remove our copyright notices or disclaimers).
The information given on this site has been carefully checked and is believed to be correct, but no legal liability can be accepted for its use. Do not use code, components or techniques unless you are satisfied that they will work correctly in your applications.
© Copyright Mike Lewis Consultants Ltd.