Error accessing state change that has a country

Asked

Viewed 39 times

0

I have a state register, which has a country. It registers normal, only that error occurs when accessing the state change.

inserir a descrição da imagem aqui

I don’t know if it’s right, but from what I understand, something from the country is coming empty. How do I fix it. I’m not getting.

The architecture I’m using is MVC. and I’m programming in Delphi.

In my system, all records that have other records, this error occurs. So much so that in the city register, I can’t even add the state because this same error occurs, but speaking of the state.

DAO ESTADOS:

function daoEstados.carregar(pObj: TObject): string;
var mEstado : Estados; mPais : Paises;
begin
  mEstado:= Estados( pObj );
  mPais:= mEstado.getoPais;

  mEstado.setCodigo( aDM.QEstados.FieldByName('CODESTADO').Value );
  mEstado.setEstado( aDM.QEstados.FieldByName('ESTADO').AsString );
  mEstado.setUF( aDM.QEstados.FieldByName('UF').AsString );

  mPais.setCodigo( aDM.QEstados.FieldByName('CODPAIS').Value );
  mPais.setPais( aDM.QPaises.FieldByName('PAIS').AsString );
  mPais.setDDI( aDM.QPaises.FieldByName('DDI').AsString );
  mPais.setSigla( aDM.QPaises.FieldByName('SIGLA').AsString );

  mEstado.setDataCad( aDM.QEstados.FieldByName('DATACAD').AsDateTime );
end;

At CONTROLLER STATES:

function ctrlEstados.carregar(pObj: TObject): string;
var mPais : Paises; AFilter: TFilterSearch; tipoConsulta : TTipoConsulta;
begin
  aDaoEstados.carregar( pObj );

  mPais:= Estados( pObj ).getoPais;
  aCtrlPaises.pesquisar(AFilter, IntToStr(mPais.getCodigo));
  aCtrlPaises.carregar( oEstado.getoPais );
end;

She calls the research method the controller country, which calls the dao:

msql:= '';

case AFilter.TipoConsulta of

 TpCCodigo:
 begin
   msql:= 'SELECT * FROM PAISES WHERE CODPAIS =' + IntToStr( 
   AFilter.Codigo );
 end;

 TpCParam:
 begin
   msql:= ( 'SELECT * FROM PAISES WHERE PAIS LIKE ' + QuotedStr( 
 '%' + AFilter.Parametro + '%' ) );
 end;

 TpCDDI:
 begin
   msql:= ( 'SELECT * FROM PAISES WHERE DDI LIKE ' + QuotedStr( 
 '%' + AFilter.DDI + '%' ) );
 end;

 TpCMoeda:
 begin
   msql:= ( 'SELECT * FROM PAISES WHERE MOEDA LIKE ' + QuotedStr( 
  '%' + AFilter.Moeda + '%' ) );
 end;

 TpCTODOS:
 begin
   msql:= 'SELECT * FROM PAISES ORDER BY CODPAIS';
 end;

end;

aDM.QPaises.Active:= false;
aDM.QPaises.SQL.Text:=msql;
aDM.QPaises.Open;
result:= '';

In this research method, I made a marry to know the type of filter that is selected for query.

Only when you get to that part:

aDM.QPaises.Open;

Is that the error occurs.

  • Which code when running generates this error?

  • There is an error in Dao País. HERE Adm.QPaises.Active:= false; Adm.QPaises.SQL.Text:=msql; Adm.QPaises.Open; -> HERE result:= ''; In Controller Status you have this method: Function ctrlStated.load(pobj: Tobject): string; var mPais : Countries; Affiliate: Tfiltersearch; tipoConsulta : TTipoConsulta;
begin
 aDaoEstados.carregar( pObj );
 mPais:= Estados( pObj ).getoPais;
 aCtrlPaises.pesquisar(AFilter, IntToStr(mPais.getCodigo));
 aCtrlPaises.carregar( oEstado.getoPais ); end; .

1 answer

0


I don’t know if it’s right, but from what I understand, something in the country is coming empty. How do I fix this. I’m not getting.

The error message displayed:

Comand [Qpaises] text must be not Empty

Translating the error message shown, we have:

The text of the Qpaises command must not be empty.

The Problem:
The problem is that the variable msql is not receiving a new value, this variable empty start and if it does not satisfy the condition case AFilter.TipoConsulta of, will not receive a new value, remaining empty.

A possible correction:
To correct, in the controller país start the variable in a generic way: replace the text:

msql = ''; 

for

msql = 'SELECT * FROM PAISES';

Thus, if any condition does not satisfy the case, you will have a standard query to be executed.

aDM.QPaises.Active:= false;
aDM.QPaises.SQL.Text:=msql;
aDM.QPaises.Open;

As I was not doing any checking before assigning the msql, everything indicates that an empty value is being assigned and the error is being generated.

Another possible correction:

aDM.QPaises.Active:= false;
if msql <> '' Then
   aDM.QPaises.SQL.Text:=msql
else
   aDM.QPaises.SQL.Text:= 'SELECT * FROM PAISES';  //Sua consulta padrão
aDM.QPaises.Open;
  • 1

    Thank you so much. It worked. Wow what a relief kkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.