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

my properties and my classes

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,
I know it is possible but forgot how to do it.
1) I would like to create a new property for which you can only set a .T. or .F. like e.g. the native properties Enabled.
As far as I can remember one should give some script code on creating the property, the question is: how to do it?
2) I would like to give my class a by my defined icon and not the default icon. So if I create a class myCheckbox which is a container containing a checkbox, a line and a textbox plus some code. The class, saved into myClassLib will show a container as icon, I would like to change that to a by me selected image file. I know it can be done, but how?
Stay healty,
Koen
 
Koen,

Re your first question ...

To force a custom property to always be a given data type, you create an Assign method for it. To do that, create the property in the usual way. In the New Property dialogue, tick the box labelled Assign Method. Then click Add and then Close.

You now have a new method named xxx_Assign, where xxx is the name of the property. From now on, whenever you try to assign a value to the property, it will execute the Assign method. So you can write code in the method to accept or reject the value. The method takes a parameter, which is the value being assigned. By default, the value is accepted, but you can write whatever code you like to check the value (in this case, to check that the data type is Logical) and then to accept or reject it.

Re your second question ...

I think someone answered a similar question recently. Let me check and get back to you.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Second question: While modifying the class choose Class in the menu bar, Class Info, Toolbar Icon.
 
Mike,
Tks, will try it imm.
Jack,
Also, Tks, will try it imm.
Stay healthy,
Koen
 
No, I couldn't find what I was looking for. But it is quite easy to do what you want.

Open the class in the Class Designer, then go to the Class menu, and then to Class Info. There are two places where you can set the icon here; choose either Toolbar icon or Container icon as appropriate (in practice, you would probably set them both to point to the same image).

Edit: Re the second question, Jack beat me to it, but his answer is the same as mine.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,
The setting of an image is no problem at all.

The setting of myProperty ( default .F.) to .T. is not so easy (for me) I have computed following in myProperty_assign:

Code:
Lparameters vNewVal

This.myProperty = m.vNewVal
lvNewVal = This.Val
If Vartype(m.lvNewVal)='L'
	lvNewVal = !m.lvNewVal  && change from .F. to .T. vicaversa
Else
	lvNewVal = .T.
ENDIF
RETURN m.lvNewVal

It does not give the required result. Any idea where I go wrong?

Stay healthy,
Koen
 
You're close, Koen, but not quite there. Try this:

Code:
Lparameters vNewVal
If Vartype(m.lvNewVal)='L'
	THIS.MyProperty = !m.lvNewVal  && change from .F. to .T. vicaversa
Else
	THIS.MyProperty = .T.
ENDIF

So, if you pass a logical value, the property will contain the opposite of the value that you are trying to store (.T. instead of .F., or vice versa). If you pass anything other than a logical value, you will ignore that value, and you will set the property to .T. Is that what you want?

In any case, the Assign method doesn't return anything. Instead, it actually stores the value that you specify directly in the property.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Me said:
the property will contain the opposite of the value that you are trying to store (.T. instead of .F., or vice versa). .... Is that what you want?

I can't help thinking that's not what you want. More likely, you want to accept whatever logical value is passed, and reject any non-logical value.

If that's right, just remove the [highlight #FCE94F]![/highlight] in the above code. In other words, instead of this:

Code:
THIS.MyProperty = [highlight #FCE94F]![/highlight]m.lvNewVal

do this:

Code:
THIS.MyProperty = m.lvNewVal

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
Both your options allow me to set e.g. .F to myProperty. One dot missing, making the value character and not logic.
When this is the case
And that was exactly what I would like to avoid.
In fact I am looking for a solution like with the native properties controlling a logic, like e.g. AllowInput,
when you click on that a dropdown is presented with the .T. or .F. possibility.
I believe I must think about to show a shortcut menu.
Stay healthy,
Koen
 
Koen,

Just to be clear .... Do you want to achieve this at design time or at run time? In other words, do you want to prevent a property being set to a non-logical value in the property sheet, in the form or class designer? Or is it something you want to control within the program?

If it is at design time, then you can create a custom property editor to do the job. A property editor is a tool that sits in the property sheet, and that you can invoke when you want to change the value of a property. An example is the colour picker dialogue that you can invoke when you want to change a colour-related property. Another example is the Anchor editor.

In your case, it would be a simple menu offering .T. and .F. options.

If that is what you want, I will try and explain how to do it. It's a little complicated, so I won't go any further with it if it is not what you are looking for.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

Yes I want it for desgin time, to avoid making a stupid, simple mistake, like entering < ,T. > into my property.
The requirement for a simple menu to replace the value is more a requirement to make my design UI more appealing. No menu but a harsh "you can only enter .T. or .F., and not ,T. in this property" should also do. Where ,T. comes of course from a variable.

Stay healthy,
Koen
 
So, in that case, you can forget everything I said about Assign methods. They don't apply at design time. If I had known you were looking for a design time solution, I would not have mentioned them.

It definitely looks like you need a custom property editor. As I said, that's quite complicated, so rather than trying to explain it myself, I recommend you read Doug Hennig's paper on the subject. See:

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
That's it, that is the document I was looking for. Thanks a lot.
Stay healthy,
Koen
 
That's fine, Koen. I hope this solves the problem.

I have to say that, personally, I wouldn't bother with this. Like most developers, I sometimes place an illegal value in a custom property (including, for example, T. instead of .T.). But it usually leads immediately to a run-time error, and it only takes a moment to correct it. But that's my personal view. By all means, create a property editor if that suits you better.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
basicly I agree, but after I had made the mistake to set a logical property to ,T. which took me more than a day to figure out what was going on, I decided to change it, provided it would not take to much time to do it, as otherwise the cure is worse than the error..
Stay healthy,
Koen
 
Fair enough, Koen. Of course, the other advantage of creating a property editor is that actually setting the property will be a little bit quicker: picking a value from a list is usually better than having to type it in the small box in the property window.

Good luck with this.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I'm using property editors extensively in a current project to do all kinds of things that would otherwise need to go into a checklist. Simplest case: we don't want AutoSize on for labels, but resizing is a pain. So I have a property editor for Width that properly sizes the label.

I'm also using them in some complex container objects to set properties of contained objects and position things as they should be.

They are saving us a ton of time.

Tamar
 
My VCX and SCX editor replacements has this built in -- see 'VFP Editors' in VFPx.

2021-04-23_13-51-19_xh6bdq.png
 
Yes, turning Autosize On and then Off and doing some additional work that makes it all work nicely.

This is the simplest version of the code, a Property Editor for the Width property of our base label class:
[pre]
LOCAL laControl[1], loLabel

IF ASELOBJ(laControl) = 0
IF ASELOBJ(laControl, 1) = 0
RETURN
ENDIF
ENDIF

loLabel = laControl[1]
loLabel.AutoSize = .T.
loLabel.Width = loLabel.Width
loLabel.ResetToDefault("AutoSize")

*-- TEG 6/11/2020
* Reset Left
loLabel.Left = loLabel.Left

RETURN
[/pre]

In some more complex classes for this app, we're doing more complex things.

Tamar
 
I think the easiest for the property which should only b .t. or .f. is adding it to IntelliSense.

First, the feature of PropertyValueEditors should be activated in the Intellisense Manager:

property_value_editors_x3v9oy.png


And then I think you find some records in the IntelliSense table foxcode.dbf which demonstrate such property value editors. There is a record with a {color} script, all color properties reference it. It's harder to explain than to do, I think you should dive into the opic of advanced intellisense manager and the foxcode.dbf

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top