Mega Code Archive

 
Categories / Delphi / VCL
 

Comboboxta otomatik tamamlama ve türkçe arama

unit comboUtils; ... const Digits = ['0','1'..'9']; TrkLetters = ['ç','Ç','ğ','Ğ','ı','İ','ö','Ö','ş','Ş','ü','Ü']; Letters = ['a'..'z','A'..'Z'] + TrkLetters; Punctuals = [' ', '.', ',', '!', '?', ':', ';', '^', '"', '''', '%', '$', '(', ')', '[', ']', '{', '}', '_', '+', '-', '*', '\', '/']; var TrkUpCase : array [Char] of Char; function UpperCaseTrk(const s: string): string; function NearestItemAtList(Text : string; List : TStrings; ... function UpperCaseTrk(const s: string): string; var j: integer; begin // Char map array her harf için büyük harfe dönüştürmek için upcase ve uzun case, if kontrolleri kullanmaktan daha hızlı result := S; for J := 1 to Length(S) do result[J] := TrkUpCase[result[J]]; end; function NearestItemAtList(Text : string; List : TStrings; caseSensitive : boolean) : string; var upstr : string; i : integer; begin result := Text; i := 0; try if caseSensitive then begin while (i < List.Count - 1) and (Pos(Text, List[i]) <> 1) do Inc(i); if Pos(Text, List[i]) = 1 then result := List[i]; end else begin upstr := UpperCaseTrk(Text); while (i < List.Count - 1) and (Pos(upstr, UpperCaseTrk(List[i])) <> 1) do Inc(i); if Pos(upstr, UpperCaseTrk(List[i])) = 1 then result := List[i]; end; except result := Text; end; end; ... var C: char; begin for C := Low(TrkUpCase) to High(TrkUpCase) do case C of 'ç', 'Ç' : TrkUpCase[C] := 'Ç'; 'ğ', 'Ğ' : TrkUpCase[C] := 'Ğ'; 'ı', 'I' : TrkUpCase[C] := 'I'; 'i', 'İ' : TrkUpCase[C] := 'İ'; 'ö', 'Ö' : TrkUpCase[C] := 'Ö'; 'ş', 'Ş' : TrkUpCase[C] := 'Ş'; 'ü', 'Ü' : TrkUpCase[C] := 'Ü'; else TrkUpCase[C] := UpCase(C); end; end. ... uses comboUtils; ... procedure TForm1.myComboBoxKeyPress(Sender: TObject; var Key: Char); var fs, s: string; myComboBox: TCustomComboBox; begin if Sender is TCustomComboBox then try myComboBox := TCustomComboBox(Sender); if Key in Letters + Digits + Punctuals then begin S := Key; // Türkçe Büyük harfe çevirmek gerekebilir. Key := #0; MyComboBox.SelText := S; S := MyComboBox.Text; myComboBox: TComboBox; // TCustomComboBox; Sorunu çözer. MyComboBox.Text := NearestItemAtList(S, MyComboBox.Items, FALSE); MyComboBox.DroppedDown := MyComboBox.DroppedDown or (S <> MyComboBox.Text); MyComboBox.SelStart := Length(S); MyComboBox.SelLength := Length(MyComboBox.Text) - Length(S); myComboBoxChange(MyComboBox); end else begin if Key = #13 then begin Key := #0; S := MyComboBox.Text; MyComboBox.DroppedDown := FALSE; MyComboBox.Text := S; MyComboBox.ItemIndex := MyComboBox.Items.IndexOf(S); MyComboBoxChange(MyComboBox); end else if Key = #27 then begin Key := #0; MyComboBox.DroppedDown := FALSE; end; end; except end; end; procedure TMainBirSForm.myComboBoxChange(Sender: TObject); begin if Trim(MyComboBox.Text) <> '' then MyComboBox.ItemIndex := MyComboBox.Items.IndexOf(MyComboBox.Text); end; ...