 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
sarah Guest
|
Posted: Mon Apr 23, 2007 9:05 pm Post subject: help! |
|
|
this is probably a very easy question but i'm stuck on creating a delphi program. i have to insert shop names, their location and what items they sell.
ive managed to write most of my program but one thing i have to do is let the program offer the chance for the user to display the names of all shops that sell a particular type of item in a given town.
i understand how i get the user to enter the location so the program displays the shops in that location but i then dont understand how i make it search for whatever item the user enters within the asked location.
i hope this all makes sense
please someone help me! x |
|
| Back to top |
|
 |
Thomas Maeder [TeamB] Guest
|
Posted: Tue Apr 24, 2007 2:18 am Post subject: Re: help! |
|
|
Hi Sarah
Just two side nodes (it's better for you if I let somebody more
competent respond to your actual question ):
1) Next time you start a thread, please give it a descriptive
subject. "help!" is just too general, and I know that there are people
who simply skip over posts with such subjects; among them may be the
person with the best answer for your question.
"sarah" <fit_chelsea1987 (AT) hotmail (DOT) com> writes:
| Quote: | this is probably a very easy question but i'm stuck on creating a
delphi program. i have to insert shop names, their location and what
items they sell.
ive managed to write most of my program but one thing i have to do
is let the program offer the chance for the user to display the
names of all shops that sell a particular type of item in a given
town.
i understand how i get the user to enter the location so the program
displays the shops in that location but i then dont understand how i
make it search for whatever item the user enters within the asked
location.
i hope this all makes sense
please someone help me! x
|
2) Please in your posts wrap lines at about 72 to 75 characters. Most
newsgroup client programs will assist you in doing this (or do it
automagically); if you don't use one of them, this may mean some
manual work; the benefit is that you post is easier to read, which
means that more people are likely to read it and possibly respond. |
|
| Back to top |
|
 |
chenzero Guest
|
Posted: Tue Apr 24, 2007 5:03 am Post subject: Re: help! |
|
|
I think your program based on some database, so, SQL is used.
If not, then things going to be complex because don't know
the internal structure your programing used.
by now, let's discuss if using SQL.
"sarah" <fit_chelsea1987 (AT) hotmail (DOT) com> 写入消息新闻:462cd93f$1 (AT) newsgroups (DOT) borland.com...
| Quote: | i understand how i get the user to enter the location so the program
displays the shops in that location
|
the SQL will like this:
select * from shop where location like '***'
| Quote: | but i then dont understand how i make it search for whatever item the user
enters within the asked location.
|
select items.*
from items, shop
where shop.id = items.shopid and
shop.location like '***'
(here, the items table has a foreign key named 'shopid'
to table shop)
hope it helps.
chenzero |
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Apr 24, 2007 4:59 pm Post subject: Re: help! |
|
|
"sarah" <fit_chelsea1987 (AT) hotmail (DOT) com> wrote:
Please wrap your lines when you post.
| Quote: | [...] i'm stuck on creating a delphi program.
|
You may be better off asking in the delphi.students group
instead of cppbuilder.students if you need source samples
but otherwise the logic remains the same.
| Quote: | [...] i understand how i get the user to enter the location
so the program displays the shops in that location but i
then dont understand how i make it search for whatever item
the user enters within the asked location.
|
That would depend entirely on how you've formatted your data
base (to be clear, even if you're only using flat files, it's
still a data base).
If you are free to design the data base as you desire, the
smallest learning curve would be to use TStringList(s) and
flat files. For example, all items in a particular shop are
kept in a seperate file and when you need information from
that shop, you would use TStringList::LoadFromFile to load the
file and then TStringList::IndexOf to locate a particular item.
I would suggest that you have one file (a master file) that
contains all of the stores particulars and a numeric (integer)
code for that store and that the data be formatted as such:
"Record1 Field1","Record1 Field2","Record1 Field3"
"Record2 Field1","Record2 Field2","Record2 Field3"
....
"Recordn Field1","Recordn Field2","Recordn Field3"
The quotes are included in the data file and can be created
using NotePad. Use LoadFromFile to load the master file and
then parse each record using TStringList's CommaText method.
For example:
// allocation of Master TStringList not shown
Master->LoadFromFile( "SomePathAndFileName" );
TStringList *TmpList = new TStringList()
for( int x = 0; x < Master->Count; ++x )
{
TmpList->CommaText = Master->Strings[ x ];
// TmpList->Strings[0] is the 1st field
// TmpList->Strings[1] is the 2nd field
// ...
// TmpList->Strings[n] is the nth + 1 field
}
delete TmpList;
This approach is also very useful when designing the UI. For
example, as you parse the Master record, you can build
individual TStringLists that can be logically connected using
the numeric StoreID and the TStringList's Objects property.
IOW, you can build a list of store names and use the Objects
property to point back into the Master list. For example:
// assumes that the first field is the store ID
// and that the second field is the store name
TStringList *TmpList = new TStringList()
for( int x = 0; x < Master->Count; ++x )
{
TmpList->CommaText = Master->Strings[ x ];
NameList->AddObject( TmpList->Strings[1], (TObject*)StrToInt(TmpList->Strings[0]) );
}
delete TmpList;
Now, any where in your GUI where the user needs to select an
existing store, simply Assign the the NameList to a TComboBox:
NameComboBox->Items->Assign( NameList );
When the user makes a selection, The NameComboBox->ItemIndex
can be used to index into the NameList where you'd use the
Objects[] property to index into the Master list. You could
also use TStringList->IndexOf( NameComboBox->Text ) as well to
get an index into the list.
The way to connect many different lists together is to use the
Objects property. Once you have the Objects[x], that can be
used with TStringList::IndexOfObject with any other TStringList
to get an index to that list's particular data which means that
you can use TStringList CustomSort on any or all of the lists
and they can be completely out of sync with each other and it
all works irrespective.
~ JD |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|