|
|
|
Forum Guru
      
Group: Forum Members
Last Login: 2010-05-16 05:14:12
Posts: 63,
Visits: 355
|
|
| I am getting an error while trying to loop through an IObjectList ******************** oResultList := myps.Evaluate( 'Person.allinstances') as IObjectList;for each oObj:IObject in oResultList do begin//other code oPerson :=oObj.AsIObject as person;//error on this line //other code end; ******************************* What does this error mean ? *************************************** System.InvalidCastException was unhandled by user code Message="Unable to cast object of type 'Eco.Framework.Impl.Frontside.DefaultFrontsideLocator' to type 'Package_1.Person'." Source="Eco54Nuts" StackTrace: at Eco54Nuts.FormMain.btnSendMail_Click(Object sender, EventArgs e) in E:\54Nuts\Copy (2) of Copy of Eco54Nuts Rank subgroup\Eco54Nuts\MainForm.pas:line 156 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m) at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException:
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-11-18 23:48:32
Posts: 139,
Visits: 410
|
|
| Here is how I use IObjectList for collections in C#: IObjectList oclResult = ecoSpace.GetEcoService<IOclPsService>().Execute(null, null, "Person.AllInstances", -1, 0); Person persons = oclResult.GetAsIList<Person>(); foreach ( var person in Persons ) { // access person for your logic } I'll take a stab at what the Delphi syntax would be, but I'll probably be off a little. oResultList := myps.Evaluate( 'Person.allinstances') as IObjectList; persons := oResultList.GetAsIList<Person>(); for each person: Person in oResultList do begin // access person for your logic end; I'm not sure how Delphi uses generic methods, so the syntax is probably wrong. Also, if your result is not a collection you can use IObjectList.AsObject to return an instance of the object returned from the ocl expression. You will need to cast it to the proper type. This works for value types as well (i.e. int/integer, bool/booloean). Brian
|
|
|
|
|
Forum Guru
      
Group: Forum Members
Last Login: 2010-08-12 17:32:24
Posts: 51,
Visits: 600
|
|
| Hi Venks oPerson :=oObj.AsIObject as person;//error on this line Should be oObj.AsObject not oObj.AsIObject Nick
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-11-18 23:48:32
Posts: 139,
Visits: 410
|
|
| Just noticed a bug in the code. Person persons = oclResult.GetAsIList<Person>(); should be: IList<Person> persons = oclResult.GetAsIList<Person>(); or var persons = oclResult.GetAsIList<Person>(); Brian
|
|
|
|