Ir al contenido


Foto

[TRUCO DELPHI] Verificar si un elemento existe en una Listbox/Combobox/Memo.


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 sir.dev.a.lot

sir.dev.a.lot

    Advanced Member

  • Miembros
  • PipPipPip
  • 545 mensajes
  • Location127.0.0.1

Escrito 25 agosto 2016 - 11:35

[TRUCO DELPHI] Verificar si un elemento existe en una Listbox/Combobox/Memo.


delphi
  1. function StrIsInList(
  2. sl : TStrings;
  3. s : string;
  4. bCaseSensitive : boolean )
  5. : boolean;
  6. var
  7. n : integer;
  8. begin
  9. Result := False;
  10. if( not bCaseSensitive )then
  11. s := LowerCase( s );
  12. for n := 0 to ( sl.Count - 1 ) do
  13. begin
  14. if( ( bCaseSensitive and
  15. ( s = LowerCase(
  16. sl.Strings[ n ] ) ) )
  17. or ( s = sl.Strings[ n ] )
  18. )then
  19. begin
  20. Result := True;
  21. Exit;
  22. end;
  23. end;
  24. end;

Ejemplo de Uso:


delphi
  1. procedure
  2. TForm1.Button1Click(Sender: TObject);
  3. begin
  4. if( not StrIsInList( ListBox1.Items,
  5. Edit1.Text, False ) ) then
  6. ListBox1.Items.Add( Edit1.Text );
  7. end;

Saludos!


  • 2




IP.Board spam blocked by CleanTalk.