INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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

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

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:

Quote:

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:
http://www.garfieldhudson.com/freevideos.aspx

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

Good Luck,
JRB-Bldr



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

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

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

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 http://www.foxyclasses.com/pricing.htm

Bye, Olaf.

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

(OP)
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).

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

(OP)
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.

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

Quote:

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

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

(OP)
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.


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

Quote:

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")
oimgupload.Top = 20
oimgupload.Left = 40
* etc. etc.
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

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

(OP)
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 --> VFP

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.

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

Quote:

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")
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 

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

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

Quote:

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 [code][/code] 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

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

(OP)
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 --> VFP

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 -


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

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

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

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

(OP)

Quote (Mike)

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.



Quote (Mike)

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?

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

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

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

Quote:

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

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

(OP)

Quote (Mike)

Which class are you refering to here?
The Class that we just defined as form.

CODE --> vfp

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)?

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

(OP)

Quote (Scott)

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.

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

Quote:

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 DEFINE CLASS ... AS Container. Then add it to the form by using the form's AddObject method.

Quote:

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

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

Quote (A Beginner)

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?

Well, first I would like an english version of that sentence, but as far as I interpret it you think you must design visual stuff within forms. No, that isn't the case. The form designer is just one special designer for SCX, any other visual class than the form can be the basis of any class you design in a VCX, including forms, so designing a class via class designer, you can design partial forms, single controls and more, the form is just a special case you can design in the class designer. So the class designer and in general OOP class design offer much more capabilities than the form designer.

The only thing is you can't DO a class, you have to instanciate (create) it via CREATEOBJECT(). But whether you do that in code or within the designer is up to you, too. You can add controls at design time or runtime, that also means you can design several classes and as far as containership allows combine them into a next class, which kind of means your final class inherits from several previous classes. Ther is just one parent class in all cases, but that one base class can be form or container and you can then add in anything else. Container can contain container, so you can also nest objects, there also is no limit about this. All the classes you design as possible subforms or form components or pages or containers themselves not being forms can finally be put on a form class, which you either start by a combination of two code lines oForm = CREATEBOJECT("formclass") and oForm.Show() or if you want to be able to DO FORM yourform.scx, you create an empty SCX form you use to put your classes on it, or you base the SCX on a form class you already created as class, which kind of means you only convert the class to become an SCX with its simpler usage. Needing two instead of one line of code is not a big help, though, considering how much time it takes to get to this point, this is not a 50% savings issue. You see there are very many ways, but in OOP design you start from the single simple things and build up the form, not the other way around.

That said you can indeed create a form, put several things on it, then select a section and choose the item "save as class" from the file menu, then picking the option to only save selected elements. This will ask you to which vcx to store a class with which name, and then you have what I also suggested, a class, which mainly will be based on the container and contain the elements you picked. I find it easier to build up from detail to the whole form, though I understand developing a form concept is easier starting with the form level. The form level won't help you create several differently composed forms though, that obviously first needs the single components to put together in different ways to different forms, doesn't it?

Bye, Olaf.

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

(OP)

Quote (Olaf )

Well, first I would like an english version of that sentence, but as far as I interpret it you think you must design visual stuff within forms.
When I started with define class as form and added a few objects on it, seen nothing visible on running my prg. That's why I had written that post.
Mike's post beginning with "Here's something you can do:...." helped me to design the form first and use its code next.

At the moment I am going to define the class as container, put an image control on it, use some getfile(),lockfile kind of stuffs to grab the image and attach that with the askingrid form.
Can't I design cool looking forms like
with curved textboxes and smooth and shaded buttons?
Please guide me on that perspective.

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

(OP)
Can I use this image for showing images on the form and mimic the look and feel like canvas?

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

You are kidding me, are you? You're not designing a form by code, are you? Common, use the visual designers.

Bye, Olaf.

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

A-Beginner,
Yes you can use your picture frame image. What you do is put it on the form as in image class, with the picture clause set to that image.
Then put another Image class sized inside the frame lines you want to use. Set its picture property dynamically, and I would suggest make it "Invisible" (this.visible = .F.) if the picture is empty, or create a .bmp or .jpg very small image and make it the default that is "stretched" across the image surface, make it either all white, or all gray to match the background color of your object.
Not a bad idea actually. I usually wind up using shape objects that are square/rectangular to create borders for my image boxes... but this is a neat idea.

As for your Send File form, yes you can do all that in VFP with various properties in the objects. You *could* theoretically use that image as well, and just put text boxes on it with transparent backgrounds as well, if it's going to be that form, and buttons with transparent properties over the places you want those, and it would work too...

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

"Everything should be made as simple as possible, and no simpler."hammer

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

(OP)
One thing is worth mentioning here.
I found for multiple selection a link on tek-tips itself.
http://www.tek-tips.com/faqs.cfm?fid=3106

Quote (Olaf)

You are kidding me, are you? You're not designing a form by code, are you?
smile2 No no no I am not kidding. I am using first visual form designer and then utilizing its code.
Please tell me is it a harmful approach?

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

Yes it is harmful in many ways:
1. It partially won't run as generated. It is NOT the code that is equivalent to what running the visual form or class is
2. It is only meant for source control, to have text to be able to detect what changed as source version control software is very text oriented only. It doesn't work at all.
3. You have a hard time using such classes, eg you can't simply drag controls you have defined in PRG code onto forms.
4. You'll run into walls if you try to combine visual and PRG classes, inheritance chains should only have one type and compositing from both visual and PRG class also is a nightmare.

PRG code often is posted in forums, but only because it is the simplest form to post code. You sometimes find such forms in faqs, but mainly, as Mike recently also said to you, we concentrate on only posting essential parts of the code.

If you develop in VFP you develop with the visual designers. You'll see that many things are much easier this way. If yo argue only a PRG of the full class can give you an overview of everything, you haven't used Code References, or GoFish and see how easy they list things you search and "beam" you into the corresponding method via doubleclicking on results.

There is a slight downside of the editor only showing you a single method, but it helps focus. And the OOP principle of encapsulation means, if you really need to switch between many methods to extend your code, you do something completely wrong. So actually the way designers work and only let you edit one method at a time, help you create better code.

Bye, Olaf.

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

(OP)

Quote (Scott)

Yes you can use your picture frame image.
Thank you very much Scott for you taught me how to do that.
In the init event of the form I wrote

CODE --> vfp

IF EMPTY(Thisform.img2.Picture)
   Thisform.img2.Visible = .F.
ENDIF 
When run found that there is only the first image visible.

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

Well, yes, that was the intention of Scott, because if the inner img2.Picture is empty, this will show as an ugly icon of a broken link/image. You only want to show the inner image, if it is set to a picture file, too.

Bye, Olaf.

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

(OP)

Quote (Olaf)

Yes it is harmful
In one of my previous thread (about Systray notification) you had written in a post that you will help me designing the form with code.
When I try myself by defining a class based on form and adding a few object to it, I see nothing visible. So I feel quite difficult to proceed in that way.

Let me draw the outline-
1. In the askingrid form (I have uploaded the image of the grid and form in one of my previous post)I need to add the image of the product (in add mode of the program)
2. As soon as the image's path is added to the concerned field or the image is appended to the concerned memo field, it will be visible in the image control.
3. In change mode of the program only the available image will be seen with no option to upload.

So please write in what way should I proceed if I start coding the form from scratch.

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

>adding a few object to it, I see nothing visible
When you put a grid on the form, you don't see the grid?

Or what are you saying? It's time you watch a few of the Garfield Hudson tutorial videos you were pointed to, to learn the very basic things on how to use the visual designers.

Right clicking on things gives you context menu and shows you what you can do. Having the property Window open all the time also will show you things of anything you click in a parallel open form or class designer. Double click on a button you put on the form and the code editor will bring you to the click event. Just to give three essential handles on how to work here.

If your first contact with computers was via smartphone touch interface, this now is both desktop and Microsoft Windows. Apple's mice only have one button, but MS also have a right button for right clicking on things and getting more options via a context menu.

Bye, Olaf.

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

(OP)
All those videos I had watched more than 4-5 months back all the videos in the series up till grid. .... For the sake of continuity and revision I will again watch few of them related.

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

Quote (A Beginner)

In one of my previous thread (about Systray notification) you had written in a post that you will help me designing the form with code.
I assume you mean thread184-1776585: How to notify users on new message, chat, end date of something in a vfp application., but I don't see where I made the promise in helping you with PRG forms.

When we're at reading back what already was said, notice how I recommended visual classes and forms in thread184-1776488: What is wrong with 'ADD OBJECT footer.cntpanel1.image1 AS image WITH;' ? Can't I use it As it is? already.

Can you point out what makes you think I hel]p you with creating PRG classes? I'll surely not support that approach at all.

Bye, Olaf.

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

(OP)

Quote (Olaf)

I would help, if you'd write in whole sentences here. I don't know what you mean, now?
http://www.tek-tips.com/viewthread.cfm?qid=1776585

Quote (Olaf )

but I don't see where I made the promise in helping you with PRG forms.
No, no I never say you made any promise. yet, I say you had encouraged me to write my own class by that encouraging statement of yours.

Quote (Olaf)

....In one of my previous thread (about Systray notification) you had written in a post that you will help me designing the form with code.
This is really a bad statement and I apologize for that and instead I improve the statement like 'You had promoted my confidence to write my own class code.'
Please consider this as my improfessionalism and please don't ignore it, rather mark me wherever you feel like that.
I will be thankful to whosoever does that.

By the way I watched Garfield's video on
https://www.youtube.com/watch?v=SY2rpRR-hfo
was about class and realized that I had completely forgotten the vcx and instead mixed vcx and scx.

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

OK, well, but I encouraged you to do your own class, but not in a PRG, not with code. So try to get a grip on the visual designers.

If you right click on controls within your form or container class you get a context menu item builder. Try that. It'll "interview" you about what you want to do with the control, typically ask what data to bind. This is something you don't get in a PRG.

If you edit a method/event of a class having parent classes, above the code editor you have a combobox to change the object (if you edit some class composed of several objects, eg a form with several controls on it, that means nothing unusual), right to that you can choose procedure (method or event). In a PRG you can simply scroll to that code section, but isn't it nice you get a list of methods and events available to program? The third thing in the header of the visual class code editor is a button "View Parent Code", this is something you can only have in a PRG, if you have all class hierarchy code in one PRG, so the parent class definition also is in there.

Once you have defined a grid or textbox or any control class, open up or create a form class and set the project manager window side by side to the designer window, drill down the libraries to the control class you want in the project manager and drag that onto the form canvas. Also not possible with PRG class definitions.

I could go on with many further advantages of visual design and coding, one very simple advantage is you visually design the visual properties, you can drag controls instead of setting left and top, in short you have a WYSIWYG editing of the form, instead of code.you need to run to see how it looks. It later, when things are more complicated is a big advantage to be able to edit a form this way and not need to start it when it has lots of prerequisites and you only get to it at the end of a longer workflow, for example.

And last not least, well, the visual class itself is an end product, it's nothing you need to turn to PRG code to run it, it is runnable by instanciating it. The PRG code you can generate has the necessary code lines you need in general, o=NEWOBJECT("classname") and o.Show (for forms). That's all you have to program in some PRG or the command window. Besides you want to add your folder of VCXes onto the PATH or SET CLASSLIB to your VCXes and then can simply use NEW/CREATEOBJECT().

Bye, Olaf.

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

Consider using Dynamic Forms: https://vfpx.codeplex.com/wikipage?title=Dynamic%2...

Create forms with code... Lots of documentation on that site to show you how. There is also a YouTube video.

Good luck!

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

(OP)

Quote (jrbbldr )

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:

I think quarter a year back I had watched them when I was beginning with VFP.
Last night and today morning I watched few of them related to class and found that I had almost forgotten the concepts and found them pretty useful at the moment. Thank you.

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

(OP)

Quote:

Consider using Dynamic Forms
Thank you I am going through

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

(OP)
Once I am done with this static way of making form I will definitely do the same with dynamic form.

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

(OP)
Ok, Now when I am done with bringing the clicked image on to the canvas the problem I am facing is that the dimension of image is independent of the canvas boundary.
In what way can I confine the image within the boundary of canvas?

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

(OP)
What I have done till now can be jotted down as follows:
1. Created the project with name AddImage.pjx,
2. Defined NewClass based on BaseClasses.
3. Created a new class AddImage.vcx as NewContainer.
4. Added 'Img1' with an image (to mimic to Canvas) into the Picture property of Img1.
5. Added 'Img2' with no image in it's picture property.
6. In the init of 'Img2' typed code-

CODE --> vfp

IF EMPTY(This.Picture)
   This.Visible = .F.
ENDIF 
7. Added a label 'lblPath' with autosize .T., to the container.
8. Added a textbox 'txtPath'
9. Added a command button 'cmdBw' with caption '...'
10. Added 'adddialog' AS _comdlg
11. In the click event of 'cmdBw. created cursor to store the path of image selected.
12. In the click event of 'cmdBw' copied the code mentioned on http://www.tek-tips.com/faqs.cfm?fid=3106 with some modification as under

CODE --> vfp

Procedure cmdbw.Click
  Crea Curs FILENAMES (filename C(254))
  With This.Parent.adddialog
    .ClearFilters() && Clear filters in case in loop
    .lAllowMultiSelect = .T. && Enable multiple file selection
    .cFileName = [] && Do not set an initial file name
    *.cInitialDirectory = [[C:\My Documents]
    .cInitialDirectory = [C:\Users\Aspire\Desktop\Don't Delete] && Start folder
    .cTitlebarText = [Select multiple files] && Dialog titlebar text
    *.aFilterList[1,1] = [Image Files (bmp,gif,jpg)] && First half of filter list
    *.aFilterList[1,2] = [*.bmp;*.gif;*.jpg;*.jpeg] && Second half of filter list
    .AddFilter([Image Files (bmp,gif,jpg)],[*.bmp;*.gif;*.jpg;*.jpeg])
    * Should you want additional filters you can add them with :-
    *.AddFilter([MS Office (doc,ppt,rtf,txt,wri,xls)],[*.doc;*.ppt;*.rtf;*.txt;*.wri;*.xls])
    .nFileCount = 0 && Reset file count value in case dialog in DO WHILE... loop
    .ShowDialog() && Show dialog

    If .nFileCount > 0 && File(s) selected
      For i = 1 To Alen(.aFileNames,1) && Loop through array created
        Insert Into FILENAMES (filename) Values (Addbs(.cFilepath);
          +Lower(.aFileNames[1,i])) && Insert path\filename.ext in cursor
      Endfor
    *Browse Last
    Else
      Messagebox([You have not made a selection],16,[No files],2000)
    Endif
    This.Parent.txtpath.Value = FILENAMES.filename
    This.Parent.img2.Picture = FILENAMES.filename
    This.Parent.img2.Visible = .T.
  Endwith 

13. To show the path of the image in 'txtPath' and to open the picture as 'Img2' typed following code-

CODE --> vfp

This.Parent.txtPath.Value = FILENAMES.filename
  This.Parent.img2.Picture = FILENAMES.filename
  This.Parent.img2.Visible = .T. 
14. Created a new form AddImage.Scx in the project itself and added the Addimage.vcx on it.

15. When run the form and select any image, it opens it but of the image's original dimension(large or small)

Please guide me on how to adjust the image's dimension dynamically?

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

(OP)
Ok That too happened by setting the stretch property of Img2 to 2

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

When you set img2.Picture the img2 width and height get set to the picture dimensions, right. Setting stretch does not put the img2 dimensions back to how they were.
You have to set stretch before setting the picture, then the image control knows it should not resize itself to picture dimensions but should stretch the picture to fit.

Notice: Stretched pictures will look blurred, especially when they are graphical. What you show there would perhaps also look nice stretched. Ideally, you have pictures which are larger than the inner canvas, because downsizing a picture rather sharpens it.

Bye, Olaf.



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

(OP)

Quote (Olaf)

You have to set stretch before setting the picture, then the image control knows it should not resize itself to picture dimensions but should stretch the picture to fit.
Ok, Then I modified the code in the click event of 'cmdBw' as

CODE --> vfp

This.Parent.Img2.Stretch = 2 
and also after endwith typed

CODE --> vfp

IF !Empty(This.Parent.txtPath.Value)
     This.Parent.img2.Visible = .T.
  ELSE  
     This.Parent.img2.Visible = .F.
     This.Parent.img2.Stretch = 0
  ENDIF 

Running ok.

Quote (Olaf)

Ideally, you have pictures which are larger than the inner canvas, because downsizing a picture rather sharpens it.
Thank you farsightedness. In what way should I recover it?
Should I not accept larger images or should I give cropping opetion? or what else?

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

I understood the opposite of what I said. Larger images are fine, they will look fine downsized. Notice stretch includes shrinking, if the image is larger.

Bye, Olaf.

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

(OP)
fine.

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

As you want all pictures to stretch, you could set stretch to 2 in the property window and keep it that, no need to switch this setting just because there is no picture set.

Bye, Olaf.

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

(OP)
Yes I had tested it was working fine but for the good practice I had modified the code.

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

What good practice says you set something, when no change is needed? Setting Stretch=2 once makes all pictures you set to the control.Picture stretch (or shrink), you define the automatic behavior of the image control, there is no need to do this repeatedly, as you always want to do the same.

Bye, Olaf.

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

(OP)
Ok I shall revert.

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

(OP)
Well, to grasp the concept of Class and other important concepts more deeply I am going through Advanced Object Oriented Programming with Visual FoxPro 6.0. Please give notions- Is it good to go with concepts dealt with version 6 when I am programming with version 9.0? Should I continue reading or any other easy to understand book?
The link is as follows.
http://flylib.com/books/en/2.340.1.1/1/

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

That book should be fine. There are newer features, but the basics remain unchanged.

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

(OP)

Quote (DanFreeMan)

That book should be fine. There are newer features, but the basics remain unchanged.
Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close