Delphi XE8 Get Web Data RaiseError - android

Good Morning,I have a confused problem.I'm writing a multi-device application to get data from web server. I'm Using Rad Studio XE8.When the application running, it raise error like this
Debugger Exception Notification
Project SmartManager.apk raised exception class Segmentation fault (11).
1.I create a WSDL Importer,the WSDL file location is 'http://60.12.81.154/MobileQueryService/services/MobileQueryDaoImpl?wsdl'
2.Add a button and two edit component to the app .The button Onclick event is to finish user login,the code is:
**
procedure TFrmUserLogin.LoginByWebService;
var
ret: string;
JSONObject: TJSONObject;
begin
try
ret := GetMobileQueryDaoImplPortType.Sys_Return_UserInfo(eUserNo.Text, ePwd.Text);
if ret <> '' then
begin
JSONObject := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(ret), 0) as TJSONObject;
...
end;
except
showmessage('login failure!')
end;
end;
**
when the APP Run to 'ret := GetMobileQueryDaoImplPortType.Sys_Return_UserInfo(eUserNo.Text, ePwd.Text);',it raise error "class Segmentation fault (11)".
3.The webserver is writen by Java ,running on Tomcat7,when the app raise error,I find the server is running Normal.I print the result,it is right.
4.this app is running normal on win32 or win64 platform,but when i switch to android,the error is raised.
5.I have tested 2 mobile phone.One is HuaWei P6, the Android version 4.2.The Other is HuaWei P9, the Android version is 6.0. The App is working OK on P6,but raised error On P9.
6.Yesterday,I tried another way to get data from wbeserver By using httpclient,
the code like this:
**
procedure TFrmUserLogin.LoginByHttp;
var HttpClient:TIDHttp;
ParamList:TStringList;
url:String;
retResponse:TStringStream;
i: Integer;
rt,ret: string;
begin
try
HttpClient:=TIdHTTP.Create(Application.Owner);
retResponse:=TStringStream.Create;
url:='http://60.12.81.154/MobileQueryService/servlet/UserLoginAction' ;
ParamList:=TStringList.Create;
ParamList.Add('userno='+eUserNo.Text);
ParamList.Add('password='+ePwd.Text);
HttpClient.Post(url,ParamList,retResponse);
...
end;
**
The error is same!!!
Then I replace 'HttpClient.Post(url,ParamList,retResponse);'
with
'HttpClient.Get(url+'?userno='+eUserNo.Text+'&password='+ePwd.Text,retResponse);'
It is working as expected.
I do not know why,can anyone help me ?
I debugged the problem and it stops at the following line of code in "System.pas" file :
dlclose(handle);
I found when the handle is 0,the error raised.And I checked the file in XE10,all the code using dlclose will check that weather the handle is 0,like this :
if handle<>0 then dlclose(handle);
Could it be said that it is a bug of XE8?

Related

Android Test App perform programming steps backwards

I am using Delphi Enterprise version 10.2.3 with Android SDK ver 24.3.3 32bit. I tried a very simple program with only one button. The Onclick is simply the following:
ShowMessage('1');
ShowMessage('2');
ShowMessage('3');
ShowMessage('4');
The result I got on my Samsung phone when clicking on the button is:
4
3
2
1
Of course I am expecting to get
1
2
3
4
This is not my first Android Program. The previous ones runs smoothly. But when I got strange errors on my latest program, I found that programming steps are carried out in reverse. I am also scared now to recompile the previous apps, just in case I am getting this strange behavior. So I just make a new program (above) to test, but got the same results. I also disabled the Antivirus Avast program, and even try it on another Samsung device.
Help will be very much appreciated. At this moment I am really confused and not sure what next steps to take to solve the problem. Please help me!
On mobile platforms, ShowMessage behaves asynchronously. The call finishes instantaneously, it does not wait for the user to close the dialog box.
Try this code:
function TForm1.MyShowMessage(const Msg: String): TModalResult;
var
MR: TModalResult;
begin
MR := mrNone;
TDialogService.MessageDialog(Msg, TMsgDlgType.mtConfirmation,const [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], TMsgDlgBtn.mbYes, 0,
procedure(const AResult: TModalResult)
begin
 MR := AResult;
end);
while MR = mrNone do begin
Application.ProcessMessages;
CheckSynchronize;
end;
Result := MR;
end;

Delphi android application is raising issue in Lennova A5000 mobile

I'm using Delphi 10 Seattle trail version for developing mobile application. And I tried to create new android mobile application which contains only TEditBox. And then compiled by setting the option as "Release". Then, generated the .apk file and then provided the file to the user. And when the user tried to click the edit box, the application raises the error message that "The Appname is not responding".
The user is using the Lennova A5000 and the Os is Android 5.0.2.
And the same application is running in my Moto g2 (5.0.2) and Micromax Yureka.
Please provide me is there any solution.
Also, I have updated the app in google app store. Then, it is showing as incompatible application for this device (Lennova A5000).
And also I have updated all the android SDK packages. After that also, it is raising the same issue.
I think this may be problem to Embarcadreo Delphi or any missing packages? Dont know what to do.
Thanks in advance.
Atlast I got the solution from Embarcadreo website. Please follow the mentioned steps.
1.Copy FMX.Platform.Android.pas to the project folder from source/fmx folder
and add the copied files to the project.
Then, do the changes in the following procedures.
procedure TPlatformAndroid.RunOnUIThread(Proc: TThreadProcedure);
procedure TPlatformAndroid.RunOnUIThread(Proc: TThreadProcedure);
begin
//MainActivity.runOnUiThread(TSimpleProcedureRunner.Create(Proc));
CallInUIThread(
procedure()
begin
Proc;
end);
end;
procedure TPlatformAndroid.SynchronizeOnUIThread(Proc: TThreadProcedure);
procedure TPlatformAndroid.SynchronizeOnUIThread(Proc: TThreadProcedure);
var
Runner: TSimpleProcedureRunner;
begin
// CallInUIThread(
// procedure()
// begin
// Runner := TSimpleProcedureRunner.Create(Proc);
// MainActivity.runOnUiThread(Runner);
// Runner.Event.WaitFor;
// end);
CallInUIThreadAndWaitFinishing(
procedure()
begin
Proc;
end);
end;
procedure TPlatformAndroid.SetClipboard(Value: TValue);
procedure TPlatformAndroid.SetClipboard(Value: TValue);
var
Setter: TClipboardSetter;
begin
Setter := TClipboardSetter.Create(Value.ToString);
CallInUIThread(
procedure()
begin
SharedActivity.runOnUiThread(Setter);
end);
Setter.Done.WaitFor(INFINITE);
end;
function TPlatformAndroid.GetClipboard: TValue;
function TPlatformAndroid.GetClipboard: TValue;
var
Getter: TClipboardGetter;
begin
Getter := TClipboardGetter.Create;
CallInUIThread(
procedure()
begin
SharedActivity.runOnUiThread(Getter);
end);
Getter.Done.WaitFor(INFINITE);
Result := Getter.Value;
end;
Then, Rebuild the project. After doing this every thing is working fine.

Android delphi application Segmentation fault (11) exception when calling Firedac

I have problem with Delphi XE5 Firedac application. I use ZTE Blade 3 phone to run application. I used deployment manager to add database file to assets\internal directory. But when I call FDQuery1.FieldByName('Nimi').AsString it raises exception Segmentation fault (11).Thanks.
FDQuery1.SQL.Clear;
FDQuery1.SQL.Add('SELECT * FROM Laskuttaja');
FDQuery1.Open();
FDQuery1.First;
while(not FDQuery1.Eof) do begin
FormTiedot.EditNimi.Text := FDQuery1.FieldByName('Nimi').AsString;
FormTiedot.EditOsoite.Text := FDQuery1.FieldByName('Osoite').AsString;
FormTiedot.EditY.Text := FDQuery1.FieldByName('Ytunnus').AsString;
FDQuery1.Next;
end;
if FormTiedot.ShowModal = mrOk then begin
FDQuery1.SQL.Clear;
FDQuery1.SQL.Add('UPDATE Laskuttaja SET Nimi = '+QuotedStr(FormTiedot.EditNimi.Text)+', Osoite = ' + QuotedStr(FormTiedot.EditOsoite.Text) + ', Ytunnus=' + QuotedStr(FormTiedot.EditY.Text));
FDQuery1.SQL.Add('WHERE ID=1');
The error occurs on this line:
FormTiedot.EditNimi.Text := FDQuery1.FieldByName('Nimi').AsString;
A segmentation fault means that you are referring to invalid memory. So, this could arise for at least one of the following reasons:
FormTiedot is invalid.
FormTiedot.EditNimi is invalid.
FDQuery1 is invalid.
FDQuery1.FieldByName('Nimi') returns nil.
Now, as far as I know, FieldByName() raises an exception to indicate failure, rather than returning nil. And FDQuery1 is surely valid, otherwise the earlier code would have failed.
So, the most likely conclusion is that either FormTiedot or FormTiedot.EditNimi are invalid. Perhaps you failed to instantiate FormTiedot?
I was able to solve (I compiled and the error gives in function function "TClientModule1.GetServerMethods1Client: TServerMethods1Client;" when accessing the class FServerMethods1Client...
Go to menu:
Project -> Options -> Forms;
Verify that TClientModule1 is first in the Auto-Create forms.

Alarm Clock using DELPHI XE5 and Android

did someone already find the correct way to program an alarm clock using DEPHI XE 5 and Android OS?
I found this code , but it does not work/compile at all:
procedure TNotificationsForm.btnSendScheduledNotificationClick(Sender: TObject);
var
Notification: TNotification;
begin
{ verify if the service is actually supported }
if NotificationC.Supported then // compile error here
begin.Supported
Notification := NotificationC.CreateNotification; // compile error here
try
Notification.Name := 'MyNotification';
Notification.AlertBody := 'Delphi for Mobile is here!';
{ Fired in 10 second }
Notification.FireDate := Now + EncodeTime(0,0,10,0);
{ Send notification in Notification Center }
NotificationC.ScheduleNotification(Notification);
finally
Notification.DisposeOf;
end;
end
end;
The first error is that NotificationC.Supported this property does not exist
You should mention that the code is based on one of the sample applications distributed with XE5. They can be found in the Start Menu entry for XE5 under Samples, or in the default C:\Users\Public\Documents\RAD Studio\12.0\Samples\MobileCodeSnippets\Notifications folder (Windows 7).
It appears you've forgotten to drop the TNotificationCenter component (available on the Component Palette's Services page) on the form and name it NotificationC as the demos do. Once you've done that, your code compiles just fine.
When you mention that you get a "compile error" in a question here, it's important to include the error message. We can't see your screen from where we are. :-) You have that exact information right in front of you, so there's no excuse for not including it. The Messages window will even copy the exact message to the clipboard for you to paste here, if you right-click the error line.

Indy's TIdMultipartFormDataStream weird behavior on Delphi XE5/Android platform

I'm trying to use Indy's TIdHTTP component to send data to a website.
The code works perfectly on Windows platform but unfortunately it behaves strangely on Android platform. The problem occurs when I use TIdMultipartFormDataStream to send POST parameters.
On Android platform TIdMultipartFormDataStream behaves strangely and this what happens:
Suppose your POST data is myparam=myvalue where "myparam" is parameter name and "myvalue" is the parametervalue.
The parameter values gets changed to {FIRST CHARACTER REMOVED}yvalue{NULL CHARACTER} so the final output will look like this yvalue\x00 where \x00 is a null character.
I can replace TIdMultipartFormDataStream with TStringList and I won't face such issue but I prefer to use TIdMultipartFormDataStream because it enables me to upload files + send POST data at the same time.
Sample code:
procedure HTTPPOST;
var
HTTP: TIdHTTP;
POSTData: TIdMultipartFormDataStream;
begin
HTTP := TIdHTTP.Create(nil);
POSTData := TIdMultipartFormDataStream.Create;
try
POSTData.AddFile('myfile','file.txt'); // works
POSTData.AddFormField('username', 'user1'); // On Android the value gets changed to ser1\x00 where \x00 = Null character
HTTP.Post('http://www.example.com', POSTData)
finally
POSTData.Free;
end;
end;
Note: the code was tested using Delphi XE5 and Delphi XE5 Update 1
What you describe sounds like a ZEROBASEDSTRINGS bug, which should not exist in the current SVN version because Indy disables ZEROBASEDSTRINGS globally in all of its units after it kept suffering from lots of ZBS bugs in XE4. So I do suggest you upgrade to the lastest SVN verson. If you are having problems doing so, please update your question with details explaining why
Works..
procedure HTTPPOST;
var
HTTP: TIdHTTP;
POSTData: TIdMultipartFormDataStream;
begin
HTTP := TIdHTTP.Create(nil);
POSTData := TIdMultipartFormDataStream.Create;
try
POSTData.AddFile('myfile','file.txt'); // works
POSTData.AddFormField('username', UTF8Encode('user1'), 'utf-8').ContentTransfer:= '8bit';
HTTP.Post('http://www.example.com', POSTData)
finally
POSTData.Free;
end;
end;

Categories

Resources