Re: Add String in AddObject method and retrieving its va lue

"Fabiano Paolini" <[email protected]>
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <00bb01c346c0$7374de90$2716a8c0@PAOLINI>
Your code is quite dangerous (using type casting between incopatible types
as strings and Objects or similar).
IMHO is better to define a new Class (TObject compatible that contains your
data (string in your example).

Fabiano

----- Original Message -----
From: "ebis007de" <[email protected]>
To: <[email protected]>
Sent: Thursday, July 10, 2003 10:32 AM
Subject: Re: [Delphi] Add String in AddObject method and retrieving its va
lue




> > I though something like this but must have something wrong..
> > hope someone can help
> >
> > list : Tstrings
> > q :query
> >
> > I've tried some ways... but doesn´t work.
> >
> > while not q.eof do begin
> > List.addObject(q.fieldbyname('FullName').asstring,
> >
> > TObject(q.fieldbyname('ShortName').asstring))   //
> > also put the string word after TObject and looks like
> > TObject(String(q.Fieldby....
> > q.next;
> > end;
> >
> > ComboBoxOnChange(Sender:Tobject);
> > begin
> >   with TComboBox(Sender) do
> >   Showmessage(string(items.object[itemindex]))
> > end;
> >

You can't do that in this way because the string-handling is a bit
special in Delphi. See more in the Delphi help

What you can do (short example out of my head)


Type TPerson = Class
     public
       Constructor Create (_Short: String);
       ShortName : String;
     end;

Constructor Create (_Short: String);
begin
  Shortname := _Short;
end;


while not q.eof do begin
  List.addObject(q.fieldbyname('FullName').asstring,
     TObject(TPerson.Create (q.fieldbyname
                                ('ShortName').asstring));
  q.next;
end;



ComboBoxOnChange(Sender:Tobject);
begin
  ShowMessage (TPerson (TComboBox(Sender)items.objects
                                    [itemindex])).ShortName)
 end;

Bests Ebi



Delphi Tips & Tutorials...
http://www.delphicollection.com
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/




------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/sOykFB/k9VGAA/ySSFAA/i7folB/TM
---------------------------------------------------------------------~->

Delphi Tips & Tutorials...
http://www.delphicollection.com
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.