procedure TBaseObjList.FilterByDate(propName: string; startDate, endDate:
TDateTime);
var
i: Integer;
prop: TDateTime;
begin
for i:= Count-1 downto 0 do
begin
prop:= TDateTime(GetObjectProp(TBaseObj(Items[i]),propName));
if (prop < startDate) or (prop > endDate) then
Remove(TBaseObj(Items[i]));
end;
end;
procedure TBaseObjList.FilterByProperty(propName: string; propValue: string);
var
i: Integer;
begin
for i:= Count-1 downto 0 do
begin
if GetStrProp(TBaseObj(Items[i]),propName) <> propValue then
Remove(TBaseObj(Items[i]));
end;
end;
would work, but it doesn't. I get EPropertyError that property does not exist,
although it does and it is published (in second example), and incompatible types
(in first).
Please help me make it work.
Thanks in advance
nikola
> would work, but it doesn't. I get EPropertyError that property does not
> exist, although it does and it is published (in second example), and
> incompatible types (in first).
TDateTime is not an object, it's just typedef for a double.
Danny
---
GetObjectProp returns a TObject, not a TDateTime. TDateTime is a
floating-point type, so use GetFloatProp.
> if (prop < startDate) or (prop > endDate) then
> Remove(TBaseObj(Items[i]));
> end;
> end;
>
> procedure TBaseObjList.FilterByProperty(propName: string; propValue:
> string);
> var
> i: Integer;
> begin
> for i:= Count-1 downto 0 do
> begin
> if GetStrProp(TBaseObj(Items[i]),propName) <> propValue then
> Remove(TBaseObj(Items[i]));
> end;
> end;
>
> would work, but it doesn't. I get EPropertyError that property does not
> exist, although it does and it is published (in second example), and
> incompatible types (in first).
What is the ancestor of TBaseObj? A property isn't really published
unless the class was compiled in the $M+ state, or if one of its
ancestors was compiled in that state. If your class descends (directly
or indirectly) from TPersistent, then it has RTTI. Otherwise, it doesn't.
If your class doesn't descend from TPersistent, then your class
declaration needs to look like this:
type
{$M+}
TBaseObj = class
end;
{$M-}
That turns on RTTI for the class.
--
Rob
It was obvious for someone able to think :)
>
> What is the ancestor of TBaseObj? A property isn't really published
> unless the class was compiled in the $M+ state, or if one of its
> ancestors was compiled in that state. If your class descends (directly
> or indirectly) from TPersistent, then it has RTTI. Otherwise, it doesn't.
>
> If your class doesn't descend from TPersistent, then your class
> declaration needs to look like this:
>
> type
> {$M+}
> TBaseObj = class
> end;
> {$M-}
>
> That turns on RTTI for the class.
>
TBaseObj = class(TObject)
so this M directive did the trick.
Thanks.
Working for about 20 hours straight, I seem to cannot think clearly anymore.
Thanks, that was so obvious. <blush>