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

is image can be a variable? 3

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
0
16
PH
I have an image that is displayed on my form, that everytime i change the image with the same filename as hardcoded, it changes to the image i have created... my problem is, in the pageframe image, it doesnt change even if the filename is the name as the filename in the code... my question is, is it possible that image be dynamic even if i dnt change the code? I dont know if have explain it well but i hope you could help me... Thanks in advance...
 
I think you need to CLEAR RESOURCES if you want to be sure that the correct image is shown

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
I dont know if have explain it well

No, Mandy, I'm afraid you did not explain it well. If you will just read through what you have written, I think you'll agree that it doesn't make much sense.

However, I suspect that what you mean is that when you change the Picture property of an image control, the image does not change. If that's the case, then Griff has given you the right answer. Because of the way that images are cached, you have to clear the cache when you change the file.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
There is one more hurdle, you'll trigger the error that the file is in use, also when you SET SAFETY OFF.

What I did is COPY FILE from some specific directory to the directory referenced by the image.picture property, and that fails with error #3. That error happens because the image control uses the image COPY wants to overwrite it. That problem can be overcome by setting Picture to "" temporarily. I don't even need to CLEAR RESOURCE, but the situation differs in the EXE.

Because notice what happens when you build an EXE from your project. The image file will become a project item and be embedded into the EXE, so replacing the file nor CLEAR RESOURCES will cause an image change. The image control doesn't even load its image from the file, it loads it from the EXE.

I guess your idea is based on keeping images out of an EXE, which is possible, as you can decide for each project file to include or exclude it from the EXE. You have to do this for any image you want to be able to later read from some directory and exchange it with other files.

To get this without any blinking or flickering artifact, you should use Thisform.Lockscreen=.T., then set image.Picture="", then replace the image file, then set image.Picture back to what it was and then set Thisform.Lockscreen = .F.

I haven't thoroughly tested under which other circumstances this perhaps still fails, but before I'd deep dive into finding other problems with this, this minimum procedure of setting Picture="" temporarily actually means the whole thing is simpler by setting the image.Picture to the other file instead of copying over the file name given in the Picture property. Then you don't need to copy files.

I mean, codewise it doesn't make much of a difference if you need to program to copy some file to the file given by image.Picture, or if you simply set image.picture to the other file name. Since you need to set the picture property anyway, it's simplest to do that once, instead of doing it once to "" and back to what it as, copying a file in the meantime. Just setting image.Picture to the other file works for me, too, also without CLEAR RESOURCES, I just set form.lockscreen=.T. before changing image.Picture and then set form.lockscreen back to .F. and the picture change takes effect.

Chriss
 
I don't know if you actually think about replacing files at runtime, maybe you'd exchange a set of files with another while the EXE does not run and then restart. The only thing that you have to care for then is that the image files part of the project items are set to be not included in the build process. Otherwise you always see the images that are embedded into the EXE at build time, no matter what images are currently on HDD.

Chriss
 
Here's an idea for internationalization of images, just as an example for switching sets of images.

requirement 1: Your EXE excludes all images.
requirement 2: You have a folder per language you want to support with your application, .../en/, .../fr/, .../es/, etc. and all your application UI images load images from .../active/, then all you do to switch language (in anythingrelated to text in images) is renaming the language directory you want - for example French = .../fr/ - to .../active/ after you renamed .../active/ to its original name it was before becoming active.

This way you actually don't really copy files, you just rename directories. This should be fast, as you don't really shovel a lot of files around on HDD, you just change the directory structure.

But this only works, if no image of .../active/ is currently displayed in an image control. So before being able to make that move, your EXE should either not be running at all, i.e. you do a little separate utilitiy that runs while your EXE quits and then restarts the EXE. Or, if that's too intrusive, you would need to make use of something like SetAll to temporarily set all picture properties to the empty string, rename the two directories you need to switch and then reset all picture properties to their default value.

I guess the duo of the SetAll and ResetToDefault methods could do this, properly done with object orientation this would make it easy to switch the looks, not only depending on some language, also some theme like dark/light/high contrast styles would be doable.

Chriss
 
And Griff,

I think I remember where you never get around CLEARing RESOURCES: When it comes to images in reports. But I don't need this with image controls as far as I've played with switching images in several ways.

Chriss
 
That's how I know Chris, the community gave me an answer, I pass it on..

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top