Acess violation ao executar

23/11/2020

0

Estou com um erro de acess violation na execução do programa e acredito que possa ser no meu TFDQuery, que está instanciado dentro do create
 type
  TBaseDAO = class(TObject)

  protected
    FQuery: TFDQuery;
    constructor Create;
    destructor Destroy; override;

    function ExecutarComando(pSQL: string): integer;
    function RetornarDataSet(pSQL: string): TFDQuery;
    function HaRegistro(pSQL: string): integer;
  end;

implementation

{ TBaseDAO }

constructor TBaseDAO.Create;
begin
  inherited Create;
  FQuery := TFDQuery.Create(Nil);
  FQuery.Connection := DM.Conn;
end;
destructor TBaseDAO.Destroy;
begin

  Try
    if Assigned(FQuery) then
    begin
      FreeAndNil(FQuery);
    end;
  except
    on e: exception do
      raise exception.Create(e.Message);
  End;
end;

function TBaseDAO.ExecutarComando(pSQL: string): integer;
begin
  Try
    DM.Conn.StartTransaction;
    FQuery.SQL.Text := pSQL;
    FQuery.ExecSQL;
    Result := FQuery.RowsAffected;
    DM.Conn.Commit;
  except
    DM.Conn.Rollback;
  End;
end;

function TBaseDAO.HaRegistro(pSQL: string): integer;
begin
  try
    DM.Conn.StartTransaction;
    FQuery.SQL.Text := pSQL;
    FQuery.Open;
    Result := FQuery.RowsAffected;
    DM.Conn.Commit;
  except
    DM.Conn.Rollback;
  end;
end;

function TBaseDAO.RetornarDataSet(pSQL: string): TFDQuery;
begin
  FQuery.SQL.Text := pSQL;
  FQuery.Active := True;
  Result := FQuery;
end;

end.
Geovanna Biscaia

Geovanna Biscaia

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar