Re: Filter of TObjects
From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 09/22/04
- Next message: Maarten Wiltink: "Re: InternetOpen - help needed."
- Previous message: Rob Kennedy: "Re: MaskEdit for IP Address"
- In reply to: Bernd Pocher: "Filter of TObjects"
- Next in thread: Bjørge Sæther: "Re: Filter of TObjects"
- Reply: Bjørge Sæther: "Re: Filter of TObjects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 22 Sep 2004 10:13:41 +0200
"Bernd Pocher" <BerndPocher@freenet.de> wrote in message
news:4150a2ad$0$32699$9b622d9e@news.freenet.de...
> I have some lists with different TObjects and I will filtering this
> with a statement e.g.
> val1 = 20 and val2 = 'hallo' or val3 = Green
TObject does not have val1, val2, or val3 properties. You need to
assume/enforce that the list contains only objects that do. The
big problem is to let the compiler know it; options are casting or
querying for interfaces.
> val1 = integer
> val2 = string
> val3 = set of or enumerates
>
> I don't have writen a filter without a database any time. So I need
> background information. Or exists anywhere a control?
This is a real programming problem. Be prepared to write actual code,
hundreds or thousands of lines.
The actual filtering code isn't hard, because it defers all the hard
work. (This is called top-down programming.)
i:=0;
while (i<list.count) do begin
if pass_filter(list.items[i], test)
then inc(i)
else list.delete(i);
end;
Pass_filter() is a function that performs a test (second parameter) on
an object (first parameter). Do not underestimate the thought that
should go into the test parameter. The first candidate is perhaps a
string "(val1=20) and (val2='hallo') and (val3=green)", but that
means you have to interpret that string, fill in the variables from the
object you have, and evaluate the resulting expression. Well, you
probably have to do that anyway, but you can do a lot of preprocessing
so the "test" passed to pass_filter can be an object of your own
devising.
Groetjes,
Maarten Wiltink
- Next message: Maarten Wiltink: "Re: InternetOpen - help needed."
- Previous message: Rob Kennedy: "Re: MaskEdit for IP Address"
- In reply to: Bernd Pocher: "Filter of TObjects"
- Next in thread: Bjørge Sæther: "Re: Filter of TObjects"
- Reply: Bjørge Sæther: "Re: Filter of TObjects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|