Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorrect appearance of bitmap from a general field

Status
Not open for further replies.

grahamrhind

Technical User
Jul 8, 2003
99
A1
In VFP 6, using this code:

APPEND GENERAL logofile FROM 'EGU2005-LOGO.BMP'

I am adding a bitmap file to a general field in a database. In a form I have added an OLEBoundControl with as contolsource logofile (the name of the general field). However, on the screen the bitmap appears with its file name. I.e., it appears with the text "EGU2005-LOGO.BMP" beneath it. The same applies when adding it to a report with the source of the OLE as the general field name.

Am I missing something obvious? How can one prevent the field name appearing in the bitmap?

Thanks in advance!
 
My guess is that whatever program is associated with .bmp files on your system is what is putting up the caption.

Try clearing out the logofile field by issuing:
Code:
APPEND GENERAL logofile

Then do:
Code:
APPEND GENERAL logofile FROM "EGU2005-LOGO.BMP" CLASS "Paint.Picture"

This will make OLE associate this bmp with MS Paint which should not add the caption.

Hope this helps.

Ed

Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
Thanks Ed. Unfortunately, this hasn't resolved the problem. Any other input would be much appreciated.
 
Additional to information already provided, running the code on a different machine, without ACD (which is the graphics program associated with BMP files on this machine), the bitmaps appear correctly.
 
grahamrhind,

what program is associated to BMP on the machine it works?
That (better: it's GUID/CLSID) is coded within the general field. Therefore these kind of errors occur, if different programs are associated with a certain file type.

It's better not to use general fields therefore.

You may store the file in a binary memo field and then save to disk when the file is needed or just save a patch in a text field...

Bye, Olaf.
 
Thanks Olaf, and everybody's patience. I've found some code to do what Olaf suggested, but as it seems to me overly complicated and I don't understand what it's doing, I can't get it to work.

Briefly:

In the database I have added a binary memo field called logofile.

In the startup program I have added:

set proc to showlogo

In a form under a button where the user chooses the logo bitmap (always in the same directory as the program) I have:

M.logo=GETFILE('bmp','Select logo file','Open',0)
if not empty(m.logo)
dele file templogo.bmp
copy file &logo to templogo.bmp
insert into tournament (logofile) values ('templogo.bmp')
endif

That runs without error.

The showlogo.prg contains:

procedure showlogo('logofile.bmp','logofile')
set safety off
strtofile('logofile','logofile.bmp')
set safety on
return 'logofile.bmp'

The report contains an OLE container taking a picture from file with this text:

showlogo('templogo.bmp','logofile')

When I try to run the report I get

Object "Logofile" not found

I'm sure I've got quotation marks wrong all over the place. Can anybody show me what I'm doing wrong? Thanks!

 
Hi,

This is a file association problem. Save the code below to a batch file (myfile.bat) and run it - it will reassociate bitmaps with paint.

Code:
REM Restore Default File Associations for Windows XP.
REM Copyright 2003 - Doug Knox
REM This BAT file restores the Default associations that XP ships with
REM It does not restore associations created by 3rd party applications.

Echo Restoring Default File Associations

assoc.bmp=Paint.Picture

Echo Default File Associations Restored

Regards

Griff
Keep [Smile]ing
 
Well, your first program just copies any bmp file, which was choosen to a file called "templogo.bmp" and then stores the filename templogo.bmp to a field logofile of the table tournament.

I can't see how that corresponds to the second code, which creates a file logofile.bmp, to which the string 'logofile' is saved. In what way should that work? For showing a picture it must be set as a property of an image control...

If having an Image control on your form you just need to set it's picture property to a full path of a picture, so storing paths may be sufficient. And if you want the pictures to be in the database, store them with APPEND MEMO memofieldname FROM ("filename") OVERWRITE into the memo field (once! not everytime) and when you need to display an image copy it back to disk with COPY MEMO memofieldname TO ("filename") and point the picture property to that (temp)file.

Bye, Olaf.




 
I started by having problems with a file name appearing in a bitmap stored in a general field. This was due to the file associations on that PC, and changing the associations is not an option. The advantage of this method was that, though the bitmap looked incorrect, it changed in the reports as the users changed their logos, as the bitmap was stored in a field and the OLE control in the report pointed to that field.

Secondly, I tried simply using a bitmap called "templogo.bmp" on all the reports. When the user chooses a bitmap, the bitmap is copied to that file name. That works fine, but the report embeds the bitmap as it was when the OLE control is put onto the report. I.e. the bitmap in the report doesn't change as the bitmap on the disk does.

On the basis of your first post, Olaf, I went searching for how to do this, as I don't understand really what you were saying, and found a post at which suggested a way. That was what I was trying to do, and failing miserably, with my next post in this thread.

The problem really is getting the picture as embedded in the report to be able to be changed at the whim of the user. My attempts up to now to point to a field have failed because of the GENERAL type issues, and attempts at pointing to a file on disk means that the logo can't be changed by successive users. I'll try to point the OLE control at a MEMO field instead of the GENERAL field and see if that works. Anyway, this might make clearer what I'm trying to do :-(
 
RESOLUTION:
Fishing around, it seems that this question is answered very commonly and not often resolved (or, not in a way that I could understand it), so as I now have a solution for my needs, here is the answer:

1) In a table (in my case TOURNAMENT) add a character field long enough to hold a full path and file name - called, in my case, LOGOFILE

2) To fill this field with the path to the desired logo,add this coding (or similar) under a button on a form:

M.logo=GETFILE('bmp','Select logo file','Open',0)
if not empty(m.logo)
replace logofile with m.logo
endif

The stores the full path to TOURNAMENT.LOGOFILE

3) In the report which is to have the dynamic image, add an OLE control. Choose the FILE radio button. In the field next to it give the field name containing the path to the image, i.e. TOURNAMENT.LOGOFILE

Works a treat!

Now I have to find out how to get the same dynamism of the image on my form ...... any ideas?
 
Resolved that one too! I simply altered the code under the form button in this way:

M.logo=GETFILE('bmp','Select logo file','Open',0)
if not empty(m.logo)
replace logofile with m.logo
thisform.image1.picture=tournament.logofile
endif

Simple stuff, perhaps, but it makes me happy ;-)
 
Your solution is nearly correct however if your app is a network app it will not work!!

The stored path returned by getfile() on one machine means nothing to another client machine and that second user will not be able to find yr bmp file. We resolve this by pulling ALL pictures/logos etc together into a picture subdir on to the server where our DBC's are stored then store this new path in the table the path is then always correct for all users and works on all forms and reports.

Bob Palmer
The most common solution is H2O!
 
Hi graham,

glad you found a solution both to a changing image on a report and form. Well, on a report you can choose to bind the OLE bound control to an file(name) or a general field, I think you did this.

You may not need to worry about bob palmer's advice, because if a user selects a filename this should work. You may make a check after GetFile() with if FILE(m.logo) instead of if !empty(m.logo), which would be a little safer.

Bye, Olaf.

 
I beg to differ Olaf,
If you are storing a path in a file on a server that may be mapped as \\server\myapps and a user uses getfile and stores a file from his local machine from say C:\my documents\my pictures <-- this path will mean absolutely nothing to a second user loggin on a different client machine!!

By pulling the files to say \\server\myapps\pictures then storing THIS path the app will always find the file no matter which client machine is running it.



Bob Palmer
The most common solution is H2O!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top