E
E
Evgeny Ivanov2019-04-10 07:43:39
Delphi
Evgeny Ivanov, 2019-04-10 07:43:39

How to organize data selection by condition?

RAD Studio 10.1 Berlin software.
Everything works, but you need to change the code. Namely, somehow remove the condition from the code to an external file, so that it can be changed. In the meantime, the condition is "sewn" into the program.
The meaning of the program is that there is a two-dimensional array that needs to be filtered. (A sort of table - simplified.)
The array consists of 100 elements and 50,000 rows.
Filtering is carried out by the first 5-6 fields.
The filter conditions are equal, not equal, contains, and, or.
Condition matched - no error, array string passes. And all this is now in the program code.
But conditions are changing. Like their meanings, so sometimes logic is a sequence.
Example

if ((A1='1') and (CountPos('A13.29',A2)>0) and (A3='73') and (A4='97') and (A5='3')) then error:=0;

CountPos - content search function (contains).
And tomorrow may be necessary
if ((A1='222') and (CountPos('A13.29',A2)>0) or (A3='73') and (A4!='97') and (A5='3')  and (A5<>'4')) then error:=0;

What doesn't change.
Names of variables A1, A2...A6.
Their maximum number is 6, i.е. A7 will never be in the code.
Condition type.
Inside brackets, up to OPERATOR no more than 3x.
In total, there are no more than 4 combinations of "triples" of conditions.
if (
((условие 1) оператор (условие 2) оператор  (условие 3)) ОПЕРАТОР 
((условие 1) оператор (условие 2) оператор  (условие 3))  ОПЕРАТОР 
((условие 1) оператор (условие 2) оператор  (условие 3))  ОПЕРАТОР 
((условие 1) оператор (условие 2) оператор  (условие 3))
) then begin end;

How to organize data selection by condition?
Thought ideas?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Ronald McDonald, 2019-04-10
@Zoominger

The array has 100 elements and 50,000 rows.

Out of 100 elements or columns?
It's not entirely clear why it's an array if it's supposed to be a database, but delphists can.
Although no, you can't. Drive data into some MySQL and make an interface to it, then any queries can be done easily and simply.
Well, or write your own parser and binding to the "array", then you can do almost the same thing, but through one place. In this case, the user will enter something like "!A1>2!A2=3", the program will parse the string and make the necessary requests. You can read this topic, lol: https://www.sql.ru/forum/708369/razrabotal-drayver...

K
kalapanga, 2019-04-10
@kalapanga

Support Ronald McDonald . The database is requested here. I think even some SQLLite will do. And edit requests as you like.
If you solve the problem completely according to the written one, then you can try to fasten something like this: https://www.remobjects.com/ps.aspx But I didn’t use it, I can’t guarantee anything.

K
Konstantin Tsvetkov, 2019-04-10
@tsklab

When using XLSReadWriteI , you can store conditions in a text file and load them via VBA Macros.

Z
zed, 2019-04-10
@zedxxx

There are options:
1. Draw a gui so that it repeats the maximum combination, as you gave in the example. Those. for each position (condition N) you give the opportunity to choose a variable, with what and how to compare it. Moreover, you make the fields optional, i.e. so that some can be left blank.
Here is an example of how something similar is done in TheBat!
2. Connect a scripting language ( Lua or Pascal-like DWScript , RemObjects PascalScript ) and write simple instructions for users.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question