não pode confirmar se tiver campo vazio

Delphi

29/09/2003

Tem algum forma mais prátoca para q tipo em um formulario quando vamos confirmar inclusões por exemplo, todos os dbetis não pode estar vazios, sem ter q fazer aquele monte de ifs, ou fazer referencial integridade pela estrutura da tabela, existe alguma coisa mais fácil?


Janete

Janete

Curtidas 0

Respostas

Mmtoor

Mmtoor

29/09/2003

determine em sua tabela que o campo é requerido, ou seja, não será aceito campo null.
Pode aplicar esta regra para qualquer tipo de BD.
MMTOOR2003


GOSTEI 0
Luizfernando777

Luizfernando777

29/09/2003

Funciona o q nosso colega disse,
mas acho que a menssagem vai ficar em ingles,
nosso cliente vai gostar disso,

experimente isso
function PreencherCampos( DataSet: TDataSet);
var
Texto : String;
OK : Boolean;
begin
Texto := ´´;
OK := False;

for I := 0 to DataSet.Fields.Count-1 do
begin
{
os números o case que eu coloquei são os que
eu preciso, caso você precise de todos
então no lugar do case faz o seguinte:
for I := 0 to DataSet.Fields.Count-1 do
if DataSet.Fields[i].IsNull then
OK := True;

}

case I of
5 : OK := DataSet.Fields[i].IsNull;
6 : OK := DataSet.Fields[i].IsNull;
7 : OK := DataSet.Fields[i].IsNull;
8 : OK := DataSet.Fields[i].IsNull;
9 : OK := DataSet.Fields[i].IsNull;
10 : OK := DataSet.Fields[i].IsNull;
11 : OK := DataSet.Fields[i].IsNull;
end; // case

if OK then
if DataSet.Fields[i].IsNull then
Texto := DataSet.Fields[i].DisplayLabel;

if Texto <> ´´ then
begin
Application.MessageBox(PChar(Format( ´Favor preencher o campo ´ ¬s ´´, [ Texto ] )),
´Atenção´, MB_ICONWARNING+MB_OK);
Texto := ´´;
Abort;
end;// if

end; // for
end;


GOSTEI 0
POSTAR