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

Adding existing code to a form so additional table fields can be added 1

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
334
GB
In a follow up to a previous question ( I would like to add the working code below to a form so I can add some additional fields from a table to it.

Kindly resolved by Chriss, this is what I have now:

Code:
Public oForm
oForm = Createobject("Images")
oForm.Show()

Define Class images As Form
  Height=450
  Width=450
  AutoCenter = .T.
  BorderStyle = 2

  Add Object myImage As Image With ;
    Left = 10,Top=10,Height=430,Width=430,OLEDropMode=1,Stretch=1

  Procedure myImage.OLEDragOver
    Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState

    If m.nState = 0 And oDataObject.GetFormat( 15 )
      This.OLEDropEffects = 5
      This.OLEDropHasData = 1
    Else
      This.OLEDropEffects = 0
      This.OLEDropHasData = 0
    Endif
  Endproc

  Procedure myImage.OLEDragDrop
    Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
	If oDataObject.GetFormat( 15 )
	    Local Array laData[1]
	    oDataObject.GetData(15,@laData)
 
	    [b]APPEND MEMO PHOTO FROM laData[1][/b]
	    This.PictureVal = Photo
       ENDIF

Endproc
Enddefine

From here I have tried to create a form by:

[ul]
[li]Modify form IMAGES[/li]
[li]Added a table to the dataenvironment[/li]
[li]Added an image control called myImage[/li]
[li]Added the below to the myImage procedure OLEDragOver[/li]
[/ul]

Code:
Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState

If m.nState = 0 And oDataObject.GetFormat( 15 )
  This.OLEDropEffects = 5
  This.OLEDropHasData = 1
Else
  This.OLEDropEffects = 0
  This.OLEDropHasData = 0
Endif

Adding the below to the myImage procedure OLEDragDrop

Code:
Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
  If oDataObject.GetFormat( 15 )
    Local Array laData[1]
    oDataObject.GetData(15,@laData)
 
    APPEND MEMO PHOTO FROM laData[1]
    This.PictureVal = Photo
  Endif

I have also changed the image control to OLEDropMode=1 and Stretch=1 (for isometric).

When I run the form and try to drag over and image and drop it from a windows folder, it works with the original code but doesn't allow me on the form I'm trying to create.

What am I missing please?

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Since Ole Drag&Drop does not work there's something missing on the level of the form or any control, which you'll find in the original form.

So can you post your original form? You can get the full code of it with the help of the Object Browser and its view code in the toolbar.

There's also a fully functional Ole Drag&Drop example in the solution samples, which includes dragging files from explorer to a form.



Chriss
 
You also have two simpler options: Copy the form files (scx+sct) and rename the copies, then you have the ideentical form to start with and can modify exxtend it.

Or open the original form, choose save as class from the file menu, let current form be checked and then pick or write in the name of a class library file (vcx), you may not have one, so create it here, forms.vcx, for example. And then name the formclass, imageform, for example.

You can then create another form based on the class by doing CREATE FORM NewForm.scx AS imageform of myforms.vcx (with the full path to the vcx, perhaps, if it's not in the current directory.

That way you also can be sure everything of the old form is in the new form.

The form based on the class will not allow you to delete anything that's part of the class, as that's all in the class inherited and not owned by the form itself. So to get rid of something you'd need to modify the class, it's just as easy as modifying the form, the class designer for forms is the same as the form designer. So this way you can tidy up the class to only have the bare minimum for the image drag&drop. And you can use that as template for any other image form with other tables.

If you are at the stage of Save as class, you'll notice the dialog will allow you to make a separate data environment class. That's because for classes have no dataenvironment. So you can do that and create a separate data environment class and combine them to let the secondary form also get the same data, or you recreate the D by adding the images dbf. But this also goes back to what I wanted to teach about encapsulation and single-responsibility. You could now use deifferent ddataenvironments with the same form class, also with any scx which does not make use of its own DE, you can set the DE and as you can do so for a set of forms, you can have a formset that uses the same data, albeit it's not becoming a formset, which are really a bad feature of VFP. And you can edit the base DE class to make changes to all the forms, which each might have a private datasession, but share the tables they use.



Chriss
 
Wow!

Thanks Chriss. I’ll post back when I’ve looked into this.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Chriss

Since Ole Drag&Drop does not work there's something missing on the level of the form or any control, which you'll find in the original form.

A check with the settings for the image properties found that I had not set OLEDropMode to 1 - Enabled.

My form is now workng perfectly which has also allowed me to add the addtional fields from a table to my form.

Your time has been very much appreciated.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top