Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TObjectList don´t retrieve properties

Status
Not open for further replies.

Pontelo

Programmer
Dec 18, 2001
80
BR
How can I retrieve values from my fields, descendants from TObjects

I have this definition of an object :
TRFComando = class(TOBject)
private
fID : Integer;
fINI : char;
fSTX : char;
fComando : String;
public
ID : Integer read fID write fID;
::: ans so on

Then I used
X := TRFComando.Create;
RFComando := TObjectList.Create(True);
RFComando.Add(X);

But when i try to retrieve values like this :
RFComando[0].ID
RFComando[0].Comando

Always comes Zero or empty Strings and chars.
Sounds like the properties i have created in my object was not stored in TObjectList but just the natural properties os the object itself.
What am I doing wrong ?
Thank You. Excuse bad English.

 
You need to tell Delphi what object type you are referencing. TObjectList is just a list of pointers.

Here is one way:
Code:
var
  oRFCommando:TRFCommando;
  nID:integer;
  sCommando:string;
begin
  oRFCommando := TRFCommando(RFCommando[0]);
  nID         := oRFComando.ID;
  sCommando   := oRFComando.Comando;
  :
  :
end;

Here is another:
Code:
var
  oRFCommando:TRFCommando;
  nID:integer;
  sCommando:string;
begin
  with TRFCommando(RFCommando[0]) do
    begin
      nID       := ID;
      sCommando := Commando;
    end;
  :
  :
end;

Or yet another way:
Code:
var
  nID:integer;
  sCommando:string;  
begin
  nID       := TRFCommando(RFCommando[0]).ID;
  sCommando := TRFCommando(RFCommando[0]).Commando;
  :
  :
end;
 
Thank You Zathras
I think i understand. This is hust novice blind.
In between i found on internet a way to derive my own object from TObjectList, rewriting few methods. Worked too.

TRFCmdList = class(TObjectList)
private
FOwnsObjects: Boolean;
protected
function GetItem(Index: Integer): TRFComando;
procedure SetItem(Index: Integer; AObject: TRFComando);
public
function Add(AObject: TRFComando): Integer;
function Remove(AObject: TRFComando): Integer;
function IndexOf(AObject: TRFComando): Integer;
procedure Insert(Index: Integer; AObject: TRFComando);
property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects;
property Items[Index: Integer]: TRFComando read GetItem write SetItem; default;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top