You were really, really close.
You had done two things not quite right.
1. When you looked up the type, you used Type.GetType(). If you use this you have to supply a fully qualified name, including assembly info. A pain. Instead use the SF helper function GetTypeFromReferencedAssemblies().
2. You didn't cast the object returned by Actvator.CreateInstance to be a BusinessLayer.
Here is the complete code for the form.
namespace Test_APP
{
public partial class CustForm : MicroFour.StrataFrame.UI.Windows.Forms.StandardForm
{
public CustForm()
{
InitializeComponent();
}
private void button1_Click( object sender, EventArgs e )
{
string boString = "TEST_BOLibrary.SFCustBO";
MicroFour.StrataFrame.Business.BusinessLayer bo = null;
//-- Use GetTypeFromReferencedAssemblies because BO is in different assembly than form.
//-- Wrong --> Type oType = Type.GetType( boString); can't find type in current assembly.
Type oType = MicroFour.StrataFrame.Tools.Common.GetTypeFromReferencedAssemblies( boString );
//-- Need to cast object returned by Activator.CreateInstance to a BusinessLayer
//-- Wrong --> bo = Activator.CreateInstance(oType); Type mismatch as CreateInstance returns an object.
bo = (MicroFour.StrataFrame.Business.BusinessLayer)Activator.CreateInstance( oType );
//-- Just access the BO to ensure that it got created.
MessageBox.Show( string.Format( "Number of records in bo: {0}", bo.Count ) );
}
private void sfCustBO1_ParentFormLoading_1()
{
//-- I changed this to load just the top 100 records...faster for testing.
this.sfCustBO1.FillTopN( 100 );
}
}
}
In the code above you'll see a reference to the FillTopN method on SFCustBO. I added this instead of the fill all just to speed up loading (yeah, I can be impatient
)
//-- In SFCustBO
public void FillTopN( int numberToFill )
{
this.FillDataTable( string.Format( "Select Top {0} * From {1}", numberToFill, this.TableName ) );
}