Delphi Access violation address

404 Views Asked by At
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

0

There are 0 best solutions below