Type Coercion error when casting an object loaded in a different application domain - apache-flex

My application currently contains a number of Widgets that are managed by a Widget Manager. When the user clicks on a widget (e.g. a Helper widget), the Widget Manager loads the widget into a separate sibling application domain with the following line of code:
wgtInfo.load(null, null, null, moduleFactory); //wgtInfo = IModuleInfo
However, I am unable to use the widget's variables and functions later on. I attempt to find the Helper widget from the Widget Manager's list of widgets, and I do successfully. But when I try to caste the Helper Widget from type IBaseWidget (the interface all widgets share) to type HelperWidget, I receive the following error:
TypeError: Error #1034: Type Coercion failed.....
This is because the application domain of the class trying to use the Helper widget is different from the application domain of the Helper Widget. I tried to fix this by loading all widgets into the same application domain as the loader:
wgtInfo.load(ApplicationDomain.currentDomain, null, null, moduleFactory);
I now get the following error whenever I attempt to load the Helper widget:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
How can I load my Helper widget into a common application domain that is accessible by the other widgets?

I believe your problem comes from the class not being included in the swf. This is because Flash doesn't compile in classes in a swf if they aren't used to reduce filesize. To prevent this, you only need to create a variable with the helper class you need in that class, like this:
private var helper:HelperWidget;
See if that helps.

I'm gonna repost my 'comment' as a real answer. I'm guessing that the error is not based on the ApplicationDomain but based on which classes you are being compiled into your Module. When Flex compiles the SWF it automatically optimizes unused classes out of the SWF. You can force them back into the SWF in one of two ways:
Use the compiler argument include-libraries to force the Flex compiler to add the class to your SWF.
Add a fake variable in in your application so that the Flex compiler thinks it is used and adds it to the final SWF. Something like this.
private var myFakeObject : HelperWidth;

After trying a number of solutions unsuccessfully (including the other responses on this page), I resorted to another, event-driven, solution.
I ended up dispatching a custom event to notify my other widgets when the Helper widget had completed loading:
(HelperWidget.mxml)
ViewerContainer.addEventListener(AppEvent.WIDGET_OPEN_TAB, widgetOpenTabHandler); //listen for other widgets to open a tab within the Helper Widget
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_READY_OPEN_TAB)); //notify other widgets that loading is complete
My other widgets listen for this event to fire, and upon completion, dispatch another event (AppEvent.WIDGET_OPEN_TAB) to perform a function within the Helper widget.

Related

Why does the error occurs then I try to utilize pzRDExportWrapper in Pega 7.1.8?

I have a task to export a repeat grid's content to Excel. I have read an
article, but I still can't realize how to properly use it. I tried to repeat article's steps to provide pzRDExportWrapper, but after I click "Save" button I get the error:
Method: Rule-Obj-Activity instance not found:
Sb-FW-CTrackFW-Work.pzRDExportWrapper. Details: Invalid value for
Activity name passed to ActivityAssembler.
Could anybody give me any suggestions? Thank you.
You invoke activity from another activity which applies to class Sb-FW-CTrackFW-Work. Rule Resolution use primary context Sb-FW-CTrackFW-Work class and try invoke activity pzRDExportWrapper from it and you get error (because rule resolution can't found invoked activity in this class).
Activity pzRDExportWrapper applies to Rule-Obj-Report-Definition class. Try invoke from it.
Try activity step as below:
Call Rule-Obj-Report-Definition.pzRDExportWrapper
Or use step page for this step which defined as applies to Rule-Obj-Report-Definition class(you can declare it on Pages&Classes tab)
Okay. I have resolved the issue (thank you njc). I have two sections on a lone web page.
A context of the first section is my custom data page Co-Name-FW-Data-Search. The Search page has some single value properties which are initialized by an user via an UI.
The second section is a repeat grid section, a report definition as a source. My Search page pointed out in a Pages and Classes tab. Also there is a Page, which is created by report definition and contains results. The report definition takes Search’s values as parameters.
So, I have created an activity and passed the Search page and a Cods-Pega-List MyResultList as parameters. There are some steps in the activity:
Check if Search is null. If true- skip step; else - transfer Search properties into Params props with Data Transform.
Set Param.exportmode = "excel"
Call pzRDExportWrapper with Step Page MyResultList.pyReportDefinition. Pass current parameter page.
P.S.: If it doesn’t work try to play with report definition’s settings.
P.P.S.: An only minus of pzExportWrapper is that it invokes report definition again.

how to implement source filter property page?

I have followed the instructions at http://msdn.microsoft.com/en-us/library/windows/desktop/dd375010%28v=vs.85%29.aspx to create a property page for my CSourceStream based stream.
When testing with amcap I can see that amcap now shows the menu item to show the capture pin properties (ISpecifyPropertyPages::GetPages is queried). The problem is that when amcap calls OleCreatePropertyFrame it returns with E_FAIL and I am not sure why, it does not seem to even get to the stage of quering my dll for the factory method to instantiate the CBasePropertyPage based property class.
The problem was my DllRegisterServer only registered my filter.
I can use AMovieDllRegisterServer2 to register all components in g_Templates but that function does not register source filters properly so for the moment I am just calling AMovieDllRegisterServer2 and then re-registering my filter with source filter specific code.

Error in using created custom widget in designer

I am having a problem on using created custom widget. I have successfully created a custom widget that produces .dll file. I placed this .dll file under bin/designer. It was also recognized in the designer. I used it and placed it on my ui. But when I tried to build it, error occurred.
debug\moc_scribblearea.cpp(44) : warning C4273: 'staticMetaObject' : inconsistent dll linkage
d:\project\qt\workspace\sample-build-desktop\debug../../oep/scribblearea.h(53) : see previous definition of 'public: static QMetaObject const ScribbleArea::staticMetaObject'
debug\moc_scribblearea.cpp(44) : error C2491: 'ScribbleArea::staticMetaObject' : definition of dllimport static data member not allowed
debug\moc_scribblearea.cpp(54) : warning C4273: 'ScribbleArea::metaObject' : inconsistent dll linkage
d:\project\qt\workspace\sample-build-desktop\debug../../sample/scribblearea.h(53) : see previous definition of 'metaObject'
debug\moc_scribblearea.cpp(59) : warning C4273: 'ScribbleArea::qt_metacast' : inconsistent dll linkage
d:\project\qt\workspace\sample-build-desktop\debug../../sample/scribblearea.h(53) : see previous definition of 'qt_metacast'
debug\moc_scribblearea.cpp(67) : warning C4273: 'ScribbleArea::qt_metacall' : inconsistent dll linkage
d:\project\qt\workspace\sample-build-desktop\debug../../oep/scribblearea.h(53) : see previous definition of 'qt_metacall'
How can I use my created custom widget correctly? Are there any document/reference that describes how to use custom widget, from copying .dll to bin/designer folder upto building a project?
I have never created a custom widget stored in a .dll, therefore I can't help your on your primary question, but I have a workaround to offer:
If your custom widget is relatively simple (it does not have complex properties that explicitly require the Form-Editor) you can create a placeholder of another kind (e.g. a superclass of your widget) in your container-form, to be able to set the basic properties like position, geometry, size & size-policy and then replace this placeholder with your custom widget using some simple code in the container-form constructor.
Let's say that you have the following:
a. A custom widget GuiInpImageView inheriting from QGraphicsView:
GuiInpImageView::GuiInpImageView(QWidget *parent):QGraphicsView(parent)
b. A mainwindowbase.ui (class MainWindow) at which you actually want to put an instance of GuiInpImageView
This is the workaround solution step-by-step:
Put the .cpp source & header file for GuiInpImageView directly in your project (not in a DLL)
Define the following private member in MainWindow class header:
GuiInpImageView *inpImageView;
Open the mainwindowvase.ui in Form-Editor and put a QGraphicsView widget at the position you actually wanted to put your custom GuiInpImageView widget.
Let's say you have created a vertical layout named inpImageViewVertLayout containing a QGraphicsView named inpImageViewPH (PH = PlaceHolder).
You can also set -if you wish- the geometry, Min & Max Size and the size policy of inpImageViewPH using the properties exposed in form-editor of QtCreator.
Put the following code into your MainWindow constructor:
// Main Window Constructor
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
setupUi(this); // Setup UI
// Replace inpImageViewPH with custom Widget
// (inpImageViewPH is just a place holder to visualize UI in design mode)
inpImageView = new GuiInpImageView(centralwidget);
inpImageView->setGeometry(inpImageViewPH->geometry());
inpImageView->setMinimumSize(inpImageViewPH->minimumSize());
inpImageView->setMaximumSize(inpImageViewPH->maximumSize());
inpImageView->setSizePolicy(inpImageViewPH->sizePolicy());
inpImageViewVertLayout->addWidget(inpImageView);
// Remove and hide placeholder, keep only the Custom View
inpImageViewVertLayout->removeWidget(inpImageViewPH);
inpImageViewPH->hide();
...
This is the easiest way I have found to insert a custom widget in a form using code (without creating a .DLL) but to have also a graphical-preview and some control about the position & size of the widget in the form-container.
Hope this helps...

access mxml component from external actionscript file

i'm trying to access an mxml component from my external as file. e.g
main.mxml:<br>
<code>[mx:text id="myText" />]</code>
file.as:<br>
<code>var mainM:main = new main();
mainM.text.visible = true;</code>
I get the following error:
[TypeError: Error #1009: Cannot access a property or method of a null object reference]
Any suggestions on how to approach it better.
The ID of your component instance becomes a member of your application and can easy be accessed like so
import mx.core.Application;
mx.core.Application.application.myText.visible = true;
An additional answer is that when you create a new Flex component (new myFlexComponent()), the child UI components are not created until a CREATION_COMPLETE call is invoked, indicating the component is fully created. In the case of application, there is only one, and its automatically created by the framework, and referenced by (Application.application) as stated above.
For example, if your variable was a simple class variable (e.g. myDate:Date), you could access it via the above syntax

React to change on a static property

I'm re-writing an MXML item renderer in pure AS. A problem I can't seem to get past is how to have each item renderer react to a change on a static property on the item renderer class. In the MXML version, I have the following binding set up on the item renderer:
instanceProperty={callInstanceFunction(ItemRenderer.staticProperty)}
What would be the equivalent way of setting this up in AS (using BindingUtils, I assume)?
UPDATE:
So I thought the following wasn't working, but it appears as if Flex is suppressing errors thrown in the instanceFunction, making it appear as if the binding itself is bad.
BindingUtils.bindSetter(instanceFunction, ItemRenderer, "staticProperty");
However, when instanceFunction is called, already initialized variables on the given instance are all null, which was the cause of the errors referenced above. Any ideas why this is?
You have 2 options that I am aware of:
Option 1
You can dig into the code that the flex compiler builds based on your MXML to see how it handles binding to static properties. There is a compiler directive called -keep-generated-actionscript that will cause generated files to stick around. Sleuthing through these can give you an idea what happens. This option will involve instantiating Binding objects and StaticPropertyWatcher objects.
Option 2
There is staticEventDispatcher object that gets added at build time to classes containing static variables see this post http://thecomcor.blogspot.com/2008/07/adobe-flex-undocumented-buildin.html. According to the post, this object only gets added based on the presence of static variables and not getter functions.
Example of Option 2
Say we have a class named MyClassContainingStaticVariable with a static variable named MyStaticVariable and another variable someobject.somearrayproperty that we want to get updated whenever MyStaticVariable changes.
Class(MyClassContainingStaticVariable).staticEventDispatcher.addEventListener(
PropertyChangeEvent.PROPERTY_CHANGE,
function(event:PropertyChangeEvent):void
{
if(event.property == "MyStaticVariable")
{
someobject.somearrayproperty = event.newValue as Array;
}
});
I think you need to respond to the "PropertyChanged" event.
If you're going to do that, use a singleton instead of static. I don't think it will work on a static. (If you have to do it that way at all, there are probably a couple ways you could reapproach this that would be better).
var instance:ItemRenderer = ItemRenderer.getInstance();
BindingUtils.bindProperty(this, "myProperty", instance, "theirProperty");
After fiddling with this for a while, I have concluded that this currently isn't possible in ActionScript, not even with bindSetter. It seems there are some MXML-only features of data bindings judging by the following excerpt from the Adobe docs (though isn't it all compiled to AS code anyways)?
You cannot include functions or array
elements in property chains in a data
binding expression defined by the
bindProperty() or bindSetter() method.
For more information on property
chains, see Working with bindable
property chains.
Source: http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_7.html
You can create a HostProxy class to stand in for the funciton call. Sort of like a HostFunctionProxy class which extends from proxy, and has a getProperty("functionInvokeStringWithParameters") which will invoke the function remotely from the host, and dispatch a "change" event to trigger the binding in typical [Bindable("change")] Proxy class.
You than let the HostProxy class act as the host, and use the property to remotely trigger the function call. Of course, it'd be cooler to have some TypeHelperUtil to allow converting raw string values to serialized type values at runtime for method parameters (splitted by commas usually).
Example:
eg.
var standInHost:Object = new HostFunctionProxy(someModelClassWithMethod, "theMethodToCall(20,11)");
// With BindingUtils.....
// bind host: standInHost
// bind property: "theMethodToCall(20,11)"
Of course, you nee to create such a utlity to help support such functionality beyond the basic Flex prescription. It seems many of such (more advanced) Flex bindings are usually done at compile time, but now you have to create code to do this at runtime in a completely cross-platform Actionscript manner without relying on the Flex framework.

Resources