fbpx
Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

GetPEM() and PemStatus() not supported in X#.VFP 13 Feb 2020 02:45 #13204

  • FoxProMatt's Avatar

  • FoxProMatt

  • Topic Author


  • Posts: 400
  • I am just now seeing that GetPEM() and PemStatus() apparently won't be supported in X#.VFP.

    That's a bummer... And I think it will cause pain to many people. I get that these Functions are definitely from a Dynamic Language perspective, and perhaps hard to wedge into a purely Object Oriented language platform.

    However, as far as the GetPEM() function is concerned, that function is written in C# already in the Visual-FoxPro-Toolkit-for-.NET library.
    .
    GetPem(object oObject, string cPropertyEventMethodName)

    Here is the C# code for that function:
    /// <summary>
    /// Returns a bool specifying whether a property/method/event exists in an object. 
    /// (Currently this method does not implement all the parameters.)
    /// </summary>
    /// <param name="oObject"></param>
    /// <param name="cPropertyEventMethodName"></param>
    /// <returns></returns>
    /// 
    /// //Create a new listbox
    /// ListBox lstMyListBox;
    /// lstMyListBox = new ListBox();
    /// 
    /// //Check if the listbox has a ForeColor or MyColor property
    /// VFPToolkit.common.GetPem(lstMyListBox,"ForeColor");  //return true
    /// VFPToolkit.common.GetPem(lstMyListBox,"MyColor");  //return false
    /// 
    
    public static bool GetPem(object oObject, string cPropertyEventMethodName)
    {
    	//Get a list of all the properties in this object
    	PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(oObject);
    
    	//Beta 1 code
    	//PropertyDescriptor[] pda = TypeDescriptor.GetProperties(oObject).All;
    
    	//Loop through the properties an check if our property exists
    	foreach (MemberDescriptor md in pdc)
    	{
    		if (md.Name.ToLower() == cPropertyEventMethodName.ToLower())
    		{
    			//This means that we found our property
    			return true;
    		}
    	}
    
    	//Now we check for event name in this object
    	//Get a list of all the events/methods in this object
    	EventDescriptorCollection edc= TypeDescriptor.GetEvents(oObject);
    
    	//Loop through the events/methods an check if our event/method exists
    	foreach (EventDescriptor ed in edc)
    	{
    		if (ed.Name.ToLower() == cPropertyEventMethodName.ToLower())
    		{
    			//This means that we found our event/method
    			return true;
    		}
    	}
    
    	//If we reached here this means that we did not find our event/method/property
    	return false;
    }

    Please Log in or Create an account to join the conversation.

    Last edit: by FoxProMatt.

    GetPEM() and PemStatus() not supported in X#.VFP 13 Feb 2020 06:56 #13207

  • robert's Avatar

  • robert


  • Posts: 1793
  • Matt,
    It should not be a problem to support this. All the info about properties, fields and methods is available at runtime through reflection.
    Can you show us how you are using these functions?

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    GetPEM() and PemStatus() not supported in X#.VFP 13 Feb 2020 11:17 #13214

  • mainhatten's Avatar

  • mainhatten


  • Posts: 139
  • robert wrote: Matt,
    It should not be a problem to support this. All the info about properties, fields and methods is available at runtime through reflection.
    Can you show us how you are using these functions?


    Often to get a reference when doing dynamic cofiguration, as property name is read as a string from file or table.
    Cleaner and faster than calling eval() with host object "stringified" as well.

    regards
    thomas

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1