Solved

Multiple DB filtering

Posted on 2002-04-14
13
205 Views
Last Modified: 2010-04-04
I use next code to filter my table :

table1.filter := 'GRUPA= ''A05AA02'' or GRUPA= ''A06AD11'' or GRUPA= ''A07AA11'' or GRUPA= ''C03AA03'' or GRUPA= ''C03CA01'' or GRUPA= ''C03DA01'' or GRUPA= ''C07AA05'' or GRUPA= ''H02AB04'' or GRUPA= ''J01CA01'' or GRUPA= ''J01MA02'' or GRUPA= ''J01MA06'' or GRUPA= ''J05AF05'' or GRUPA= ''L04AX01'' or GRUPA= ''V03AC01'' or GRUPA= ''H02AB07''';

table1.filtered := true;

The problem is that my string is longer than 256 characters and I get an error message when compile the project.

Any suggestion how can I step over this problem?
0
Comment
Question by:ginsonic
  • 4
  • 4
  • 2
  • +3
13 Comments
 
LVL 3

Accepted Solution

by:
marcoszorrilla earned 100 total points
ID: 6940469
Split the string
you must load for example S1 with 250 characters for example and S2 with the rest

Var
S1,S2:String

Table1.filter:=S1+S2
Table1.Filtered:=True;

Best regards.
Marcos.
0
 
LVL 15

Expert Comment

by:simonet
ID: 6940857
Try this:

table1.filter := '( GRUPA IN (''A05AA02'', ''A06AD11'', ''A07AA11'', ''C03AA03'' , ''C03CA01'', ''C03DA01'', ''C07AA05'', ''H02AB04'', ''J01CA01'', ''J01MA02'', ''J01MA06'', ''J05AF05'', ''L04AX01'', ''V03AC01'', ''H02AB07''))';

table1.filtered := true;



if the code above works it will not only sole the large string problem, but the filtering will also be faster.

Yours,

Alex
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6941212
It also works when splitting up the string in your code without the use of variables:

Table1.Filter := 'first part < 255 charachters' +
  'second part < 255 charachters' +
  'third part < 255 charachters' +
  'etc...';

Regards Jacco
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6941213
With complex filters that change often it might also be better to use the OnFilterRecord event.

Regards Jacco
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6941260
i would use a tquery instead a ttable,
if there are such complex (where) clauses
affected

meikl ;-)
0
 
LVL 9

Author Comment

by:ginsonic
ID: 6941802
kretzschmar can you tell me more ? Untill now I have used just table+dataSource+DBGrid in my projects :(

I wish to say that I have couple situations when I use ~50 conditions for filtering .
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Author Comment

by:ginsonic
ID: 6941835
simonet , your suggestion get me an error message alike 'Operation not applicable' for this.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6941895
guessing simonets suggestion
is not supported by your database :-(

you can do the same as the ttable with a tquery+tdatasource+tdbgrid+tupdatesql (as updateobject of the tquery, if editing, deletes and inserts may possible)

lets say we have a sql-statement like

select * from atable

this shows all entries of atable

if you want to filter, you modify the sql-statement like
select * from atable where condition

you can do this on the fly like

function get_filter_sql(atable, awhereclause : String)
const
  sqltextnowhere := 'select * from atable %s';
  sqltextwhere := sqltextnowhere+' where %s';
begin
  if awhereclause = '' then
   result := format(sqltextnowhere,[atable])
  else
   result := format(sqltextwhere,[atable,awhereclause])
end;

usage sample

query1.close;
query1.sql.text := get_filter_sql(yourtable,yourfilter);
query1.open;

hope this helps

meikl ;-)
0
 
LVL 9

Author Comment

by:ginsonic
ID: 6942407
Look a little more complicated . What's the difference between my filtering and the query's one ?
What gain using a query ?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6942506
usual on sql-databases it is recommended to work with queries
-lower overhead
-faster results
-you can order the result by any field(s) with an order by clause

there should be no difference
in the result of the query
and the filtering

in your case, you use dbase,
i guess from previous q's,
it is a workaround

meikl ;-)
0
 
LVL 4

Expert Comment

by:nestorua
ID: 6942918
HI, ginsonic,
If you don't want to use TQuery component and use TTable one
for your purpose it would be reasonable to use OnFilterRecord
event.
Create TStringList, fill it with your specific strings
('A05AA02', ...) and write the following
Accept:=StringListName.IndexOf(GRUPA.AsString)<>-1.
That's all.
Sincerely,
Nestorua.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6943067
yep, this may also a solution, Nestorua
0
 
LVL 9

Author Comment

by:ginsonic
ID: 6955969
I choice a different way to step over my problem ( not proposed here ) but this is the first working solution .

Thanks to all experts,

Nick aka ginsonic
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 73
select query - oracle 16 94
how can i search if string exist in array ? 3 49
DBGrid or StringGrid ? 6 70
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now