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!

Generic programming for creating a form that can be embedded on other modal forms to upload images. 4

Status
Not open for further replies.

A Beginner

Programmer
Apr 15, 2017
81
IN
I Want to Create a form programmatically(a generic program) that could be embedded on any other modal form having grid for uploading images.
How to deploy the idea in a very simplistic way?
The visual portion being Cool and light layout.

Thank you
 
Welcome to Visual Foxpro and this forum.

One thing to understand is that we don't GIVE you the code to accomplish a task.
Instead, in order to help YOU LEARN to DO IT YOURSELF, we provide Advice and/or Suggestions on how to approach individual challenges.

You don't seem to be asking a single finite question above - so how could we respond to it?

If your finite question is:
How to deploy the idea in a very simplistic way?
You could build a Form as a Class and then use that Class in your other VFP Applications.

To learn some of the basics of VFP, you might want to spend some time looking at the free on-line VFP Tutorial Videos at:

If you come back with a single finite question we would be glad to advise you.

Good Luck,
JRB-Bldr
 
I agree with JRB. Your question is much too broad. We will help you with specific problems, but we are not here to write your code or to work out your strategy.

In addition, you ask how to "create a form programmatically ... that could be embedded on any other modal form". You can't embed one form on another. That doesn't make sense. One form call call another form, but it's not clear that is what you want.

In general, to create a form programmatically, you should look at the DEFINE CLASS command. That will let you create a form class programatically. You can then use CREATEOBJECT() to create a form based on that class.

As for having a "grid to upload images", that doesn't make a lot of sense either. Grids are used to display data, not for uploading things. In any case, where would you upload these images to?

If you would take the trouble to clarify your question, we will do our best to help.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You have to learn the basic concepts of OOP and then take a look at your possibilities to "grow" forms in a class hierarchy, where you have several base forms encapsulating base functionality, but in themselves incomplete and unusable, rather just abstract classes, that are more and more specialized into the level of the last class hierarchy level, the leaf node classes of the class inheritance tree, which are the forms you run. Eg a base search form you specialize to a customer search form, order search form and such. A base list form you specialize to become a customer- or order list form, a base edit form you specialize to a customer- or order edit form.

This constitutes three simple two level class trees with a root and each two leaf node forms. The base search, list or edit forms would not be used. The base search form may only have a search "submit" button and nothing else on it and obviously in itself is useless but is the general interface for any search. The list form will have a grid or list box for listing anything not yet defined on the base level and the edit form will perhaps even be empty but have a set of methods to load and save, just the most general outset of what any search, listing or editing means.

On the other side, you can define modules or components using the container base class. Containers simply contain any set of controls, just like a form, but without border, title bar and such things. You can even let the container be borderless and transparent itself, so it only is an organizational outer, well, container, of the things you put together to a certain component. Then you can put that on a form, also at runtime.

If you want to go in that direction of development, take a look at application frameworks, they already have sets of such classes and components. Since VFP is an abandoned language, I don't know any framework you can still buy, but there are some made freely available, eg
Bye, Olaf.
 
Thank you all in Trinity.
I think I will have to define the class as container finally before calling it on any form.
But before that, in order to visualize the class in it's construction process ie. adding object and viewing the effect, changing property and viewing the effect I will have to define it as form, isn't it?
For now I am going through foxy classes as guided by Olaf(lot of thanks).
 
By upload what I meant, let me clear:
There is an askingrid on the form that is taking the entries of products (ie. it is taking product description). There I want to attach the images of the product in the concerned table. The form should also show the image of the product if the image is available.
This is the idea behind.
I am not seeking for code but just seeking a push to proceed in write direction.
Thank you.
 
But before that, in order to visualize the class in it's construction process ie. adding object and viewing the effect, changing property and viewing the effect I will have to define it as form, isn't it?

Here's something you can do:

1. Create the form in the Form Designer. You don't have to make it exactly as you want the finished product. Just do enough so that you can visualise its main features.

2. Save the form. Close the designer.

3. Open the Class Browser (from the Tools menu).

4. Click the Open button (in the Class Browser's toolbar), set the File to Type to Form, and open the form that you saved above.

5. Click the View Code button (the 4th button on the toolbar in the Class Browser). You will now see a code window with all the code needed to create the form.

6. Use File / Save As to save the above code in a PRG.

If you look at the PRG, you will see that it contains a complete class definition for the form, along with the code needed to instantiate it. You can modify that code to get the actual form that you want, then incorporate it into your application.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you Mike.
I have created a small form.
The code is as follows:

PUBLIC oimgupload

oimgupload=NEWOBJECT("imgupload")
oimgupload.Show
RETURN


**************************************************
*-- Form: imgupload (c:\users\aspire\documents\visual foxpro projects\import.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 05/29/17 02:34:09 PM
*
DEFINE CLASS imgupload AS form


Top = 0
Left = 0
DoCreate = .T.
Caption = "Upload Image"
Name = "ImgUpload"


ADD OBJECT shp AS shape WITH ;
Top = 12, ;
Left = 36, ;
Height = 217, ;
Width = 313, ;
Curvature = 10, ;
BackColor = RGB(215,227,234), ;
BorderColor = RGB(181,221,221), ;
Name = "Shp"


ADD OBJECT cmdbtn AS commandbutton WITH ;
Top = 189, ;
Left = 265, ;
Height = 27, ;
Width = 72, ;
Caption = "Upload", ;
Name = "cmdBtn"


ADD OBJECT lbluploadfile AS label WITH ;
AutoSize = .T., ;
FontBold = .T., ;
FontSize = 16, ;
BackStyle = 0, ;
Caption = "Upload File ", ;
Height = 27, ;
Left = 48, ;
Top = 24, ;
Width = 119, ;
Name = "lblUploadFile"


ADD OBJECT lbldb AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Database:", ;
Height = 17, ;
Left = 61, ;
Top = 76, ;
Width = 59, ;
Name = "lblDb"


ADD OBJECT lbltbl AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Table:", ;
Height = 17, ;
Left = 61, ;
Top = 112, ;
Width = 36, ;
Name = "lblTbl"


ADD OBJECT lblbw AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Browse:", ;
Height = 17, ;
Left = 61, ;
Top = 148, ;
Width = 47, ;
Name = "lblBw"


ADD OBJECT txtdb AS textbox WITH ;
BorderStyle = 1, ;
Height = 24, ;
Left = 133, ;
Top = 72, ;
Width = 193, ;
ColorSource = 4, ;
Name = "txtDb"


ADD OBJECT txttbl AS textbox WITH ;
Height = 25, ;
Left = 133, ;
Top = 108, ;
Width = 193, ;
Name = "txtTbl"


ADD OBJECT txtbw AS textbox WITH ;
Height = 25, ;
Left = 133, ;
Top = 144, ;
Width = 193, ;
Name = "txtBw"


ENDDEFINE
*
*-- EndDefine: imgupload
**************************************************

Now defining variables for top, left, width and heightI am trying to make it generic.


 
Now defining variables for top, left, width and heightI am trying to make it generic.

I'm not sure if that's a question or a statement.

But in general, if you want to vary the form's size and position programmatically, then use the code that you showed. But set the Top, Left, Height and Width properties after you instatiate the form but before you make it visible. In other words:

Code:
oimgupload=NEWOBJECT("imgupload")
[b]oimgupload.Top = 20
oimgupload.Left = 40
* etc. etc.[/b]
oimgupload.Show
RETURN

Obviously, you can set the properties to equal a variable just as easily.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I am Sorry Mike as I couldn't see the last post of yours.
I have adjusted the left and top of all form objects based on the dimensions of Thisform. Is this ok or a more generic way would be to make it based on form objects. If later is true then how to refer to the form objects?
My code at the moment is as follows-
Code:
LPARAMETERS tnTop,tnLeft,tnHeight,tnWidth

PRIVATE pnTop,pnLeft,pnHeight,pnWidth
pnTop = IIF(EMPTY(tnTop),100,tnTop)
pnLeft = IIF(EMPTY(tnLeft),300,tnLeft)
pnHeight = IIF(EMPTY(tnHeight),250,tnHeight)
pnWidth= IIF(EMPTY(tnWidth),400,tnWidth)


PUBLIC oimgupload

oimgupload=NEWOBJECT("imgupload")
oimgupload.Show
RETURN


	**************************************************
*-- Form:         imgupload (c:\users\aspire\documents\visual foxpro projects\import.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   05/29/17 02:49:10 PM
*
DEFINE CLASS imgupload AS form


	Top = pnTop && 0
	Left = pnLeft && 0
	Height = pnHeight && 263
	Width = pnWidth && 408
	DoCreate = .T.
	Caption = "Upload Image"
	Name = "ImgUpload"


	ADD OBJECT shp AS shape WITH ;
		Top = pnTop+10, ;
		Left = pnLeft+10, ;
		Height = pnHeight-40, ;
		Width = pnWidth-20, ;
		Curvature = 10, ;
		BackColor = RGB(215,227,234), ;
		BorderColor = RGB(181,221,221), ;
		Name = "Shp"


	ADD OBJECT cmdbtn AS commandbutton WITH ;
		Top = Thisform.Top+Thisform.Height-80,;
		Left = Thisform.Left+Thisform.Width-100,;
		Height = 30, ;
		Width = 70, ;
		FontName = "Verdana", ;
		Caption = "Upload", ;
		Name = "cmdBtn"


	ADD OBJECT lbluploadfile AS label WITH ;
		AutoSize = .T., ;
		FontBold = .T., ;
		FontShadow = .T., ;
		FontName = "Verdana", ;
		FontSize = 18, ;
		BackStyle = 0, ;
		ForeColor = RGB(85,95,230), ;
		Caption = "Upload File ", ;
		Height = 30, ;
		Left = Thisform.Left+30, ;
		Top = Thisform.Top+25, ;
		Width = 120, ;
		Name = "lblUploadFile"
		
	ADD OBJECT lbldb AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Database", ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Height = 15, ;
		Left = Thisform.Left+50, ;
		Top = Thisform.Top+70, ;
		Width = 60, ;
		Name = "lblDb"

	ADD OBJECT lbltbl AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Caption = "Table", ;
		Height = 15, ;
		Left = Thisform.Left+50, ;
		Top = Thisform.Top+100, ;
		Width = 35, ;
		Name = "lblTbl"


	ADD OBJECT lblbw AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Caption = "Browse", ;
		Height = 15, ;
		Left = Thisform.Left+50, ;
		Top = Thisform.Top+130, ;
		Width = 50, ;
		Name = "lblBw"


	ADD OBJECT txtdb AS textbox WITH ;
		BorderStyle = 1, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Left = Thisform.Left+145, ;
		Top = Thisform.Top+70, ;
		Height = 20, ;
		Width = 200, ;
		ColorSource = 4, ;
		Name = "txtDb"


	ADD OBJECT txttbl AS textbox WITH ;
		BorderStyle = 1, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Left = Thisform.Left+145, ;
		Top = Thisform.Top+100, ;
		Height = 20, ;
		Width = 200, ;
		ColorSource = 4, ;
		Name = "txtTbl"


	ADD OBJECT txtbw AS textbox WITH ;
		BorderStyle = 1, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Left = Thisform.Left+145, ;
		Top = Thisform.Top+130, ;
		Height = 20, ;
		Width = 200, ;
		ColorSource = 4, ;
		Name = "txtBw"


	ADD OBJECT cmddb AS commandbutton WITH ;
		Left = Thisform.Left+345, ;
		Top = Thisform.Top+70, ;
		Height = 20, ;
		Width = 25, ;
		Caption = "...", ;
		Name = "cmdDb"


	ADD OBJECT cmdtbl AS commandbutton WITH ;
		Left = Thisform.Left+345, ;
		Top = Thisform.Top+100, ;
		Height = 20, ;
		Width = 25, ;
		Caption = "...", ;
		Name = "cmdTbl"


	ADD OBJECT cmdbw AS commandbutton WITH ;
		Left = Thisform.Left+345, ;
		Top = Thisform.Top+130, ;
		Height = 20, ;
		Width = 25, ;
		Caption = "...", ;
		Name = "cmdBw"
	
	ADD OBJECT lblcolon1 AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Caption = ":", ;
		Height = 15, ;
		Left = Thisform.Left+130, ;
		Top = Thisform.Top+70, ;
		Width = 5, ;
		Name = "lblColon1"


	ADD OBJECT lblcolon2 AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Caption = ":", ;
		Height = 15, ;
		Left = Thisform.Left+130, ;
		Top = Thisform.Top+100, ;
		Width = 5, ;
		Name = "lblColon2"


	ADD OBJECT lblcolon3 AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		FontName = "Verdana", ;
		FontSize = 12, ;
		Caption = ":", ;
		Height = 15, ;
		Left = Thisform.Left+130, ;
		Top = Thisform.Top+130, ;
		Width = 5, ;
		Name = "lblColon3"

ENDDEFINE
*
*-- EndDefine: imgupload
**************************************************
Please explore your last post in a bit more details.
Sorry you all have to take too much toils with me.
Please also tell me how to post codes as all of you do because even after using code button my code is consuming too much space.
 
LPARAMETERS tnTop,tnLeft,tnHeight,tnWidth

PRIVATE pnTop,pnLeft,pnHeight,pnWidth
pnTop = IIF(EMPTY(tnTop),100,tnTop)
pnLeft = IIF(EMPTY(tnLeft),300,tnLeft)
pnHeight = IIF(EMPTY(tnHeight),250,tnHeight)
pnWidth= IIF(EMPTY(tnWidth),400,tnWidth)


PUBLIC oimgupload

oimgupload=NEWOBJECT("imgupload")
oimgupload.Show
RETURN

NO. That's not the way to do it. What you should do is to set the properties of the form (not the class) directly in your code, not in the DEFINE CLASS construct:

Code:
LPARAMETERS tnTop,tnLeft,tnHeight,tnWidth
oimgupload=NEWOBJECT("imgupload")
[b]oimgupload.Top = IIF(EMPTY(tnTop),100,tnTop)
oimgupload.Left = IIF(EMPTY(tnLeft),300,tnLeft)
oimgupload.Height = IIF(EMPTY(tnHeight),250,tnHeight)
oimgupload.Width= IIF(EMPTY(tnWidth),400,tnWidth)[/b]
oimgupload.Show
RETURN

In your DEFINE CLASS, don't bother to set the Top, Left, Height and Width of the form. Just remove those lines of code. The properties will take on their default values, which you will be overwriting with the above code.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Please also tell me how to post codes as all of you do because even after using code button my code is consuming too much space.

You have already discovered how to use the [ignore]
Code:
[/ignore] tags. That's a good start.

Next, delete all the code that is not relevant to the discussion. For example, you can remove all the lines that set the many different properties of your objects, such as the labels' BackStyle and FontName. Those lines have got nothing to do with the problem, and including them in your post only takes up space and adds to the clutter.

You should also reduce the tabs to just one or two spaces each. I assume you are pasting the code from the VFP code editor. If so, manually delete all the tabs, and instead insert on or two spaces for each. Alteratively, use the Beautify tool (right-click in the code editor and choose Beautify). Under Type of Indent, select Spaces, then 2. Then paste the code into the forum.

Eliminating the tabs in this way won't reduce the vertical height of the code, but it could reduce the width to the extent that users won't have to scroll horizontally to see it all (which is a major nuisance).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you Mike very very much for your step by step guidance, patience and very easy understandable English.
Beside understanding the concept of creating form programmatically I also knew how to post codes.
I have improved my code as under-
Code:
Lparameters tnTop,tnLeft,tnHeight,tnWidth
Public oimgupload
oimgupload=Newobject("imgupload")
oimgupload.Top = Iif(Empty(tnTop),100,tnTop)
oimgupload.Left = Iif(Empty(tnLeft),300,tnLeft)
oimgupload.Height = Iif(Empty(tnHeight),250,tnHeight)
oimgupload.Width = Iif(Empty(tnWidth),400,tnWidth)
oimgupload.Show
Return
**************************************************
Define Class imgupload As Form
  Top = 0 && 0
  Left = 0 && 0
  Height = 263 && 263
  Width = 408 && 408
  DoCreate = .T.
  Caption = "Upload Image"
  Name = "ImgUpload"

  Add Object shp As Shape With ;
    Top = Thisform.Top+10, ;
    Left = Thisform.Left+10, ;
    Height = Thisform.Height-40, ;
    Width = Thisform.Width-20, ;
    Curvature = 10, ;
    BackColor = Rgb(215,227,234), ;
    BorderColor = Rgb(181,221,221), ;
    Name = "Shp"
My form at the moment looks like -
Form_fsewkc.png


Now I want to use this form to upload image to Image field of any table in any database.
Please just give me an idea how to proceed. .
Thank you very much
 
Just to be clear. When you say "uploading an image", I think you mean "storing an image in a table". You are not uploading it in the sense of sending it across a link to a remote server. Is that correct?

Although it is possible to actually store an image in a table, it is generally not considered advisable. A better solution is to store the image somewhere on disk, and to store its path and filename in the table. This is very simple. All you have to do is to create a field in the table that holds the path/filename. You can then use VFP's normal table updating commands (REPLACE, UPDATE, etc.) to store the actual path/filename.

Going further, if you always store the images in the same directory, you only need to store the filenames in the table, not the paths. The paths will be implied.

One problem. Judging by your screenshot, you seem to be giving the user the choice of which table to hold the image. The problem is that the table that the user chooses might not contain the field for the filename. It's true that you could add the field on the fly (using ALTER TABLE), but that leads to various complications, not least of which is the fact that you would need exclusive access to the table in question. Are you sure this is what you want?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike said:
When you say "uploading an image", I think you mean "storing an image in a table". You are not uploading it in the sense of sending it across a link to a remote server. Is that correct?

Absolutely right.
Both the data (image in our case) and the application is on the remote server. So, I should rather use the word 'locate' instead of upload.
I just want to locate an image in a specific folder on the remote server to the ProductImage field of database table on that remote server itself.

The_form_tgxrbo.png


Mike said:
Are you sure this is what you want?
You are right, This was my misunderstanding.
Instead of database and table there would be an Image control which will show the image of the product if available otherwise will provide the option to locate the image.

For that reason can I define the class as container and embed it on the askingrid's form?

How should I proceed?
 
A Beginner-

Since your Grid is only showing one record at a time, I highly recommoend you don't put the image actually IN the grid, you can make it look like part of the grid though, simply by taking that space you have below the grid, and mimic the look and feel. But in the "White" area below it, do this:

Add an image object and size it to the width, put it aligned directly under it.

Then when you "look up" the image name, in the remote location (however it is you identify it, even by picking it from a list),
lcMyImage = <however you get the path to the image>

then in the Image Refresh you can say:


This.Picture = (lcMyImage)

This uses "name substitution" so use the fully qualified path to the image, and it will programmatically make that path appear in the (lcMyImage) value at runtime. (This is faster than & macro substitution).
If you want to store that value, put it in a memo field, and it can then be assigned to the refresh():

This.Picture = TABLENAME.MEMOFIELD



Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
can I define the class as container and embed it on the askingrid's form?

Which class are you refering to here? Do you want a container that hold the image, along with some sort of control to let the user navigage to the image?

If so, you can certainly define that as a class, but it might be easier just to drop a native Container class onto the form (in the Form Designer). Then put container in "edit mode" (right-click in the container and choose Edit; you will see a fuzzy green line around its edges). Then simply drop the other controls (the image, etc.) into the container.

But I'm not sure if that is what you are asking, or even what the benefit would be of doing that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike said:
Which class are you refering to here?
The Class that we just defined as form.
Code:
Define Class imgupload As Form
Can I define it as container instead of form and attach it directly to the form having askingrid(in the space available on right or bottom.)?
Moreover, should I remove database and table form controls and instead add an image control to the container(which I am thinking to be defined in place of form)?
 
Scott said:
Since your Grid is only showing one record at a time, I highly recommoend you don't put the image actually IN the grid, you can make it look like part of the grid

You are welcome.
 
Can I define it as container instead of form and attach it directly to the form having askingrid(in the space available on right or bottom.)?

Yes. Use DEFINE CLASS, as before, but this time do[tt] DEFINE CLASS ... AS Container[/tt]. Then add it to the form by using the form's AddObject method.

Moreover, should I remove database and table form controls and instead add an image control to the container(which I am thinking to be defined in place of form)?

Yes, that makes good sense. You have established that you don't want the user to select the table or database, so there is no reason to keep those controls.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top