xsharp.eu • GetPEM() and PemStatus() not supported in X#.VFP
Page 1 of 1

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

Posted: Thu Feb 13, 2020 1:45 am
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;
}

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

Posted: Thu Feb 13, 2020 5:56 am
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

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

Posted: Thu Feb 13, 2020 10:17 am
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