0

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');
Avijit
  • 3,834
  • 4
  • 33
  • 45
user3146414
  • 89
  • 2
  • 6
  • Set a debugger breakpoint on the problem line, and run your app. When the breakpoint is hit, examine `FormTiedot` to see if it actually has a value. It's usually a bad sign when you're referencing a form by name, especially if this code is running in a method of that form. – Ken White Dec 30 '13 at 13:32
  • Yes thank you for your help. I forgot TFormTiedot.Create()-call. Now there is another exception problem. exception class ENotImplemented with message " – user3146414 Dec 30 '13 at 20:40
  • 1
    Do you have XE5 Update 2 installed ? If not, then you should install it. – da-soft Dec 31 '13 at 02:47

2 Answers2

2

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?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • @user3146414: Btw, I'm just a bit surprised that noone has commented that your while loop seems pointless, because it will leave the FormTiedot edit Texts assigned to the field values of the last record read in the loop, regardless of the field values in prior records, so it seems a waste of time to read all the preceding ones (unless the assignments have side effects you haven't shown us). – MartynA Dec 31 '13 at 16:20
0

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.

Jalpesh Patel
  • 3,150
  • 10
  • 44
  • 68
Cássio
  • 1
  • 1