Ver Mensaje Individual
  #2  
Antiguo 19-11-2013
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Alejandro73,

Cita:
Empezado por Alejandro73
...Comparar un String con el contenido de un Arreglo...al intentar comparar los valores no lo encuentra...
Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ArrOpc  : Array [1..5] of String = ('Opcion1','Opcion2','Opcion3','Opcion4','Opcion5');

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
   i : Integer;
begin
   for i := 0 to 9 do
      ComboBox1.Items.Add('Opcion' + IntToStr(i+1));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   i : Integer;
   B : Boolean;

begin

   if ComboBox1.Text <> EmptyStr then
   begin

      for i := Low(ArrOpc) to High(ArrOpc) do
         if ComboBox1.text = ArrOpc[i] then
         begin
            MessageDlg('Item Encontrado en el Arreglo en la Posicion = ' + IntTostr(i),mtInformation,[mbOK],0);
            B := True;
         end;

      if not B then
         MessageDlg('Item No Encontrado en el Arreglo',mtError,[mbOK],0)

   end
   else
     MessageDlg('No se Ha seleccionado Ningún Item',mtError,[mbOK],0);

end;

end.
El código anterior compara los elementos de un arreglo con los elementos de un TComboBox.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 19-11-2013 a las 21:21:17.
Responder Con Cita