Board index » delphi » Missing object info within TStringList...

Missing object info within TStringList...

OK...I feel like an idiot, but would someone please explain what I'm
doing wrong here.  I need to store objects in a TStringList.  I found
that if the object is of type TObject, I would lose access to the
object's information as soon as the function lost focus.  Therefore, by
recommendation of another Delphite, I descend from TComponent so the
form takes care of destroying the objects.  Maybe somewhere along these
lines I'm going wrong.  Here's the code...

type
  PhoneTypeInfo = class(TComponent)
  Code: String[2];
  Description: String[10];
end;

  PhoneTypes := TStringList.Create;
  PhoneTypestable := PhoneBookDB.OpenRecordset( 'PhoneTypes' );
  PhoneTypestable.Index := 'PrimaryKey';
  PhoneTypeCount := PhoneTypestable.RecordCount;
  PhoneTypestable.MoveFirst;

  for i := 1 to PhoneTypeCount do
  begin
    PhoneTypeRec := PhoneTypeInfo.Create(self);
    PhoneTypeRec.Code := PhoneTypestable.Fields['Code'].Value;
    PhoneTypeRec.Description :=  
        PhoneTypestable.Fields['Description'].Value;
//OK right here!
    PhoneTypes.AddObject( PhoneTypeRec.Code, PhoneTypeRec );
//Info GONE!
    PhoneTypestable.MoveNext;
  end;

Right after I AddObject, I can no longer see PhoneTypeRec.Description OR
the value of Description from within the stringlist.  What gives???

Thanks for any help in advance,

Bruce Goldstein
Software Engineer
Interactive Strategies, Inc.
br...@centcon.com

 

Re:Missing object info within TStringList...


Quote
>Right after I AddObject, I can no longer see PhoneTypeRec.Description OR
>the value of Description from within the stringlist.  What gives???

        When referencing Object you need to typecast it back to the type that it is to
see it's specific properties.

_
******************************************************************
NOTE: This software is currently in early alpha. If you notice any
problems, or RFC non-compliance, please report it to p...@pbe.com
 \------------------------------------------------------------\
  \           Chad Z. Hower  -  phoe...@pobox.com              \
   \  Phoenix Business Enterprises - p...@pbe.com - www.pbe.com  \
    \     Physically in Church Hill, TN - Logically Not Sure     \
     \------------------------------------------------------------\

Quote
>>SQUID - The ultimate 95/NT offline databasing reader

**Special Compile: 3.000A (Alpha)

Other Threads