Forum > General
[SOLVED] Lazarus | locate on numeric field
micoudic:
Hi,
I am doing incremental searches from a DBGRID. This works perfectly, but for string fields only.
I'm trying to do the same on numeric fields. I defined them in currency, because it is the only format that allows me to enter the decimal place. This almost works, except that from the 3rd digit entered, nothing changes. It doesn't crash, but it's like I can't grasp anything anymore.
I enter the search criteria from an Edit on the Form (named "Edt_Recherche_Num")
--- 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 TForm_01.Edt_Recherche_NumChange(Sender: TObject);var WKleSearchN: string;begin if (Edt_Recherche_Num.Text = '') or (Edt_Recherche_Num.Text = '0') then Abort; WKleSearchN := Edt_Recherche_Num.Text; Datamodule1.DB_Annonces.Locate(WFieldName,WKleSearchN,[loPartialKey])end;
I also tried with this instruction
--- 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";}};} ---WKleSearchN := StrToCurr(Edt_Recherche_Num.Text);
But without change.
By changing the field type to Integer, I have not more success.
Of course, my fields are indexed
I can't find any info for a locate with a digital key
Thanks
Mint 20
Lazarus 2.0.3
dBase7 files
jamie:
I am not an expert in Db-coding but I see a couple of issues.
First off, you need to use "EXIT" instead of Abort, because about works with a TRY statement at some point before this code.
It's to raise an exception early.
Also, you should be converting the string data from edit to a currency for test.
if StrToCurr(TheEditString) = 0.0 then.....
etc
paweld:
Locate is a function and returns True if successful.
Sample in attachment
micoudic:
Small details:
I use 2 distinct procedures for my incremental searches
1- a procedure for searching on String fields (there are specific additional treatments in this procedure which do not need to be in searches on numeric fields)
2- in procedure for searching numeric fields.
You will notice that I defined a variable "WKleSearchN" inside this procedure. This variable is normally defined at the very beginning of the unit. But as I had to make numerous (unsuccessful) attempts, I found more practical to redefine this variable in the search procedure, which avoids me, each time, going back to the very beginning of the unit to modify the type of this variable.
This is why, in the code cited above, this variable is of type String. This is the last test that I carried out, but obviously, I tested all kinds of combinations, without perfect results.
Concerning the research, in the current state, I noticed this:
if the column I want to search for contains
5.00
52.15
68.87
525.18
525.23
525.32
638.55
....
Entries Result
5 OK out of 5.00
52 OK out of 52.18
525 Remains on 52.18
525. Rest on 52.18
525.3 Rest on 52.18
525.32 OK
525.32 : The cursor only moves if, and only if, the exact amount is found.
This is not what I expect from my research, but to be able to get as close as possible to the amount I am looking for, not knowing in advance the exact amount, to the nearest cent.
To Jamie:
Abort suits me perfectly. I don't need to do a search if the input edit is blank or zeros. This is the case when I go back, or when I reset the research edit. But maybe I'm missing something?
a paweld
I downloaded your program, but cannot test it.
when trying to compile, I get the following messages
--- 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";}};} ---Compilation du projet - Cible : project1 : Code de sortie 1 - Erreurs : 1Unit1.pas(8,22) Fatal: Impossible de trouver Forms utilisé par Unit1. Vérifier que le paquet LCLBase est dans les dépendances.
TryStrToFloat: I didn't know this function. I will test with this function.
I tested with the StrToFloat function, without entirely satisfactory results.
Zvoni:
The second argument of Locate is a Variant
https://www.freepascal.org/docs-html/fcl/db/tdataset.locate.html
Since you're passing your variable WKleSearchN, which IS of Type String, why do you expect it to work on Floating points?
Navigation
[0] Message Index
[#] Next page