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

AMEMBERS() 2

Status
Not open for further replies.

tilltek

Programmer
Mar 8, 2001
298
PH
I'm sure this will turn out to “dumb question of 2010” but I just can't get AMEMBERS() to work for me.
I've searched high and low and found literally hundreds of sites and books that give the same sample.

goForm1 = CREATEOBJECT("Form") && Creates a Form
= AMEMBERS(gaPropArray, goForm1, 1) && Array containing Form properties

So OK, fine, but I don't want to create a form, I want to work with an existing form (Main1.scx)
How?????
 
Do you want to do this in design time or run-time?

If in run-time, try to obtain a reference to your form by using NAME clause in DO FORM command.

If in design-time, then use aSelObj to get a form reference.

PluralSight Learning Library
 
Tilltek,

To echo what Markros said, it would be helpful if you could tell us what you want to achieve. When you do, I'm sure we'll be able to help you.

Just tell us your end-product. Never mind the code you have tried so far.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Well Mike, I was looking at a way to quickly duplicate a form that I could set up with basic items like help, quit, search etc. command buttons plus headers and so forth that I could then use as a basis for other forms throughout my app.
I have since discovered that I can achieve this by copying the original two form files and pasting them under a different name in Window Explorer.
so MAIN1.SCX and MAIN1.SCT
can be copied to SALES1.SCX SALES1.SCT
Seems to work with simple stuff like command buttons.


 
Tilltek,

Thanks for the clarification. As you've discovered, the solution has got nothing to do with AMEMBERS().

However, your idea of copying and pasting the forms is far from ideal. By far the best approach to this problem is to create a form class, and then to create individual forms based on the class. This will give you all the flexibility you need, and will make development and maintenance vastly easier.

If you're not familiar with the concepts of classes and objects, I'd recommend you to read up on it before going any further. There's quite a lot of new stuff to understand, but I promise you'll be glad you did.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Yes Mike, I can see that this would work as I've already done that with command buttons.
From the start I realized that almost every form would require, for instance, a [Help] command button so straight after I made my own set of classes I added a help button. That way, all I do as I design a form is drop “cCommandButtonHelp” on to the form.
Then I got to thinking, there are so many items on almost all of the forms that do the same thing, why not clone a form.
Thanks for the advice. I'm goin to try it out first thing in the morning (I'm Scottish Mike but I live in the Philippines and right now it's pint time)

>> If you're not familiar with the concepts of classes and objects, I'd recommend you to read up on it before going any further. There's quite a lot of new stuff to understand, but I promise you'll be glad you did.

Mike, I have been toying with the change over to VFP since I purchased a copy of VFP3 and a Sam's book back about 10 or so years ago. In that 10 years I have tried and tried but sorry, to me VFP is double dutch. For the past 15 years I have made my living solely from FPD and have come to understand FPD quite well (also a Sam's book by Jeb Long). But every time I look at VFP I end up in tears of frustration. So, what I'm now doing is taking it a step at a time, solving one thing at a time, like duplicating command buttons and screens, but believe me I still don't understand what I'm doing.
 
After FPD, VFP is like a new language. Hard to help on that in a little place. However, this little single message might lead you to get a bit faster on that 'copy-paste' which was our friend in FPD days:)

-Create your 'base' form. Saying base I mean create a regular form and just place the things that would be common to all forms in your application.
-From menu select File\Save as class. Let's say you have saved with class name 'MyBaseForm' and class library name 'MyBases.vcx' under folder Classes (assume relative).
-You can close that now.

When you need to 'copy-paste' instead you do this:

Code:
Create form myNewForm as 'MyBaseForm' from 'Classes\MyBases.vcx'

That is an intelligent 'copy-paste'. Works this time and if you go and modify the form 'MyBaseForm' in that 'MyBases.vcx' then all you need is to recompile and voila all those changes (additions as well) are available in your 'MyNewForm' that you 'copy-paste'd before (and anything that you have changed explicitly in MyNewForm is still intact).



Cetin Basoz
MS Foxpro MVP, MCP
 
Tilltek,

I can sympathisebut I urge you to persevere.

I've been running VFP training courses for 14 years, and have had hundreds of people with your sort of background passing through my hands. A few of them simply never get it, but the majority do find that it falls into place eventually.

I can only suggest you read as much as you can, and keep experimenting.

By the way, you must be the first Scot living in the Philippines I have come across. I wonder if there are many others.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks cbasoz, that does the job, BUT, if I want to delete one of the command buttons that may not be needed, it warns me that I can't "CANNOT delete objects because some of the members are of a parent class" in other words, I can't change a form ade this way.
 
if I want to delete one of the command buttons that may not be needed, it warns me that I can't "CANNOT delete objects because some of the members are of a parent class"

The trick is to make the unwanted button invisible (set its Visible property to .F.).

There's a good reason for not being allowed to delete (or rename) member objects. If you could, it would "break encapsulation" (another topic for you to read up on, Tilltek).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
So in other words, copy/paste via Windows Explorer is a better idea?
 
So in other words, copy/paste via Windows Explorer is a better idea?

No, I'm not saying that.

You want a standard form, containing (say) a Help button and a Close button. You create a form class which contains those two buttons. You then base all your individual forms on that class (using the CREATE FORM ... AS ... FROM ... syntax shown by Cetin, above).

So far, so good. Your individual forms will all have those buttons.

Now, one of your individual forms doesn't want a Help button for some reason. You've found that you can't delete the button on that specific form.

What I am saying is that, instead of deleting the button, you should hide it (on that specific form). The effect is the same, but there's no risk of breaking encapsulation (aka mucking up your object model).

I'm definitely not suggesting copy/paste via Windows Explorer.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Ah ok Mike, so we're talking the inheritance again. Yes, makes sense. Ok that's what I'll do.
I have another small question about a reply you made to someone in May about putting a digital clock on screen and I can't ask it there because the thread is closed.
Mike you said....
"Just place a label on the format. Format it to make a look like a clockface (for example, big yellow characters on a black background).
Add a timer to the form. Set its interval to, say, 10 seconds. In the Timer event, set the caption of the label to the value returned by LEFT(TIME(),5)"

I assume "place a label on the format " means "on the form" but I can't work out the "timer event",
What is or where is the "timer event"?
How does one "set the caption of the label to the value returned by LEFT(TIME(),5)"?
And what makes the timer react with that label and no other.?

Dim bulb in Camiguin.

 
Tilltek,

I can't say I remember that thread, but never mind -- I'll have a shot at answering.

Yes, I did mean "on the form". If I said "on the format", that would be a misprint.

You also need to add a Timer object to the form. A Timer is just another control, just like a label (except that is has no visible presence at run time). Drop if from the Forms Controls Toolbar in the usual way.

Select the Timer in the Form Designer. Go to its Property sheet, and find the Interval property. Set that to, say, 10000 (which is 10,000 milliseconds, or ten seconds).

Still in the Property sheet, find the Timer method (this is a bit confusing; "Timer" is the name both of the control and the method; here, I'm talking about the method).

Double-click on the Timer method in the Property sheet to open a code-editing window. This is where you write your code to diplay the time of day.

Assuming the label (the one that resembles the clock face) is named Label1, the code will be something like this:

Code:
THISFORM.Label1.Caption = LEFT(TIME(),5)

This displays the time of day in HH:MM format.

Now run the form. Stare at the clock for a while. It will take a few seconds to show the initial time. Wait a minute and the "minutes" will click over.

That should get you started. I use this very same example in my training courses to introduce the concept of object orientation. I then get the students to sub-class their clock class to produce an alarm clock (a more specialised type of clock). I'll leave that for you to do on your own over the weekend.

Have fun.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Ah, now a see. There's light at the end of the tunnel.
Thanks Mike, well explained.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top