0
procedure TWebModule2.ClientGetItem(Request: TWebRequest; Response: TWebResponse);
    var
      o: TJSONObject;
     CfKey: string;
       a:TjsonArray;
    begin
       CfKey:='';
             CfKey:=  Request.QueryFields.Values['CF']  ;
          if Request.QueryFields.Count>0 then begin
               QryClientParam.SQL.Text := 'select * from TABLE where COD_FISC =  :CF';
        //       qryclient.Params.ParamByName('CF').AsString := Request.QueryFields.Values['CF'];
                 QryClientParam.Params.ParamByName('CF').AsString := CfKey;
               end else begin
               QryClientParam.SQL.Text := 'select * from TABLE';
           end;
        QryClientParam.Active := true;
      if QryClientParam.Active then begin
        if QryClientParam.RecordCount>0 then begin
           QryClientParam.First;
            o := TJSONObject.Create;
                        // o.AddPair('EmployeeNumber',TJSONNumber.Create( qryClient.FieldByName('COD').AsInteger ));
                         o.AddPair('Descrizione', QryClientParam.FieldByName('DESK').AsString);
                         o.AddPair('Codice Fiscale', QryClientParam.FieldByName('COD_FISC').AsString);
                         o.AddPair('CAP', QryClientParam.FieldByName('CAP01').AsString);
                         o.AddPair('Indirizzo', QryClientParam.FieldByName('INDIRI').AsString);
                         o.AddPair('Citta', QryClientParam.FieldByName('CITTA01').AsString);

                         a.AddElement(o);
                        QryClientParam.Next;
                         Response.ContentType := 'application/json';
                         Response.Content := a.ToString;
                        // TFile.WriteAllText('JasonResult'+ '.json', a.ToString);  //Scrivo Array del risultato in file
        end;
      end;
end; 

I get this error:

Access violation at address 00E9D93D in module 'WebServerClienti.exe'. Read of address 00000008

The error is before this line:

a.AddElement(o);

The procedure works fine with my total query without parameter.

I don't understand - please help me

3
  • 5
    You haven't created your TJSONArray. a := TJSONArray.create before tying to populate it. Jan 28 at 20:29
  • 1
    An Access Violation near address 0 usually means that a nil pointer is being accessed. That, in addition to what John Easley said, could have easily been diagnosed by using the debugger. Jan 29 at 3:34
  • 1
    In these cases, the simplest thing is to run Debug, "step by step" and stop at the error line. If you evaluate the variables of this line, you will see that a=nil. This generates the "Access Violation" error. Jan 30 at 10:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.