Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create DBCheckBox at RunTime?

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Hello all you helpful tekkies! I'm back with more questions!

I have 3 tables in my database: JuryMain, SpecialCodes, and JurorSpecial. JuryMain has a primary key of JurNum; SpecialCodes has a SPCode and SPDesc; JurorSpecial tracks which jurors have which special codes (JurNum, SPCode). I have a form with TabSheets one of which is Special Items. I'd like to run a query when the form is created to add DBcheckbox items for each of the SpecialCodes DESCRIPTIONS (Hearing Impaired, First Week Only) and when the juror information special tab is selected check the boxes from the JurorSpecial table. So if I select Joe Blow, the information form opens. When I select the Special Tab, check any boxes in which the special codes for Joe Blow from the JurorSpecial Table match the SpecialCode SPCODE. And reversely update the JurySpecial Table when any boxes are newly checked. I'm not even sure this is possible, is there some other way to accomplish it if it's not?

I found some code here for creating a button on the form at runtime and i'm going to try and modify that, but I'm not clear on how and where I'm suppose to call my CreateCheckBox function from!

Thanks for any help!

Leslie Leslie
landrews@metrocourt.state.nm.us
 
hi,

Put a button on the form and put this code in the onclick event, put the file BDctrls in the uses clause.

procedure TForm1.Button1Click(Sender: TObject);
var
MyBox: TDBCheckBox;
begin
MyBox := TDBCheckBox.Create(Self);
MyBox.Parent := Form1;
myBox.Top := 10;
MyBox.Left := 10;
end;

run and press the button.

Steph [Bigglasses]
 
But I don't want the user to have to press a button. I'd like the form to create the blank DBcheckboxes when it initializes and when the record is selected fill in the checks where appropriate (SELECT * FROM JURORSPECIAL WHERE JURNUM = (JurNum from JuryMain) and when a box is checked update the JurorSpecial Database with the JurNum and the correct SPCode (UPDATE JURORSPECIAL SET JURNUM = (JURNUM FROM JURYMAIN), SPCODE = (SPCODE FROM SELECTED BOXES)).

Thanks for the suggestion!



Leslie
landrews@metrocourt.state.nm.us
 
hi,

use your imagination. Put it in the onCreate of the form.

Steph [Bigglasses]
 
I have got most of this to work, but I'm having problems setting the DataField of my DBcheckbox. This gets all the special codes and descriptions, creates the check boxes, but I can't get it to set the datafield! What am I doing wrong?

while not JMSData.qrySpecialDesc.eof do
begin
MyBox := TDBCheckBox.Create(Self);
MyBox.Parent := frmJurorInfo.Special;
MyBox.Top := i;
MyBox.Left := 10;
MyBox.Caption := JMSData.qrySpecialDesc.FieldByName('SPDESC').AsString;
MyBox.Font.Size := 12;
MyBox.Width := 240;
MyBox.Height := 35;
MyBox.Enabled := True;
MyBox.DataSource := JMSData.dsJurorSpecial;
MyBox.DataField := ????;
JMSData.qrySpecialDesc.next;
i := i + 30;
end; Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Ok, I've decided to get regular DBcheckboxes working before delving into on the fly. So I've created the checkboxes on my form. But even though there is no data in the table, all the boxes are checked but gray (even though allowgrayed is false). And when I do actually check one, the database doesn't update even though I have a Post in the OK button. Any clues as to what I'm doing wrong?

thanks!

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top