GetPEM() and PemStatus() not supported in X#.VFP

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

Post Reply
Anonymous

GetPEM() and PemStatus() not supported in X#.VFP

Post by Anonymous »

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.
.

Code: Select all

GetPem(object oObject, string cPropertyEventMethodName)
Here is the C# code for that function:

Code: Select all

/// <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;
}
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

GetPEM() and PemStatus() not supported in X#.VFP

Post by robert »

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
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

GetPEM() and PemStatus() not supported in X#.VFP

Post by mainhatten »

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
Post Reply