【问题标题】:Delphi Access violation addressDelphi访问违规地址
【发布时间】:2023-01-29 22:29:53
【问题描述】:
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; 

我收到此错误:

模块“WebServerClienti.exe”中地址 00E9D93D 的访问冲突。读取地址 00000008

错误在此行之前:

a.AddElement(o);

该过程适用于我没有参数的总查询。

我不明白 - 请帮助我

【问题讨论】:

  • 您还没有创建 TJSONArray。 a := TJSONArray.create 在捆绑填充它之前。
  • 地址 0 附近的访问冲突通常意味着正在访问 nil 指针。除了 John Easley 所说的之外,还可以使用调试器轻松诊断出这一点。

标签: delphi elixir-jason


【解决方案1】:

尝试这个 :

procedure TWebModule2.ClientGetItem(Request: TWebRequest; Response: TWebResponse);
var
o: TJSONObject;
CfKey: string;
a:TjsonArray;
begin
CfKey:= Request.QueryFields.Values['CF'];
if Request.QueryFields.Count > 0 then
begin
QryClientParam.SQL.Text := 'select * from TABLE where COD_FISC = :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('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 := TJSONArray.Create;
a.AddElement(o);
QryClientParam.Next;
Response.ContentType := 'application/json';
Response.Content := a.ToString;
end;
end;
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    相关资源
    最近更新 更多