How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
User avatar
xinjie
Posts: 108
Joined: Wed May 20, 2020 10:05 am
Location: China
Contact:

How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

Post 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?
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

Post 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?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
xinjie
Posts: 108
Joined: Wed May 20, 2020 10:05 am
Location: China
Contact:

Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

Post 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?
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
xinjie
Posts: 108
Joined: Wed May 20, 2020 10:05 am
Location: China
Contact:

Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

Post 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
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
xinjie
Posts: 108
Joined: Wed May 20, 2020 10:05 am
Location: China
Contact:

Re: How to Specify Default Values/Descriptions for Custom Properties and Methods Presented in the Properties Window

Post by xinjie »

Hi, Chris

Thanks again!
简单的东西重复做,你能成为专家;重复的东西用心做,你能成为赢家!
Post Reply