Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  345

•  TDictionary Custom Sort  3 489

•  Fast Watermark Sources  3 236

•  3D Designer  5 001

•  Sik Screen Capture  3 489

•  Patch Maker  3 695

•  Айболит (remote control)  3 895

•  ListBox Drag & Drop  3 157

•  Доска для игры Реверси  82 852

•  Графические эффекты  4 096

•  Рисование по маске  3 389

•  Перетаскивание изображений  2 762

•  Canvas Drawing  2 912

•  Рисование Луны  2 719

•  Поворот изображения  2 332

•  Рисование стержней  2 224

•  Paint on Shape  1 625

•  Генератор кроссвордов  2 305

•  Головоломка Paletto  1 822

•  Теорема Монжа об окружностях  2 326

•  Пазл Numbrix  1 716

•  Заборы и коммивояжеры  2 091

•  Игра HIP  1 313

•  Игра Go (Го)  1 260

•  Симулятор лифта  1 508

•  Программа укладки плитки  1 257

•  Генератор лабиринта  1 580

•  Проверка числового ввода  1 400

•  HEX View  1 534

•  Физический маятник  1 385

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Искать текст в TListView



Заходит как то программист в комп.магазин долго ходил смотрел всё высматривал потом подходит к продавщице и просит посмотреть каталог, потом минуту спустя спрашивает:
- Извинити это у вас цены или номера ICQ???


// Call FindCaption Method to search for a list view item labeled by the 
// string specified as the Value parameter 


// Syntax: 

function FindCaption(StartIndex: Integer; Value: string; 
  Partial, Inclusive, Wrap: Boolean): TListItem; 


// Example, Beispiel: 

procedure TForm1.Button1Click(Sender: TObject); 
var 
  lvItem: TListItem; 
begin 
  lvItem := ListView1.FindCaption(0,      // StartIndex: Integer; 
                                  '99',   // Search string: string; 
                                  True,   // Partial, 
                                  True,   // Inclusive 
                                  False); // Wrap  : boolean; 
  if lvItem <> nil then 
  begin 
    ListView1.Selected := lvItem; 
    lvItem.MakeVisible(True); 
    ListView1.SetFocus; 
  end; 
end; 


// To search for a list view subitem (also for items), use this function: 

{ 
  Search for text in a listview item 
  @Param lv is the listview, supposed to be in vaReport mode 
  @Param S is the text to search for 
  @Param column is the column index for the column to search , 0-based 
  @Returns the found listview item, or Nil if none was found 
  @Precondition  lv  nil, lv in report mode if column  0, S not empty 
  @Desc The search is case-insensitive and will only match on the 
  complete column content. Use AnsiContainsText instead of AnsiCompareText 
  to match on a substring in the columns content. 
  Created 14.10.2001 by P. Below 
} 

function FindListViewItem(lv: TListView; const S: string; column: Integer): TListItem; 
var 
  i: Integer; 
  found: Boolean; 
begin 
  Assert(Assigned(lv)); 
  Assert((lv.viewstyle = vsReport) or (column = 0)); 
  Assert(S <> ''); 
  for i := 0 to lv.Items.Count - 1 do 
  begin 
    Result := lv.Items[i]; 
    if column = 0 then 
      found := AnsiCompareText(Result.Caption, S) = 0 
    else if column > 0 then 
      found := AnsiCompareText(Result.SubItems[column - 1], S) = 0 
    else 
      found := False; 
    if found then 
      Exit; 
  end; 
  // No hit if we get here 
  Result := nil; 
end; 

// Example call: 

procedure TForm1.Button1Click(Sender: TObject); 
var 
  lvItem: TListItem; 
begin 
  // Search subitem[0] for text from edit1 
  // in der Spalte subitem[0] den Text aus Edit1 suchen 
  lvItem := FindListViewItem(ListView1, Edit1.Text, 1); 
  // if found, then show the item 
  // falls item gefunden, dann anzeigen 
  if lvItem <> nil then 
  begin 
    ListView1.Selected := lvItem; 
    lvItem.MakeVisible(True); 
    ListView1.SetFocus; 
  end; 
end; 


// Function to search items and select if found 

procedure LV_FindAndSelectItems(lv: TListView; const S: string; column: Integer); 
var 
  i: Integer; 
  found: Boolean; 
  lvItem: TListItem; 
begin 
  Assert(Assigned(lv)); 
  Assert((lv.ViewStyle = vsReport) or (column = 0)); 
  Assert(S <> ''); 
  for i := 0 to lv.Items.Count - 1 do 
  begin 
    lvItem := lv.Items[i]; 
    if column = 0 then 
      found := AnsiCompareText(lvItem.Caption, S) = 0 
    else if column > 0 then 
    begin 
      if lvItem.SubItems.Count >= Column then 
        found := AnsiCompareText(lvItem.SubItems[column - 1], S) = 0 
      else  
        found := False; 
    end 
    else 
      found := False; 
    if found then 
    begin 
      lv.Selected := lvItem; 
    end; 
  end; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
var 
  lvItem: TListItem; 
begin 
  // in der Spalte subitem[0] den Text aus Edit1 suchen 
  LV_FindAndSelectItems(ListView1, Edit1.Text, 1); 
  ListView1.SetFocus; 
end;





Похожие по теме исходники

Image2Text (изображение в текст)

Генератор текстур

TextureGen (генератор текстур)

Текст Drag & Drop

 

Текст по синусоиде

Текст внутри файла

Зеркальный текст




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте