Fórum Ajuda com componente TChackBox no Delphi #560336
17/08/2016
0
Emanuel Gonçalves
Curtir tópico
+ 0Posts
17/08/2016
Emanuel Gonçalves
procedure TfrmRelCodLanc.Monta_SQL();
var i : Integer;
Entra : Boolean;
begin
FDLerCodLanc.Active := False;
FDLerCodLanc.SQL.Clear;
FDLerCodLanc.SQL.Add(' SELECT * FROM CODLANC ');
Entra := True;
for i := 0 to Self.ComponentCount - 1 do
begin
if (Self.Components[i] is TCheckBox) and ( TCheckBox(Self.Components[i]).Checked) then
begin
If Entra then
begin
FDLerCodLanc.SQL.Add('WHERE ');
Entra := False;
end
else
FDLerCodLanc.SQL.Add('OR '); <<<<<<<<<<<<<<<<<<< O detalhe está aqui, me retorna o erro ( Token Unknown - line 3, columm1 OR )
Case TCheckBox(Self.Components[i]).Tag of
1: FDLerCodLanc.SQL.Add('L_TIPO = ''D'' ');
2: FDLerCodLanc.SQL.Add('L_TIPO = ''R'' ');
3: FDLerCodLanc.SQL.Add('L_TIPO = ''E'' ');
4: FDLerCodLanc.SQL.Add('L_TIPO = ''S'' ');
5: FDLerCodLanc.SQL.Add('L_TIPO = ''M'' ');
6: FDLerCodLanc.SQL.Add('L_TIPO = ''U'' ');
end;
end;
end;
if RdGpListaPor.ItemIndex = 0 then
FDLerCodLanc.SQL.Add('ORDER BY L_TIPO, L_CODIGO')
else
FDLerCodLanc.SQL.Add('ORDER BY L_TIPO, L_DESCRICAO');
FDLerCodLanc.Active := True;
FDLerCodLanc.First;
end;
Gostei + 0
17/08/2016
Natanael Ferreira
Ou CheckListBox que nativamente você pode escolher mais de uma opção, mas com o código abaixo no evento OnClickChecked fica exclusivo igual o RadiogGroup.
var
i: Integer;
begin
with TCheckListBox(Sender) do
if (Checked[ItemIndex]) then
begin
Items.BeginUpdate;
for i := 0 to Pred(Items.Count) do
if (i <> ItemIndex) then
Checked[i] := False;
Items.EndUpdate;
end;
end;Gostei + 0
17/08/2016
Emanuel Gonçalves
Mas fiquei curioso para resolver o erro, não consigo entender o pq desse erro.
Gostei + 0
17/08/2016
Natanael Ferreira
Coloque um ShowMessage buscando o texto do SQL antes de ativar a query para ver como ele está sendo montado.
procedure TfrmRelCodLanc.Monta_SQL();
var
i: Integer;
Entra: Boolean;
begin
FDLerCodLanc.Active := False;
FDLerCodLanc.SQL.Clear;
FDLerCodLanc.SQL.Add(' SELECT * FROM CODLANC ');
Entra := True;
for i := 0 to Self.ComponentCount - 1 do
begin
if (Self.Components[i] is TCheckBox) and (TCheckBox(Self.Components[i]).Checked) then
begin
If Entra then
begin
FDLerCodLanc.SQL.Add('WHERE ');
Entra := False;
end
else
FDLerCodLanc.SQL.Add('OR ');
Case TCheckBox(Self.Components[i]).Tag of
1:
FDLerCodLanc.SQL.Add('L_TIPO = ''D'' ');
2:
FDLerCodLanc.SQL.Add('L_TIPO = ''R'' ');
3:
FDLerCodLanc.SQL.Add('L_TIPO = ''E'' ');
4:
FDLerCodLanc.SQL.Add('L_TIPO = ''S'' ');
5:
FDLerCodLanc.SQL.Add('L_TIPO = ''M'' ');
6:
FDLerCodLanc.SQL.Add('L_TIPO = ''U'' ');
end;
end;
end;
if RdGpListaPor.ItemIndex = 0 then
FDLerCodLanc.SQL.Add('ORDER BY L_TIPO, L_CODIGO')
else
FDLerCodLanc.SQL.Add('ORDER BY L_TIPO, L_DESCRICAO');
ShowMessage(FDLerCodLanc.SQL.Text); // Acrescentei esta linha
FDLerCodLanc.Active := True;
FDLerCodLanc.First;
end;Gostei + 0
17/08/2016
Emanuel Gonçalves
select * from CODLANC
where
or <<<<<<<<<<<<< aqui está o problema e não consigo resolver
L_TIPO = 'D'
or
L_TIPO = 'S'
order by L_TIPO, L_CODIGO
Gostei + 0
17/08/2016
Natanael Ferreira
Para que funcione, os 6 checkbox's devem estar com a propriedade Tag numerada de 1 a 6.
Se não estiver, dará este problema.
Gostei + 0
17/08/2016
Emanuel Gonçalves
if (Self.Components[i] is TCheckBox) and ( TCheckBox(Self.Components[i]).Checked) and (TCheckBox(Self.Components[i]).Tag > 0)
Gostei + 0
17/08/2016
Emanuel Gonçalves
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)