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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display general field on form 1

Status
Not open for further replies.

duongduong12345

Programmer
Mar 13, 2010
9
VN
Hi all,

Please help me !

I design the form in visual fox 9.0.
I used OleBoundCotrol to design General Field, i add picture to this field by code below:

--------
Local cJPGFile

cJPGFile = Getfile('jpg')

If !Empty(cJPGFile)
Select nhan_vien
Append General hinh From (cJPGFile) LINK
= Tableupdate()
Thisform.hinh1.refresh
Endif
--------

That code is ok, i mean it can add the picture to the general field
But after i add the picture, I CAN NOT see the picture, there's only a name of picture's file.

That picture only is view when i doulbe click on this picture.
I tried to change AutoActivate in field's properties but it's not ok.

Kindly help me

NCD
 
FoxPro does not display the contents of General fields. That is turned over to the application registered to handle whatever OLE class is embedded in the general field. (A good reason to never use a general field.)

You don't have an application registered that is capable of displaying an embedded JPG. You'll need to find one. But be aware, that the results will differ on client machines when you distribute your application unless they all have the same application registered. (Another reason not to use a general field.)

FoxPro can natively display JPG files in its native Image control, so I'm wondering why you're using a general field?
 
While dan is right - as always, double check if FILE(cJPGFile).

It's much more appropriate to use Blob, an Image control and it's PictureVal property, if storing pics into a dbf at all.

Bye, Olaf.
 
Thanks Dan and Olaf,

My dbf file content employee's photo, it's not a image. So i can not use native Image control.

Any another solutions ?

NCD
 
JPGs are not images? Are you sure you know what you're saying?

Bye, Olaf.
 
My dbf file content employee's photo, it's not a image.

In fact, that's correct.

Because you are using the LINK option in APPEND GENERAL, it's not the image itself that's stored in the general field, but just a link to the image. So when you add the field to a form, you will only see the filename.

The simple solution is to remove the LINK option.

However, there is gnerally not a good idea, for several reasons. A much better solution is not to use general fields at all. Instead, store the path to the image file; add an ordinary image control to the form; and write code to set the image's Picture property as you navigate the table.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
LINK is not the culprit. I can display an image stored with LINK option. As duongduong12345 does, without sepcifying CLASS OLEclassname.

Take a look at HKEY_CLASSES_ROOT into the entry of bmp, that should have "Paint.Picture" as it's "(Standard)" REG_SZ key value besides other keys and values. I can't tell you what exactly in conjunction with what other keys make this work, but Paint.Picture is the oleclass used to display a bmp image in an ole(bound)control.

JKpg may not have such an ole class associated, therefore it doesn't work with general fields.

@duongduong12345 I never said you can display a general field with a image control. I said you use a blob field instead. You need to change your data anyway. Even if you fix your jpg registry entry the general field does neither contain the picture nor the correct link to Paint.Picture, so you just can throw your data into trash and need to start over for all employees not displaying their photo. Use a char field or memo, to store the image path and display it via an image control.

Stay away from general fields, even with LINK option.

Bye, Olaf.


 
Hi Olaf and Mike;

You're a pro.

As both of your advice. I store the path to the image file; add an ordinary image control to the form; and write code to set the image's Picture property as you navigate the table. It's done.

And i know "Stay away from general fields, even with LINK option"

Thanks so much.
NCD
 
Some more advices about general fields:

CONTRA:
Eeven if your registry is ok and your computer has the oleclasses to display the file types, moving data to another computer it can stop working.

PRO:
If you know an oleclass is available, general fields are an easy to use option for reports driven by cursors, you can put files into gen fields and let the report display via it's olecontrol. Actually the only use of gen fields.

But for images I'd rather use the file name in any case, the report olecontrol can be driven by file, too, using control source type "Image file name", setting controlsource to ALLTRIM(the field you store the file name) you can print the employee photos.

Bye, Olaf.
 
Hope its ok for me to add this or if its more appropriate, I can start a new thread:

I have looked at the advice on this thread about images on forms and tend to agree with not storing images in blob fields etc.

So I have a table with a field - imagepath1 C(80) that stores a path c:\user\lee\desktop\demoimages\test01.jpg which is stored in the above field by using:

Code:
mimagename=GETPICT("jpg")
USE MYTABLE
GO myrecordno
REPLACE IMAGEPATH1 WITH mimagename

So far so good

[ol 1]
[li]I then placed an Image control on the form and called it imagePhoto1[/li]
[li]The PictureVal was firstly changed to the field name (imagepath1)[/li]
[li]The PictureVal was secondly changed to the actual path c:\user\lee\desktop\demoimages\test01.jpg[/li]
[/ol]

When I run the form, the image is not shown either scenario.

I have also tried appending the image into a BLOB field but as I note in a previous post, you only get to see the file name (e.g. test01.jpg) which you then have to double click on to open which is not what I'm trying to achieve.

Not sure why the image is not showing, what am I missing here guys?

Thank you

Lee
 
Lee,

In the scenario you describe, you don't want to use the PictureVal property. Use the Picture property instead, and set it to the fully-qualified filename. That should do the trick.

By the way, you say your Imagepath field is C(80). Keep in mind that, in Windows, an absolute path and filename can be up to 260 characters. That suggests you might need to use a memo field instead.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike

Thank you for the response. You said,

In the scenario you describe, you don't want to use the PictureVal property. Use the Picture property instead, and set it to the fully-qualified filename. That should do the trick.

If you try to enter a variable or fieldname in that property I get an error:

Code:
"File 'mimagename' does not exist"

As I mentioned, I am trying to allow a user to select an image via the getpict() command, the path of that image will be stored in the table field disclosed, which subsequently will be displayed on the form.

I also take your point about the memo field and length of the path. I'm also trying to look for a sollution to overcome the space between the actual path of the image when selected e.g. c:\myfolder\demo images\test1.jpg against c:\myfolder\demoimages\test1.jpg without the space between demo and images. I'll research that one!

Cheers Mike

Lee
 
Lee,

In your example, mimagename is the name of a variable that holds the filename. What you need to store in the Picture property is the actual filename, not the name of the variable. This is probably just a question of not delimiting the name with quotes.

So, your code probably needs to be something like this:

Code:
mimagename=GETPICT("jpg")
IF NOT EMPTY(mimagename)
  Thisform.Image1.Picture = mimagename
ELSE
  * user canceleed Open Picture dialogue
ENDIF

Of course, you can also store the name in MyTable.ImagePath1 if you wish. You know how to do that.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

Sorry Mike, I'm not having much luck with what seems to be a very simple process. This is what I have:

A form (Oh yes!)
On that form is an image control (Called image1 as I've created a blank form just to try this out)
I run a piece of code:

Code:
mimagename=GETPICT("jpg")
USE MYTABLE
GO myrecordno
REPLACE IMAGEPATH1 WITH mimagename  && Image path looks like c:\user\lee\desktop\demoimages\test01.jpg (With no quotes)
?mimagename  && Shows no quotes either side of the stored variable
WAIT WINDOW

* The form I run has the following code in the INIT procedure:

Code:
IF NOT EMPTY(mimagename)
  Thisform.image1.picture=mimagename
ENDIF

* Now run the form

DO FORM myform WITH mimagename

Error: Image1 is a method, event, or object

This is staring me in the face (I'm sure)

Thank you


Lee


 

Ah found it!

Code:
Thisform.pageframe1.page5.image1.Picture=mimagename1

It appears that the reason I was pulling my hair out with this is because the image was on a pageframe [mad]

All sorted and thanks again for the help guys


Lee
 
And to overcome the issue where a path to an image or the image itself has spaces betweens the words for example:

c:\my folder\my images\test image 3.jpg

If it helps anyone, here is the code I placed in a command button on my form:

Code:
nmessage=MESSAGEBOX("Add or Change NIR image 1?"+SPACE(10),4+32+0,"System Message")
IF nmessage=7
  RETURN 0
ENDIF
	
mimagename1=GETPICT("jpg")
lcfile1 = "&mimagename1"
REPLACE IMAGEPATH1 WITH ALLTRIM(mimagename1)

IF NOT EMPTY(mimagename1)
  Thisform.pageframe1.page5.image1.Picture=IMAGEPATH1
ENDIF

thisform.pageframe1.page5.Refresh

The answer is always out there somewhere (assuming you get the help and inspiration from these Tek-Tip guys!)

Thanks again

Lee
 
Lee,

Glad you've got it working.

There are a few points worth mentioning (none of them serious):

1. In the code that gave "Error: Image1 is a method, event, or object" (as posted by you at 24 Jun 12 13:47, above), you were trying to reference the control on the form before you had instantiated the form. Hence the error - although you're right about needing to reference the pageframe too.

2. You don't need to take any special action to deal with spaces in the path. That's only an issue when the path/filename is used literally in a command, such as in USE. In any case, ALLTRIM() doesn't get rid of the internal spaces; it only removes the spaces at the start and end (which is still a good thing to do).

3. In the last bit of code you posted above, it might be a good idea to test for an empty filename immediately after the call to GETPICT(), in other words before you update the table. The point is that the user might have reached the GEPICT() dialogue by accident, and merely cancelling that dialogue shouldn't cause data in the table to be overwritten.

4. Also in your last bit of code, the line lcfile1 = "&mimagename1" is redundant. You can achieve the same result more simply with lcfile1 = mimagename1. In any case, you don't appear to be using lcFile1.

These points are all fairly minor. I mention them only to help you understand the code a bit beteter. The main point is that you have solved the original problem.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike

As always, many thanks for the clear and comprehensive advice.

The way you post your information allows users like me, to get a better (and clearer) understanding of this fantastic program VFP9!

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top