Board index » delphi » Adding Listbox Items

Adding Listbox Items

I am quite new to Delphi and am running version 1.0, forgive me if my
questions sounds stupid.

1.      I am trying to load a field from a Paradox table to a listbox. I
seem to be able to read the fields into vars of type text or String, How do I
convert one of these types to Tstrings,  Which seems to be what is required
to load data to a listbox?

2.      My application will be receiving data from a flatfile created by a
c program (null terminated strings), what sort of problems will I have in
reading this file and what work arounds should I use?

Thanks in advance, Terry.

 

Re:Adding Listbox Items


Quote
Terry Haimann wrote:

> I am quite new to Delphi and am running version 1.0, forgive me if my
> questions sounds stupid.

> 1.      I am trying to load a field from a Paradox table to a listbox. I
> seem to be able to read the fields into vars of type text or String, How do I
> convert one of these types to Tstrings,  Which seems to be what is required
> to load data to a listbox?

The Strings property found in many components is of type String.
Here is an example of filling a listbox at runtime with record values
from a Paradox table:

procedure TMainForm.PopulateCategoryListBox;
var I : Integer;
begin
     CategoryTable.First;
     for I := 0 to CategoryTable.RecordCount -1 do
      begin // LBCategory is the TListbox

LBCategory.Items.Add(CategoryTable.FieldByName('Category_Name').AsString);
       CategoryTable.Next;
      end;
end;

Quote
> 2.      My application will be receiving data from a flatfile created by a
> c program (null terminated strings), what sort of problems will I have in
> reading this file and what work arounds should I use?

> Thanks in advance, Terry.

In the Delphi help search fro String Handling rountines,.. There you
will find information on converting string types..

Hope that helps!

Rkr
--
                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Delphi Programmer / Analyst             .
. TVisualBasic:=class(None);              .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) pacbell (dot) net .
. or reidr (at) autobytel (dot) com       .
-------------------------------------------

Re:Adding Listbox Items


Quote
Terry Haimann wrote:

> I am quite new to Delphi and am running version 1.0, forgive me if my
> questions sounds stupid.

> 1.      I am trying to load a field from a Paradox table to a listbox. I
> seem to be able to read the fields into vars of type text or String, How do I
> convert one of these types to Tstrings,  Which seems to be what is required
> to load data to a listbox?

The Strings property found in many components is of type String.
Here is an example of filling a listbox at runtime with record values
from a Paradox table:

procedure TMainForm.PopulateCategoryListBox;
var I : Integer;
begin
     CategoryTable.First;
     for I := 0 to CategoryTable.RecordCount -1 do
      begin // LBCategory is the TListbox

LBCategory.Items.Add(CategoryTable.FieldByName('Category_Name').AsString);
       CategoryTable.Next;
      end;
end;

Quote
> 2.      My application will be receiving data from a flatfile created by a
> c program (null terminated strings), what sort of problems will I have in
> reading this file and what work arounds should I use?

> Thanks in advance, Terry.

In the Delphi help search for String Handling rountines,.. There you
will find information on converting string types..

Hope that helps!

Rkr
--
                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Delphi Programmer / Analyst             .
. TVisualBasic:=class(None);              .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) pacbell (dot) net .
. or reidr (at) autobytel (dot) com       .
-------------------------------------------

Re:Adding Listbox Items


In article <fqszyioalgxmka.pmin...@pa1dsp11.dsm.infi.net>, "Terry Haimann"

Quote
<haim...@dmreg.infi.net> writes:
>1.  I am trying to load a field from a Paradox table to a listbox. I
>seem to be able to read the fields into vars of type text or String, How do I
>convert one of these types to Tstrings,  Which seems to be what is required
>to load data to a listbox?

LTListBox uses a TStrings to hold its strings but you do not / should not write
directly to th TStrings. The TStrings appear in a TListBox as its Items
property. The TStrings has an Add method so having got your text into a string,
you code :-

MyListBox.Items.Add(MyString).

Other useful methods are :-
 Insert(AtPosition, MyString)  - puts the string at the position noted (first
is 0) and pushes the others down.
Delete(DelPosition) - deletes a string at that position - other move up.
IndexOf(MyString) - returns the position of the matching string.

All these are methods of a TStrings.

Hope this helps

Alan Lloyd
alangll...@aol.com

Other Threads