Welcome! Log In Create A New Profile

Advanced

DBLookup Combo Box

Posted by Simone 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
DBLookup Combo Box
September 02, 2006 06:35PM
Hi, I'm working through chapter 16 example 16.2 where it asks you to add a DBLookupComboBox. For some reason when I try run the programme the box doesn't work...it remains greyed out.
Can anyone help?

I've followed the book exactly and I just cant work it out!
Re: DBLookup Combo Box
September 07, 2006 11:55AM
I had a similar problem. I am using Delphi 7. Here is how I set my values up:

DBLookupComboBox:

My list source value is dmoLibrary.datBook (TDataSource) and my data set value is cdsBook (TClientDataSet). My data set is active (in other words the value is true) and so is the list source. My provider name in the data set is dspBook (TDataSetProvider). My list field for the DBLookupComboBox component is pointing to the value AcquisitionNumber (from the database) and my key field is also pointing to the value AcquisitionNumber (from the database, this should appear if the database is connected properly). My data source for the DBLookupComboBox component is left blank.

TSQLConnection:

Take a look at your TSQLConnection and click the params tab and on the elipsis button on the Tstrings. Make sure you are pointing to the database and the table that you have defined in the database. You can test the SQL connection once you have set it up and if it is successful then it should be fine. I have set the connected value of the SQL connection to true. In your data module file, right click on the SQL Connection component and select the Edit Connection Properties option. At the top there should be a tick button, click this and it will test your connection to the database that you defined (a pop-up window will appear and it will say that it was a successfully connected).

TSQLDataSet:

If thats all good then check your sdsBook (TSQLDataSet). Check that your command text's value is pointing to the right table in the database and that the command type is ctTable.

The acquisition table file:

If there is still a problem then make sure that your Delphi unit file that contains the DBLookUpComboBox has the following line 'uses dmoLibraryu' in the code under inplementation.

The main menu file:

Then also check that your main page, the one with the TMainMenu on it also has everything included that it needs, mine is as follows: 'uses Memberu, Booku, dmoLibraryu, AcquireBooku, IssueBooku, ReturnBooku;'.

On your database make sure you are running your database. I am running MySQL and all I do is set up my database and tables and then right click on the database and connect it.

I hope that this helps you out.

Cheers
Re: DBLookup Combo Box
September 08, 2006 12:25AM
Thanks for all your help dougie, I will give it a shot this weekend!

Mel
Re: DBLookup Combo Box
September 08, 2006 08:33AM
Dougie,

I also am having problems with Chapter 16 - can you (or anyone else) help?

I am having a problem with the LibraryLoan form and table. I have typed all the event handlers exactly as is written in the text book. However, when I click on bmbIssueBook I get an error stating that there is no active index and the table will not update.

If anyone has any idea, I'd really appreciate it!

Melanie
meldevilliers@gmail.com
Re: DBLookup Combo Box
September 09, 2006 11:37AM
Dougie,

Thank you, you are a star!! it works!
Simone
Re: DBLookup Combo Box
September 10, 2006 07:02PM
Hey Mel

This is how I set my values up for the Issue book form:

DBLookupComboBox (dlcAcqNumber):

My list source is dmoLibrary.datAcquisition (TDataSource) and my data source is left blank. My key field and list field are both pointing at the value AcquisitionNumber (from the database).

Database:

Make sure that you have the database connected with the libraryacquisition, librarybook, libraryloan, and librarymember table's in the database. Fill in some values within your database's tables (in other words not using Delphi, but directly using your database administration program - I use MySQL Control center)

Also make sure you follow the right procedure for setting up your module file. (Thats the file with all your database components).

TSQLConnection (scoMyVPLibrary):

Take a look at your TSQLConnection and click the params tab and on the elipsis button on the Tstrings. Make sure you are pointing to the database and the table that you have defined in the database. You can test the SQL connection once you have set it up and if it is successful then it should be fine. I have set the connected value of the SQL connection to true. In your data module file, right click on the SQL Connection component and select the Edit Connection Properties option. At the top there should be a tick button, click this and it will test your connection to the database that you defined (a pop-up window will appear and it will say that it was a successfully connected).

TSQLDataSet (sdsAcquisition):

If thats cool then check your sdsAcquisition (TSQLDataSet). The data source is datAcquisition. Then check that your command text's value is pointing to the right table in the database (In this case the libraryacquisition table) and that the command type is ctTable.

TDataSetProvider (dspAcquisition):

Check that your database provider is pointing to the dataset sdsAcquisition (TSQLDataSet).

TClientDataSet (cdsAcquisition):

Check that your provider name is dspAcquisition.

TDataSource (datAcquisition):

Check that your data set value is cdsAcquisition.

On your design window (the window with all your components on it in graphical view) click on dlcAcqNumber (DBLookup ComboBox), and then in the object inspector click the events tab, then double click the space next to OnCloseUp and make sure you have the following code:

if (dlcSurname.Text <> ''winking smiley and (dlcAcqNumber.Text <> ''winking smiley then
bmbIssueBook.Enabled := True;

Then the other lookup Combo box (the surname) is as follows:

DBLookupComboBox (dlcSurname):

My list source is dmoLibrary.datMember (TDataSource). My list field is MemberSurname, and my key field is MemberNumber.

Then go to your module file again and make sure that you have set up the right values for the database components for member. The SQL connection component remains the same and is used by all the other components.

TSQLDataSet (sdsMember):

Once again check your sdsMember (TSQLDataSet). Check that your command text's value is pointing to the right table in the database (In this case the libraryMember table) and that the command type is ctTable.

TDataSetProvider (dspMember):

Check that your database provider is pointing to the dataset sdsMember (TSQLDataSet).

TClientDataSet (cdsMember):

Check that your provider name is dspMember.

TDataSource (datMember):

Check that your data set value is cdsMember.

On your design window (the window with all your components on it in graphical view) click on dlcSurname (DBLookup ComboBox), and then in the object inspector click the events tab, then double click the space next to the OnCloseUp event handler and make sure that you have the following code:

if (dlcSurname.Text <> ''winking smiley and (dlcAcqNumber.Text <> ''winking smiley then
bmbIssueBook.Enabled := True;

This is the code for the onCloseUp event handler that relates to the Issue book button and it will only work in runtime if I choose a acquisition number and a surname as well (Then it shouldn't be greyed out).

Then in the design window double click anywhere in free space on the form (this will bring up the frmIssueBook (Form) - then go to the events tab again and this time double click the space after the OnClose event handler) this is part that applies the values to the database and make sure it looks like this:

procedure TfrmIssueBook.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if (dmoLibrary.cdsLoan.ChangeCount > 0) then
dmoLibrary.cdsLoan.ApplyUpdates(0); // Max errors parameter: 0
dmoLibrary.cdsAcquisition.Close;
dmoLibrary.cdsMember.Close;
dmoLibrary.cdsBook.Close;
end;

Then in the design window, click on the my Issue Book button and back in the object inspector click the events tab and double click on the onClick event handler and make sure your code is similar to this:

procedure TfrmIssueBook.bmbIssueBookClick(Sender: TObject);
var MemberID, Acquisition: string;
DueDate: TDateTime;
begin
MemberID := dmoLibrary.cdsMember.FieldByName('MemberNumber'winking smiley.AsString;
Acquisition := dmoLibrary.cdsAcquisition.FieldByName('AcquisitionNumber'winking smiley.AsString;

// Is book available?
if dmoLibrary.cdsLoan.FindKey([Acquisition]) then
// Record exists, so book already out
ShowMessage('Book not available'winking smiley
else // Record not in LibraryLoan table, so book is available
begin
// Add new empty Loan record
dmoLibrary.cdsLoan.Insert;
// Put the values in the fields
DueDate := Date + 14; // 14 days after today
dmoLibrary.cdsLoan.FieldByName('LoanAcquisitionNumber'winking smiley.AsString := Acquisition;
dmoLibrary.cdsLoan.FieldByName('LoanMemberID'winking smiley.AsString := MemberID;
dmoLibrary.cdsLoan.FieldByName('LoanDueDate'winking smiley.AsDateTime := DueDate;

// Save the new record
dmoLibrary.cdsLoan.Post;
ShowMessage('Book Issued'winking smiley;
bmbIssueBook.Enabled := false;
end;

end;

The issue book table file:

At the top of my issue book file in the code section under implementation I have in my uses clause: 'uses dmoLibraryu'. This will make sure that your issue book file includes the module file.

The main menu file:

Then also check that your main page, the one with the TMainMenu on it also has everything included that it needs, mine is as follows: 'uses Memberu, Booku, dmoLibraryu, AcquireBooku, IssueBooku, ReturnBooku;'.

Then for dbgLoan (the DBGrid), my data source is 'dmoLibrary.datLoan'.

(The SQL connection component remains the same and is used by all the other components.)

TSQLDataSet (sdsLoan):

Once again check your sdsLoan (TSQLDataSet). Check that your command text's value is pointing to the right table in the database (In this case the libraryloan table) and that the command type is ctTable.

TDataSetProvider (dspLoan):

Check that your database provider is pointing to the dataset sdsLoan (TSQLDataSet).

TClientDataSet (cdsLoan):

Check that your provider name is dspLoan.

TDataSource (datLoan):

Check that your data set value is cdsLoan.

Thats everything I can think of, only more thing, make sure your database is connected properly. Does your database work for any other examples using Delphi or is the first example for you and are you stuck there? Then make sure you have set up your database, and test it in Delphi with the above SQL connection, because if it connects successfully using the SQL connection, then everything else should work. If it is not successful then go through setting up your database again.

I hope all this can help you out, I also struggled with these examples and getting it all working properly, it took me a while.

Cheers
Re: DBLookup Combo Box
September 10, 2006 07:08PM
Hey Simone

I'm happy that you got it working.

Cheers
Re: DBLookup Combo Box
September 12, 2006 08:51AM
Hello All!!!

Guys pls help, does any1 know where exactly can I find da Delphi previous papers in sol???

Re: DBLookup Combo Box
September 12, 2006 09:30AM
you can get it from @#$%& (under myDiscussionForums) on this site.
Re: DBLookup Combo Box
September 12, 2006 09:31AM
you can get it from @#$%& (under myDiscussionForums) on this site.
Re: DBLookup Combo Box
September 12, 2006 09:46AM
But where???
Re: DBLookup Combo Box
September 12, 2006 10:09AM
Thanx guys finally got it!!...I really do appreciate...
Re: DBLookup Combo Box
September 12, 2006 10:27AM
Aish, Sorry Guys 1 more thing I don't hav da username & password 2 download those file pls help!!!
Mel
Re: DBLookup Combo Box
September 12, 2006 01:11PM
The username is @#$%& and the password is @#$%&. All in caps.
Mel
Re: DBLookup Combo Box
September 12, 2006 01:11PM
Ok that didn't work....
Re: DBLookup Combo Box
September 13, 2006 08:31AM
as taken from the osprey help page....

"This login and password is provided in the COSALL tutorial letter that you receive via snail-mail when you register as a student at Unisa.

If you have NOT received the COSALL yet (or lost it, you dog ate it, it was stolen together with your car and are keen to access the material on Osprey , login to myUNISA. The login and password should be available on the welcome page."
Re: DBLookup Combo Box
September 13, 2006 11:53AM
Yeah, Thanx a mill evrything is sorted now!!!
Sorry, only registered users may post in this forum.

Click here to login