Can I close the main form from a child form? - c++builder

Is this code ok? Can the execution point correctly return after I call MainForm->Close()? Will the child form be properly closed?
void TChildForm::TestSomething()
{
if (SomethingFails)
{
MainForm->Close(); // I know Release() should be more appropriate than Close();
return;
}
else EverythingIsFine_DoTheSettings;
}

Related

Appium checking if element is displayed

I'm using Appium for Android
the following works for clicking on the element
driver.findElement(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).click();
But I am trying to check if an element is on the screen and I tried the following
if (driver.findElement(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).isDisplayed()) {
System.out.println("FOUND");
} else {
System.out.println("NOT FOUND!");
}
but it returns an Exception saying
INFO: HTTP Status: '405' -> incorrect JSON status mapping for 'unknown error' (500 expected)
org.openqa.selenium.WebDriverException: Method is not implemented
How can I check to see if an element is on the screen?
You can try this, hope it helps
//If the element found, do as you want
if (driver.findElements(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).size() > 0) {
System.out.println("FOUND");
} else {
System.out.println("NOT FOUND!");
}
you can surround your code with try catch block.
public boolean isElementDisplayed(){
try{
return driver.findElement(By.xpath("//*[#resource-id='com.app.android:id/prelogin_signup']")).isDisplayed();
}catch(Exception e){
//System.out.println(e);
return false;
}
}
you can also make the generic function to check if element is displayed.
public boolean isElementDisplayed(MobileElement element){
try{
return element.isDisplayed();
}catch(Exception e){
//System.out.println(e);
return false;
}
}
You may also try isDisplayed().
if (demoPage.proceedButton().isDisplayed() == true) {
System.out.println("BUTTON FOUND*****");
TestUtil.click(cartPage.proceedButton(), 10);
} else {
System.out.println("PROCEED BUTTON NOT FOUND!*********");
}
Note - I am using Page Factory model. Hence, demoPage.proceedButton() is used, you may use your locator in place of this declaration.

Race condition GCD

I want to keep alive main thread to not freeze my application. But i don't know how to make non race condition with my async task. So i need wait my async task, but without blocking mainQueue.
public override bool ShouldPerformSegue(string segueIdentifier, NSObject sender)
{
bool isAlowed = false;
ActivityIndicator.StartAnimating();
DispatchQueue.GetGlobalQueue(DispatchQueuePriority.High).DispatchAsync(()=>
{
NSThread.SleepFor(2);
isAlowed = true;
});
return isAlowed;
}
Rather than initiating the segue and then trying to determine if the segue should be performed, asynchronously, simply handle the user interaction without triggering the segue, determine if the segue should be performed and then initiate the segue.
I can't give you exact code since I don't know Xamarin well enough, but the pseudo-code is something like:
handleHandleButtonTap() {
initiateBackgroundCheckWithHandler( isAllowed(bool) {
if isAllowed {
performSegueWithIdentifer("SomeSegue") // You need to dispatch this on the main queue
}
})
}
Xamarin / C# example:
void SomeButton_TouchUpInside(object sender, EventArgs e)
{
bool isAllowed = false;
InvokeInBackground(() =>
{
// Do some task... and optionally assign isAllowed to true...
if (isAllowed)
DispatchQueue.MainQueue.DispatchAsync(() => PerformSegue("SomeSegue", this));
});
}

How to call javascript functions from blackberry native?

I am developing an app where i need to call some methods from blackberry native to javascript.
when i click on back key down event , i want to trigger the onBackKeyDown() method, which is declared in javascript.
Main.java
protected boolean keyDown(int keycode, int time) {
// TODO Auto-generated method stub
if(Keypad.key(keycode) == Keypad.KEY_ESCAPE)
{
// onBackKeyDown();
// i want to call the following method which is declared in main.js file
Dialog.alert("this is back button");
return true;
}
return super.keyDown(keycode, time);
}
main.js
function onBackKeyDown() {
try {
if ($.mobile.activePage.is("#Page1")) {
$.mobile.changePage("#page5");
} else if ($.mobile.activePage.is("#page2")) {
$.mobile.changePage("#main");
} else if ($.mobile.activePage.is("#page3")) {
$.mobile.changePage("#main");
} else if ($.mobile.activePage.is("#main")) {
navigator.app.exitApp();
}
} catch(e) {
alert("Exception:ConsoleLog.log:" + e);
}
}
As i am having idea that by using "extendScriptEngine" , the methods declared in javascript are invoked in native. But here how to invoke the methods in javascript which are in native as per my above code... can anyone please help me with this...
You don't show this code, but I have to assume that your app has some Screen that contains some kind of browser field, which is displaying HTML content.
I can't tell you for sure without seeing that code, but what I would recommend is to use net.rim.device.api.browser.field2.BrowserField (Browser Field 2), if your app only needs to support OS 5.0 and higher.
If you have to support less than OS 5.0, I'm not sure how to do that.
Anyway, with this 5.0+ BrowserField, you can do this:
BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE); // should be the default
// Browser basic initialization
BrowserField _browserField = new BrowserField(config);
and then
protected boolean keyDown(int keycode, int time)
{
if(Keypad.key(keycode) == Keypad.KEY_ESCAPE)
{
// i want to call the following method which is declared in main.js file
_browserField.executeScript("onBackKeyDown()");
Dialog.alert("this is back button");
return true;
}
return super.keyDown(keycode, time);
}

How to close streaming player screen when sp.realize() method executing

I have read the knowledgebase article "Streaming media - Start to finish" It is working fine. When I click the open video, the player screen is open. When I click the back button before the player is realized, it does not come to back to the right screen.
when sp.realize(); method executing user can't come to back screen.
after loading player. it close.
How to go back a screen if sp.realize() method is still executing?
new Thread(new Runnable()
{
public void run()
{
try
{
if(sp==null)
{
sp = new StreamingPlayer(url, contentType);
sp.setBufferCapacity(bufferCapacity);
sp.setInitialBuffer(initBuffer);
sp.setRestartThreshold(restartThreshold);
sp.setBufferLeakSize(bufferLeakSize);
sp.setConnectionTimeout(connectionTimeout);
sp.setLogLevel(logLevel);
sp.enableLogging(eventLogEnabled, sdLogEnabled);
sp.addStreamingPlayerListener(playerScreen);
sp.realize();
volC = (VolumeControl)sp.getControl("VolumeControl");
if(contentType.toLowerCase().indexOf("video")!=-1)
{
vidC = (VideoControl)sp.getControl("VideoControl");
videoField = (Field)vidC.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
vidC.setDisplaySize(Display.getWidth(), Display.getHeight()-timeSeeker.getHeight()-byteSeeker.getHeight());
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
replace(getField(0), videoField);
}
});
vidC.setVisible(true);
}
if(contentType.toLowerCase().indexOf("audio")!=-1)
{
audioIcon = true;
if(!(getField(0)==albumArt))
{
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run()
{
replace(videoField, (Field)albumArt);
}
});
}
}
sp.start();
}
else
{
sp.stop();
sp.close();
sp = null;
run();
}
} catch(Throwable t)
{
//log(t.toString());
}
}
}).start();
I'm not sure exactly what you mean by this. However, have you tried running the audio stuff in a separate thread? That should reduce the likelihood of it interfering with anything else.

problem in starting camera?

hie i am using jde 4.5 want to use camera through my app.
i write the code and getting runtime excepetion Pushmodelscreen caaled by non event thread
tell me what the problem in it?
public void start Camera()
{
try {
// Create a player for the Blackberry's camera
Player player= Manager.createPlayer( "capture://video" );
// Set the player to the REALIZED state (see Player javadoc)
player.realize();
// Grab the video control and set it to the current display
_videoControl = (VideoControl)player.getControl( "VideoControl" );
if (_videoControl != null)
{
// Create the video field as a GUI primitive (as opposed to a
// direct video, which can only be used on platforms with
// LCDUI support.)
_videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
_videoControl.setDisplayFullScreen(true);
_videoControl.setVisible(true);
}
player.start();
if(_videoField!=null)
{
add(_videoField);
}
} catch (Exception e) {
// TODO: handle exception
Dialog.alert(e.getMessage());
}
}
`
thnaks alot
Amit
The code that involved in UI changes should be called from within the UI thread. So most likely some part of your code should be called in a way:
UIApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
// do your UI related staff here
// e.g. push a Screen or call Dialog.alert(), etc.
}
});
Also, you may find this info interesting.

Resources