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.
Related
Using Delphi 10.4 and a FMX program.
I have a packed record with a "Single" type defined:
rRec = packed record
...
Inch: Single;
...
end;
Later in the logic, I wish to display the valve of Inch as a string. There are three ways to do this:
var
s: Single;
vStr: string;
vRec: rRec;
begin
vRec.Inch = 12.3;
//use FloatToStrF
vStr := FloatToStrF(vRec.Inch, ffFixed, 7, 1);
...
//Assign record value to variable and use TSingleHelper.ToString which simply calls FloatToStrF
s := vRec.Inch;
vStr := s.ToString(ffFixed, 7, 1);
...
//use TSingleHelper.ToString from the record value
//***** this fails on Android *****
vStr := vRec.Inch.ToString(ffFixed, 7, 1);
...
end;
All three of the above examples work on Win10, OSX and IOS. However, the last one (vRec.Inch.ToString) fails on Android with the IDE showing the error "Project xx raised exception class error (10)" before showing an access violation. The "Bus" error appears in the IDE when I try to step into the ...Inch.ToString call.
Is there a known reason TSingleHelper.ToString fails on Android when used with packed record fields? Note: I have not tested this with unpacked records, or tested the helper functions for other numeric types, or tested the TSingleHelper.ToString class function.
Edit:
turns out apparently Android does not support packed records very good or at all. I noticed in my code I had three "byte" fields before the "Single" field. By adding or removing a byte field, the vRec.Inch.ToString works. Guess I will have to use FloatToStrF.
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;
I've created simple Android Service on 10.2.3 and pinned it to my Android App same as it stands in docs. However, there where no libProxyAndroidService.so in {$BDS}/lib/android/release, I've copied it from debug dir. Next thorn made by Embarcadero to me was hanging of whole application while calling
TLocalServiceConnection.StartService('somename');
I have installed 10.3.1 with hope that this bug is eliminated in this release, but it did the same.
Running app in debug mode, I have putted some breakpoints in System.Android.ServiceApplication, when steping over and over by code, it crashed in System.InitUnits, line 23357:
try
while I < Count do
begin
P := Table^[I].Init;
Inc(I);
InitContext.InitCount := I;
if Assigned(P) and Assigned(Pointer(P^)) then
begin
{$IF defined(MSWINDOWS)}
TProc(P)();
{$ELSEIF (defined(POSIX) and defined(CPUX86)) and defined(ASSEMBLER)}
CallProc(P, InitContext.Module^.GOT);
{$ELSE}
TProc(P)(); << 23357 crashing
{$ENDIF}
end;
After execution of malfunctional P, UI thread hangs out, Service is never executed, but in background Android App is still executing code (new threads in message log)
Edit:
I've checked what is under P^
This is initalization part of unit FMX.Platform
https://quality.embarcadero.com/browse/RSP-17857
It's old bug, never fixed by Embarcadero
Just remove all things which use FMX.Types unit, remove this unit from evey uses.
Then set ClassGroup to TPersistent
Wasted hours :|
procedure TPlatformAndroid.BindAppGlueEvents;
var
AndroidAppGlue: TAndroidApplicationGlue;
begin
AndroidAppGlue := PANativeActivity(System.DelphiActivity)^.instance; // <------- Error occurs here
AndroidAppGlue.OnApplicationCommandEvent := HandleApplicationCommandEvent;
AndroidAppGlue.OnContentRectEvent := HandleContentRectChanged;
AndroidAppGlue.OnInputEvent := HandleAndroidInputEvent;
end;
Related issues: RSP-12199 and RSP-13381. FMX seems to have a lot of problems related to use of System.DelphiActivity in a service. And for good reason. DelphiActivity probably shouldn't exist in the first place! You are not supposed to hold on to references to the Activity object in the first place. And a Service doesn't even require an Activity to run! Apps and Services alike run as Contexts instead (the Activity and Service classes both derive from the Context class), so if you need to hold a reference to something, hold one to the Context that the code is running in (which FMX also does). What is FMX doing with DelphiActivity that is so important that it can't be done in other (safer) ways?
Conclusion: There is nil in System.DelphiActivity in Services so loading FMX units will create a crash in initUnits.
PDFed link with bug explanation: https://www.docdroid.net/TfUjBwg/bug.pdf
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?
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.