Home > Archive > Delphi > September 2004 > Cannot assign T... to T...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Cannot assign T... to T...
|
|
| Henning 2004-09-09, 4:00 pm |
| Hi out there,
Iīm getting crazy on a problem, hopefully someone can help me: I have
a decendant of TCollectionITem (TRessource) and a decendant of
TCollection (TRessources). I need a function which returns just some
items of the collection, depending on some field value of my
collectionitem. So I create my result and try to assign the values to
it, but I get "Cannot assign TRessource to TRessource". I know that I
need to override and implement my own assign method. But for this I
need to instantiate a new instance of TRessource. That is exactly what
I donīt want to do, I just want a list of references of the items that
match.
Maybe someone can help me? I appreciate any help on this, it already
took me too much time.
Thanks in advance!
Henning
TRessource = class(TCollectionItem)
private
FName: String;
FFirstname: String;
public
property Name: string read FName write FName;
property Firstname: string read FFirstname write FFirstname;
end;
TRessources = class(TCollection)
private
function GetItems(Index: Integer): TRessource;
procedure SetItems(Index: Integer; const value: TRessource);
public
constructor Create;
property Items[Index: Integer]: TRessource read GetItems write
SetItems; default;
//procedure Load; override;
end;
......
function TScheduleItems.Ressources: TRessources;
var i: integer;
begin
result := TRessources.Create;
for i := 0 to Count - 1 do
begin
// some <if> stuff here...
if result.ItemByIDX(Schedule.ScheduleItems[i].Ressource.IDX) = nil
then
begin
result.Add;
result[result.Count - 1] :=
TRessource(Schedule.Ressources.ItemByIDX(Schedule.Ressources[i].IDX));
end;
end;
end;
| |
|
| if you have the pro or better version of D then look at the
properties and source of how the TStringList is done..
most objects that use the Tstringlist name it as items
the set up the property as you have. with this you still
have methods that let you add, assign etc..
you can modify your assign to act as you want! have if
point to some external object of have it simply make a
duplication of it.
from what i can see i really think what you want it to
do is point to an external object and simply manipulate it.
Henning wrote:
> Hi out there,
> Iīm getting crazy on a problem, hopefully someone can help me: I have
> a decendant of TCollectionITem (TRessource) and a decendant of
> TCollection (TRessources). I need a function which returns just some
> items of the collection, depending on some field value of my
> collectionitem. So I create my result and try to assign the values to
> it, but I get "Cannot assign TRessource to TRessource". I know that I
> need to override and implement my own assign method. But for this I
> need to instantiate a new instance of TRessource. That is exactly what
> I donīt want to do, I just want a list of references of the items that
> match.
> Maybe someone can help me? I appreciate any help on this, it already
> took me too much time.
> Thanks in advance!
> Henning
>
>
>
> TRessource = class(TCollectionItem)
> private
> FName: String;
> FFirstname: String;
> public
> property Name: string read FName write FName;
> property Firstname: string read FFirstname write FFirstname;
> end;
>
> TRessources = class(TCollection)
> private
> function GetItems(Index: Integer): TRessource;
> procedure SetItems(Index: Integer; const value: TRessource);
> public
> constructor Create;
> property Items[Index: Integer]: TRessource read GetItems write
> SetItems; default;
> //procedure Load; override;
> end;
>
> .....
>
> function TScheduleItems.Ressources: TRessources;
> var i: integer;
> begin
>
> result := TRessources.Create;
>
> for i := 0 to Count - 1 do
> begin
> // some <if> stuff here...
> if result.ItemByIDX(Schedule.ScheduleItems[i].Ressource.IDX) = nil
> then
> begin
> result.Add;
> result[result.Count - 1] :=
> TRessource(Schedule.Ressources.ItemByIDX(Schedule.Ressources[i].IDX));
> end;
> end;
> end;
|
|
|
|
|