Fórum Uso do IfThen com datas #622417
16/08/2024
0
1 2 3 4 | if edt1 . text = EmptyStr then edt1 . text := 'Informe valor' else edt1 .Text := 'Valor valido' ; |
Podemos trocar o codigo acima por este que tem o mesmo efeito
1 | edit1 . text := IfThen(edt1 . text = EmptyStr, 'Informe valor' , 'Valor valido' ); |
No meu caso, tenho datas e não achei uma forma de fazer
1 2 3 4 | if DayOfWeek(Date) = 2 then dtpInicio . Date := Date - 2 else dtpInicio . Date := Date; |

Renan
Curtir tópico
+ 0Posts
16/08/2024
Arthur Heinrich
1 2 3 4 5 6 | function ifthen_date( condition : boolean; date1, date2 : tdatetime):tdatetime; begin if condition then Result:=date1 else Result:=date2; end; |
Ou, se o seu objetivo é identificar o domingo (início da semana), pode calcular diretamente sem o IF.
1 | dtpInicio.Date := Date - DayOfWeek(Date); |
Gostei + 0
20/08/2024
Renan
Na verdade eu uso esse código para preencher o DateTimePicker, de acordo com o dia da semana.
No caso acima, se for segunda-feira, vou preencher o DateTimePicker com a data de sexta-feira e se for outro dia da semana, o DateTimePicker recebe a data atual.
Gostei + 0
20/08/2024
Natanael Ferreira
1 2 3 4 | if edt1 . text = EmptyStr then edt1 . text := 'Informe valor' else edt1 .Text := 'Valor valido' ; |
Podemos trocar o codigo acima por este que tem o mesmo efeito
1 | edit1 . text := IfThen(edt1 . text = EmptyStr, 'Informe valor' , 'Valor valido' ); |
No meu caso, tenho datas e não achei uma forma de fazer
1 2 3 4 | if DayOfWeek(Date) = 2 then dtpInicio . Date := Date - 2 else dtpInicio . Date := Date; |
Você pode usar o IfThen também com datas.
Adicione Math na uses.
Teste este código:
1 | dtpInicio . Date := IfThen(DayOfWeek(Date) = 2 , Date - 2 , Date); |
Gostei + 0
20/08/2024
Renan
Gostei + 0
03/09/2024
Renan
A ideia seria reduzir essas 4 linhas em 1 linha.
1 2 3 4 | if FieldByName( 'FLUXO_CAIXA' ).AsString <> 'S' then FrmPrincipal . FluxodeCaixa1 . Enabled := False else FrmPrincipal . FluxodeCaixa1 . Enabled := True ; |
tentei assim, mas não funciona
1 | FrmPrincipal . FluxodeCaixa1 . Enabled := ifThen(FieldByName( 'FLUXO_CAIXA' ).AsString <> 'S' , False , True ); |
Gostei + 0
04/09/2024
Natanael Ferreira
Teste assim:
1 | FrmPrincipal . FluxodeCaixa1 . Enabled := FieldByName( 'FLUXO_CAIXA' ).AsString = 'S' ; |
Gostei + 0
04/09/2024
Renan
Teste assim:
1 | FrmPrincipal . FluxodeCaixa1 . Enabled := FieldByName( 'FLUXO_CAIXA' ).AsString = 'S' ; |
Natanael,
Sim, obrigado pela ajuda. Ficou ótimo.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)