Hello,
similarly to other object-oriented programming languages you have to specify the type of the argument to be a class, which is common ancestor of all classes you intend to pass in the argument. Following are the possibilities:
1. Assuming, your classes MyApp::Screen1, MyApp::Screen3, etc. are typical GUI components, then these descend from the Mosaic class Core::Group. Thus you can specify the type of the argument to be Core::Group. Accordingly, the method will accept any GUI component instance being passed in this parameter, not only Screen1 or Screen3.
2. If you want to limit the method to accept only the particular screen components, use an additional class as a common intermediate ancestor for all the screens. In practice: Create a new empty GUI component and name it e.g. MyApp::ScreenCommon. Leave the component unchanged. Then change the attribute SuperClass of your already existing component Screen1, Screen3, etc. to refer to the just created MyApp::ScreenCommon component. With this, your existing screen components become descendends of the MyApp::ScreenCommon component. Finally use the type MyApp::ScreenCommon in the declaration of the method argument. Such method will accept only instances of classes descending from MyApp::ScreenCommon.
3. Declare the argument with the very common type object. Such method will accept any object regardless of it is a screen, a timer, a view, handler, device driver instance, etc.
Which approach you select it's up to you. Please consider, within the method you can per default access properties, methods, etc. of the passed instance according to the specified argument type. If you have a new property added to the class MyApp::Screen3 and the method is declared with Core::Group as type for the argument, so trying to access this new property in context of the argument will report a Chora compiler error, since the property is unknown in Core::Group class. In such case you have to apply the object runtime cast operator on the argument to verity at the runtime, that the passed instance is really an instance of the particular class. If the cast is successful, you are able to access the particular property:
// Try to cast the argument
var MyApp::Screen1 screen1 = (MyApp::Screen1)method_argument;
// Successful? Then access the particular property
if ( screen1 != null )
screen1.SomeProperty = ...
By the way, in your above implementation is an error. The first two statements within the while-loop should be exchanged, otherwise the first found screen is never removed:
while ( view != null )
{
// try to cast the screen
var MyApp::Screen1 removeScreen = (MyApp::Screen1)view;
// find next view on the screen
view = rootObject.FindNextView( view, Core::ViewState[ Visible ] );
// cast has worked, remove the screen
if( removeScreen != null )
rootObject.Remove( removeScreen );
}
Hope it helps you.
Best regards
Paul