This article was previously published under Q155388
This article has been archived. It is offered "as is" and will no longer be updated.
The CLEAR RESOURCES command, a new command for Visual FoxPro 5.0, does notappear to work. When Visual FoxPro displays a bitmap, picture, cursor,icon, or font resource, Visual FoxPro caches the resource to optimizeperformance. If you use a resource of the same name (for example, adifferent bitmap with the same name as the one already cached), VisualFoxPro does not reload the resource.
Therefore, clearing a resource file is useful for removing a graphic imagefrom memory and forcing Visual FoxPro to reload an image of the same namefrom disk. For example, a report might display graphic images from adatabase, all of which are named TEMP; however, because they all have thesame name, Visual FoxPro does not reload each new graphic unless theexisting one has been cleared from memory using the CLEAR RESOURCEScommand.
This scenario occurs when a resource is in use when you issue the CLEARRESOURCES command.
The CLEAR RESOURCES command acts only on resources that are not currentlyinuse. In the following example, the "Toggle bitmap" button attempts to cleara resource that is in use. The click code for the "Update form" buttonsaves the current value of the picture property, sets the picture propertyto "", clears the resource (which is no longer in use), and resets thepicture property back to its original value. Note that the specificresource is cleared by name. Any remaining resources are not cleared. Theresources must be cleared because of caching for performance reasons. Youwant to clear only the resource you want to update so that any others willstill be in the cache.
This behavior is by design. CLEAR RESOURCES acts only on resources notcurrently in use.
Run the following code from a .prg:
PUBLIC oform oform=CREATEOBJECT('form1') oform.Show DEFINE Class form1 AS Form Top = 0 Left = 0 Height = 234 Width = 207 DoCreate = .T. Caption = "Clear Resource Demo" Name = "form1" changedbmp = .F. ADD OBJECT image1 AS Image WITH ; Stretch = 2, ; Height = 120, ; Left = 36, ; Top = 12, ; Width = 144, ; Name = "Image1" ADD OBJECT command1 AS CommandButton WITH ; Top = 156, ; Left = 60, ; Height = 27, ; Width = 96, ; Caption = "\<Toggle bitmap", ; Default = .T., ; Name = "Command1" ADD OBJECT command2 AS CommandButton WITH ; Top = 192, ; Left = 67, ; Height = 27, ; Width = 84, ; Caption = "\<Update form", ; Name = "Command2" PROCEDURE image1.Init Clear RESOURCES COPY FILE home()+'wizards\wizbmps\wzclose.bmp' TO 'bmptemp.bmp' THIS.Picture='bmptemp.bmp' ENDPROC PROCEDURE command1.Click IF THISFORM.changedbmp=.F. THISFORM.changedbmp=.T. COPY FILE home()+'wizards\wizbmps\wzedit.bmp' TO 'bmptemp.bmp' ELSE THISFORM.changedbmp=.F. COPY FILE home()+'wizards\wizbmps\wzclose.bmp' TO 'bmptemp.bmp' ENDIF CLEAR RESOURCES THISFORM.REFRESH ENDPROC PROCEDURE command2.Click LOCAL lcPictemp lcPictemp=thisform.image1.Picture THISFORM.image1.Picture='' CLEAR RESOURCES (lcPictemp) THISFORM.image1.Picture=lcPictemp ENDPROCENDDEFINE
Press the "Toggle bitmap" button. Note how the button does not update the image even though it contains a CLEAR RESOURCES command in its click code.
Press the "Update form" button. Now the image is updated.