Forum > Databases

[SOLVED] SQLite search edit background color

(1/2) > >>

Pe3s:
Hello, is it possible to make such a search engine functionality
1. empty edit control white
2. if found green
3. if not found color red
4. if we clear the control it returns to white


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Edit1Change(Sender: TObject);begin  with ZQuery1 do begin  SQL.Clear;  SQL.Text := 'SELECT * FROM baza WHERE Nazwisko LIKE :Nazwisko';  Active := False;  ParamByName('Nazwisko').AsString := Edit1.Text + '%';  Active := False;  Open;end;end;

dseligo:
Try this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Edit1Change(Sender: TObject);begin  If (Sender as TEdit).Text = '' then begin    (Sender as TEdit).Color := clDefault;    Exit;  end;   with ZQuery1 do begin    // SQL.Clear; // you don't need this if you directly set SQL.Text property    SQL.Text := 'SELECT * FROM baza WHERE Nazwisko LIKE :Nazwisko'; // If you use ZEOSdbo you don't need Active := False at beginning    // Active := False; // don't need this here    ParamByName('Nazwisko').AsString := (Sender as TEdit).Text + '%';    // Active := False; // don't need this here    Open;    If Eof then (Sender as TEdit).Color := clRed           else (Sender as TEdit).Color := clGreen;  end;end;

Zvoni:
Wouldn't use the Change-Event, rather KeyUp
OnChange is only useful in this context if you Copy/Paste your search-Text into the TEdit

btw: Don't you have to close the Query first?
With this code you'd open the query every time you type a new letter without having closed it

And don't use SELECT * FROM

dseligo:

--- Quote from: Zvoni on May 12, 2022, 08:15:31 am ---Wouldn't use the Change-Event, rather KeyUp
OnChange is only useful in this context if you Copy/Paste your search-Text into the TEdit

--- End quote ---

Why, what's wrong with OnChange event? Wouldn't OnKeyUp react also to arrow keys and similar, causing unnecessary queries to the database?


--- Quote from: Zvoni on May 12, 2022, 08:15:31 am ---btw: Don't you have to close the Query first?
With this code you'd open the query every time you type a new letter without having closed it

--- End quote ---

If you use ZEOSdbo and assign to SQL.Text, you don't need to close query first. I assume he uses ZEOS because query is named ZQuery1.
Although, I would rather use prepared query and only change parameter (then query should be closed first).

Zvoni:

--- Quote from: dseligo on May 12, 2022, 02:28:15 pm ---Why, what's wrong with OnChange event? Wouldn't OnKeyUp react also to arrow keys and similar, causing unnecessary queries to the database?

--- End quote ---
Exactly because of that. You can filter "illegal" keys.
the OnChange-Event doesn't ship the Key being pressed.

Now imagine having a "Search-History" (stored in a List or whatever).
And now imagine pressing the Arrow-Down-Button to quickswitch to the searchphrase before your current one.....

EDIT: And just looking at his First Post, i'm going to throw a Spanner into the gearbox, and enter a "%" as the first Character using his code....

EDIT2: btw: Or i'd use OnKeyDown in that case....

Navigation

[0] Message Index

[#] Next page

Go to full version