It is necessary to make a request for output in the form of a table in Delphi. There is a request code:

Query1.Active := False; Query1.SQL.Clear; Query1.SQL.Add('select * from table1 where nazvanie like ' +chr(39) + Edit2.Text + chr(39)); Query1.Active := true; 

When I enter a name, for example, a ΠΏΠΈΠ»Π° , it makes a selection for me and gives out a ΠΏΠΈΠ»Π° and + all values ​​in the fields. It is necessary to make it so that if there is a ΠΏΠΈΠ»Π° in the field, ΠΏΠΈΠ»Π° 2 , ΠΏΠΈΠ»Π° 3 , then they are derived from the similarity: ΠΏΠΈΠ»Π° , ΠΏΠΈΠ»Π° 2 , ΠΏΠΈΠ»Π° 3 .

  • If I needed to filter records by typed in edit text, then I would do it using filtering. And yet, it is not very clear in the request itself, where table1 is written - is this the name of the table in the database or is it the so called component? - DelphiM0ZG
  • There is a table, and if you can write a filtering code - Pavel Borshchev

2 answers 2

In the Edit event OnChange event handler, you need to write code.

 procedure TDataBaseForm.Edit1Change(Sender: TObject); begin If (Edit1.Text = '') Then Table1.Filtered:=True Else Table1.Filtered:=False; Table1.Filter:='НазваниС поля (Ρ‚ΠΎ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ Π² Ρ‚Π°Π±Π»ΠΈΡ†Π΅ Π‘Π”, Π² Π’Π°ΡˆΠ΅ΠΌ случаС nazvanie) > '+QuotedStr(EditFind.Text); end; 

And in the OnFilterRecord handler of the data set (Table or query) such code.

 procedure TForm1.Table1FilterRecord(DataSet: TDataSet; var Accept: Boolean); begin Accept:=False; If (Copy(<имя поля (Π² инспСкторС ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° ΠΏΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΌΠΎΠΆΠ½ΠΎ)>.AsString, 1, Length(Edit1.Text))= Edit1.Text) Then Accept:=True; end; 

If everything is correct, then when you enter the initial part of the word in Edit, the data in the table should be filtered. For example, if one letter is written in the Edit, then the table will show entries starting with it.

    'select * from table1 where nazvanie like' + Edit2.Text + '% ORDER BY nazvanie'