Codigo nao funciona!

Delphi

14/04/2012

//Se Selecionado uma das opções dos ComboBox, mostre-me Form3: Oculte o Form2.
if
(sComboBox1.ItemIndex = 0 or 1)and
(sComboBox2.ItemIndex = 0 or 1 or 2)and
(sComboBox3.ItemIndex = 0 or 1 or 2 or 3)and
(sComboBox4.ItemIndex = 0 or 1) then

  begin
    Form3 := TForm3.Create(Application);
    Hide;
    Form3.ShowModal;
  end;

Não aparece o form3 quando clico no botão :\, por que será?
Jhonnatas F

Jhonnatas F

Curtidas 0

Respostas

Marco Salles

Marco Salles

14/04/2012

//Se Selecionado uma das opções dos ComboBox, mostre-me Form3: Oculte o Form2.
if
(sComboBox1.ItemIndex = 0 or 1)and
(sComboBox2.ItemIndex = 0 or 1 or 2)and
(sComboBox3.ItemIndex = 0 or 1 or 2 or 3)and
(sComboBox4.ItemIndex = 0 or 1) then

  begin
    Form3 := TForm3.Create(Application);
    Hide;
    Form3.ShowModal;
  end;

Não aparece o form3 quando clico no botão :\, por que será?



utilize o case

case sComboBox2.ItemIndex of
0,1,2,3:
begin
    Form3 := TForm3.Create(Application);
    try
    Hide;
    Form3.ShowModal;
    finally
     Form3.free;
     form3:=nil;
    end;
end;
end;
GOSTEI 0
Jhonnatas F

Jhonnatas F

14/04/2012

mas como faço usando os 4 combobox?

tipo...?
case sComboBox1.ItemIndex of 0,1 and
     sComboBox2.ItemIndex of 0,1 and
     sComboBox3.ItemIndex of 0,1 and
     sComboBox4.ItemIndex of 0,1:
 begin
 //codigo
 end;


GOSTEI 0
Bruno Leandro

Bruno Leandro

14/04/2012

if
(sComboBox1.ItemIndex in [0,1])and
(sComboBox2.ItemIndex in [0,1,2])and
(sComboBox3.ItemIndex in [0,1,2,3])and
(sComboBox4.ItemIndex in [0,1]) then
begin
.
.
.
GOSTEI 0
Jhonnatas F

Jhonnatas F

14/04/2012

Bruno Leandro também não funcionou.

Todo Código do Botão:


procedure TForm2.sBitBtn1Click(Sender: TObject);
begin

if (sComboBox1.ItemIndex < 0)or(sComboBox1.ItemIndex > 1)or
(sComboBox2.ItemIndex < 0)or(sComboBox2.ItemIndex > 2)or
(sComboBox3.ItemIndex < 0)or(sComboBox3.ItemIndex > 3)or
(sComboBox4.ItemIndex < 0)or(sComboBox4.ItemIndex > 1)then
  begin
    Application.MessageBox(ERROR!,ERROR!,mb_iconerror);
    sComboBox1.ItemIndex := 0;
    sComboBox2.ItemIndex := 2;
    sComboBox3.ItemIndex := 1;
    sComboBox4.ItemIndex := 1;
  end;

if
(sComboBox1.ItemIndex in [0,1])and
(sComboBox2.ItemIndex in [0,1,2])and
(sComboBox3.ItemIndex in [0,1,2,3])and
(sComboBox4.ItemIndex in [0,1])then
  begin
    Form3:= TForm3.Create(Application);
    Hide;
    Form3.ShowModal;
  end;



É porque quando altero o item dentro do combobox em runtime, e clico no botão era pra aparecer aquela mensagem lá em cima, aliás, aparece, mas o form3 abre, coisa que não era pra acontecer...

Agora se as opções estiverem conforme os index corretos sem alteração , aí sim o form3 pode aparecer.

Existe alguma opção do combobox que eu possa ativar ou alterar para que não aceite alterações dos items?

Agradeço!!
GOSTEI 0
Jhonnatas F

Jhonnatas F

14/04/2012

Consegui.. era a forma com que o código estava organizado:

de:
if (sComboBox1.ItemIndex < 0)or(sComboBox1.ItemIndex > 1)or
(sComboBox2.ItemIndex < 0)or(sComboBox2.ItemIndex > 2)or
(sComboBox3.ItemIndex < 0)or(sComboBox3.ItemIndex > 3)or
(sComboBox4.ItemIndex < 0)or(sComboBox4.ItemIndex > 1)then
  begin
    Application.MessageBox(ERROR!,ERROR!,mb_iconerror);
    sComboBox1.ItemIndex := 0;
    sComboBox2.ItemIndex := 2;
    sComboBox3.ItemIndex := 1;
    sComboBox4.ItemIndex := 1;
  end;

if
(sComboBox1.ItemIndex in [0,1])and
(sComboBox2.ItemIndex in [0,1,2])and
(sComboBox3.ItemIndex in [0,1,2,3])and
(sComboBox4.ItemIndex in [0,1])then
  begin
    Form3:= TForm3.Create(Application);
    Hide;
    Form3.ShowModal;
  end;


para:

if
(sComboBox1.ItemIndex in [0,1])and
(sComboBox2.ItemIndex in [0,1,2])and
(sComboBox3.ItemIndex in [0,1,2,3])and
(sComboBox4.ItemIndex in [0,1])then
  begin
    Form3:= TForm3.Create(Application);
    Hide;
    Form3.ShowModal;
  end;

if (sComboBox1.ItemIndex < 0)or(sComboBox1.ItemIndex > 1)or
(sComboBox2.ItemIndex < 0)or(sComboBox2.ItemIndex > 2)or
(sComboBox3.ItemIndex < 0)or(sComboBox3.ItemIndex > 3)or
(sComboBox4.ItemIndex < 0)or(sComboBox4.ItemIndex > 1)then
  begin
    Application.MessageBox(ERROR!,ERROR!,mb_iconerror);
    sComboBox1.ItemIndex := 0;
    sComboBox2.ItemIndex := 2;
    sComboBox3.ItemIndex := 1;
    sComboBox4.ItemIndex := 1;
  end;
GOSTEI 0
Marco Salles

Marco Salles

14/04/2012

Desculpe eu não tinha reparado que se trata de 4 combobox . Porém no seu novo códgo entendo ter uma redundância

Porque DOIS Ifs se o segundo é not o primeiro ???

if
(sComboBox1.ItemIndex in [0,1])and
(sComboBox2.ItemIndex in [0,1,2])and
(sComboBox3.ItemIndex in [0,1,2,3])and
(sComboBox4.ItemIndex in [0,1])then
begin
Form3:= TForm3.Create(nil);
try
Hide;
Form3.ShowModal;
finaly
Form3.free;
form3:=nil;
end;
end
else
begin
Application.MessageBox(ERROR!,ERROR!,mb_iconerror);
sComboBox1.ItemIndex := 0;
sComboBox2.ItemIndex := 2;
sComboBox3.ItemIndex := 1;
sComboBox4.ItemIndex := 1;
end;

GOSTEI 0
Jhonnatas F

Jhonnatas F

14/04/2012

obrigado Marco Antonio Sales =)
GOSTEI 0
Marco Salles

Marco Salles

14/04/2012

obrigado Marco Antonio Sales =)


Beleza Jhonnatas , mas atente que voce esta criando o Form3 e não o esta destruindo

de modo que voce terá MemoryLeaks na aplicação

percea a forma que eu utilizei

try
Form3.ShowModal;
finaly
Form3.free;
form3:=nil;

sugiro voce utiliza-lo assim tb
GOSTEI 0
POSTAR