RE: Add String in AddObject method and retrieving its va lue
Eduardo Duran Cardenas <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <51B9D9ACEE68B840A27F7C86903C9D15012E8810@TFM_MTY_DOM05> |
Yeah, I know, creating a new class and then pass the instance of that class
will work, but I don't want to.
An other way is to pass the Bookmark pointer of the query as an object and
that will work too.
But, the way I want it to do, is possible with an integer value, but don´t
with string, that is why I though it was possible.
Here is how...
with Query, ComboBox do begin
while not Eof do begin
AddObject(FieldByName('Description').asString,
TObject(FieldByName('Id').AsInteger));
Next;
end;
end;
when retrieving...
with combobox do
ShowMessage(InttoStr(Integer(Items.Objects[itemindex])))
> -----Mensaje original-----
> De: Fabiano Paolini [mailto:[email protected]]
> Enviado el: Jueves, 10 de Julio de 2003 03:51 a.m.
> Para: [email protected]
> Asunto: Re: [Delphi] Add String in AddObject method and retrieving its
> va lue
>
>
> 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/
>
>
------------------------ 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/