table fields in combo box

I have a (paradox) table and one of the fields is show name, how do I create a combo box that shows all the records under that field name?

i.e. field is ShowName, the combo box shows: Starlight Express  Evita, Grease, Cats etc.
SRPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SRPAuthor Commented:
Edited text of question.
0
SRPAuthor Commented:
Edited text of question.
0
kretzschmarCommented:
? what is your need for this
will you select,change one field of your currentrecord of your table with all available entries of this field based by the same table ?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

simonetCommented:
something like the code above works great for me:

with Table1, ComboBox1.items do
try
   beginupdate;
   disablecontrols;
   clear;
   first;
   while not eof do
   begin
     add(fieldbyname('showname').asstring);
     next;
   end;
finally
   enablecontrols;
   endupdate;
end;

This works for me, and I guess it's what you're looking for.

Yours,

Alex

yours,

Alex
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
men xinCEOCommented:
Easy.

menxin
0
kretzschmarCommented:
aah, checked, well done alex
0
she3i3iCommented:
Hi again Alex :)

   Your code would give you multiple entries in your combobox if you have the same entry for the field showname in two or more records.

   SRP, here is what I do...

var
   S: String
begin
   with Table1 do
         First;
         while not EOF do begin
                 S := FieldByName('ShowName').AsString;
                 if S <> ComboBox1.Items then ComboBox1.Items.Add(S);
                 Next;
         end;
end;

   That's off the top of my head cause my code is all at home...

Cheers, Chris.  
0
she3i3iCommented:
of course... clearing the comcobox before each time you are going to do this... is obvious... as you can see in Alex's code :)
0
kretzschmarCommented:
hi she3i3i,

i guess you mean this

if ComboBox1.Items.IndexOf(s) < 0 then ComboBox1.Items.Add(s);

instead of this
if S <> ComboBox1.Items then ComboBox1.Items.Add(s);

because you can't compare a string with a stringlist.

meikl ;-)
0
AlphomegaCommented:
Why don't use a TDBLookupComboBox with ListSource on your Table and listfield on ShowName ?????
It's easier ...
0
simonetCommented:
Chris,

I supposed SRP's table have no repeated entries for the "ShowName" column. If it does, then an yet better solution prevent having repeated records would be to use a Query. By doing so we wouldn't have to use IndexOf, which can really slow down the whole thing in there are too many records.

So, if *and only if* there are repeated records (for the ShowName field) in the table, then this is an even better solution:

with Query1, ComboBox1.items do
try
   beginupdate;
   disablecontrols;
   clear;
   if active then close;
   if prepared then unprepare;
   SQL.Text := 'SELECT DISTINCT SHOWNAME FROM ALBUMTABLE';
   prepare;
   open;
   first;
   while not eof do
   begin
     add(fieldbyname('showname').asstring);
     next;
   end;
finally
   close;  
   unprepare;
   enablecontrols;
   endupdate;
end;

Yours,

Alex
0
simonetCommented:
SRP, are you there?
0
SRPAuthor Commented:
Sorry for not responding to all the great answers i have been away.

simonet
this answer works well for what I need to do. I also want to do a similar thing with a combobox that shows all possible fields for a given table. is this possible in the same kind of way?

thanks to simonet

SRP
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.