Page 1 of 1
How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window
Posted: Wed Oct 23, 2024 2:05 pm
by xinjie
Hi, everyone
I checked the class definition syntax for the Foxpro dialect in the help and did not find an answer. I tried to follow the instructions for [Attributes] in the non-Foxpro dialect, but I encountered an error when generating it.
Can anyone tell me the answer or confirm that it is a bug?
Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window
Posted: Wed Oct 23, 2024 4:36 pm
by Chris
Hi xinjie,
Because I do not understand completely what you tried to do, can you please post an example of code that you tried and did not work? So we can see if it requires a different syntax, or it is a bug?
Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window
Posted: Wed Oct 23, 2024 5:38 pm
by xinjie
Hi, Chris
I've made a very small demo.
I defined a Class1 in a VFP class library project that inherits from System.Windows.Forms.Label ,and I added a custom property “myTest” that has a default value of “myTest”.
Code: Select all
Using System
Using System.Collections.Generic
Using System.ComponentModel
Using System.Data
Using System.Drawing
Using System.Text
Using System.Windows.Forms
Using System.IO
Using System.Runtime.CompilerServices
Begin Namespace mytest
/// <summary>
/// The Class1 class.
/// </summary>
Define Class Class1 As System.Windows.Forms.Label
mytest = "myTest"
Enddefine
End Namespace // mytest
The project build succeeded and generated a DLL.
I added the control Class1 to a form interactively. I see the customized property “mytest” and its value in the properties window.
I'd like to show some description of this property in there as well. For example, "this is a property for testing".
Then I changed the code as shown below
Code: Select all
......
Begin Namespace mytest
/// <summary>
/// The Class1 class.
/// </summary>
Define Class Class1 As System.Windows.Forms.Label
[Description("this is a property for testing")];
mytest = "myTest"
Enddefine
End Namespace // mytest
I see the following error when rebuild the class library project:
XS1003 Syntax error, 'END NAMESPACE' expected
XS9002 Parser: unexpected input '='
These are the reasons why I asked the question.
What I want to know is, if there is an implementation method available, how should it be implemented? Or is the current version not supporting its implementation?
Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window
Posted: Wed Oct 23, 2024 9:13 pm
by Chris
Hi xinjie,
Thanks for the sample, I understand the problem now. Not sure if it's a bug or not, but attributes cannot be attached to properties that are added with this syntax, they need to be used on a "strong" property declaration. This should work ok:
Code: Select all
DEFINE CLASS Class1 AS System.Windows.Forms.Label
[Description("this is a property for testing")];
PUBLIC mytest
mytest = "myTest123"
ENDDEFINE
Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window
Posted: Thu Oct 24, 2024 3:36 am
by xinjie
Hi, Chris
Thank you for your reply.
I tried it and it generates the DLL successfully, however, the properties window still doesn't show the description of the defined properties, even if I use "Public mytest As String"
Chris wrote: ↑Wed Oct 23, 2024 9:13 pm
Hi xinjie,
Thanks for the sample, I understand the problem now. Not sure if it's a bug or not, but attributes cannot be attached to properties that are added with this syntax, they need to be used on a "strong" property declaration. This should work ok:
Code: Select all
DEFINE CLASS Class1 AS System.Windows.Forms.Label
[Description("this is a property for testing")];
PUBLIC mytest
mytest = "myTest123"
ENDDEFINE
Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window
Posted: Thu Oct 24, 2024 8:00 am
by Chris
HI xinjie,
You're right, apparently the foxpro syntax for defining classes with attributes has problems, will open a ticket for this for Robert to fix.
In the meantime, please use the "new" X# syntax for this instead:
Code: Select all
CLASS Class1 INHERIT System.Windows.Forms.Label
[Description("this is a property for testing")];
PUBLIC PROPERTY mytest AS STRING AUTO
CONSTRUCTOR()
SELF:mytest = "myTest123"
END CLASS
I tested this one and it works.
Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window
Posted: Thu Oct 24, 2024 10:23 am
by xinjie
Hi, Chris
Thanks again!