TwwDBCheckBox(Info Power) Creation and Link to wwRecordViewDialog

VENKAT
VENKAT used Ask the Experts™
on
I have three logical fields from one table and table is linked to the TwwDBGrid & TwwRecordViewDialog. So when I Insert/Edit then I will open the RVD to keyin the data.
      Now the problem is Infopower dont have any TwwDBcheckbox, so I am not able place any component on the form so using below code to assign check box to Grid&RVD.
----------------------------------------------------------
     for nI := 0 to Table.FieldCount-1 do
          if Table.FieldDefs.Items[nI].DataType = ftBoolean then
               wwDBGrid1.SetControlType(Table.Fields[nI].FieldName, fctCheckBox, 'True;False');
---------------------------------------------------------

But I am not able to control the check box like,
If I click 1st check box want to make 2nd check box forex:

-------------------------
if (Check1 = true) then begin
Check2.ReadOnly          := True;
Check2.Color           := clBtnFace;
Check2.Enabled       := False;
end
------------------
and click other then want to do reverse..so the main problem is i am not able to track the name of the checkbox coz its created automatically.

 Anybody can help me how can do this three checkbox actions, click one make other checkbox readonly&color change&disable. Please show me how to do it in TwwRVD.
Thank you.
------------------------------

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CSJ

Commented:
Try something on the lines of:

private
  recForm : TwwRecordViewForm;
  procedure CheckBoxChange(Sender: TField);

// In the TwwRVD.GetInitDialog event:
// Create pointer to the dynamic form that is created

procedure TForm.rvdGetInitDialog(Form: TwwRecordViewForm);
begin
  recForm := Form;
end;

// In the TwwRVD.OnAfterCreateControl event:

procedure TForm.rvdAfterCreateControl(
  Form: TwwRecordViewForm; curField: TField; Control: TControl);
begin
  if curField.DataType = ftBoolean then
    curField.OnChange := CheckBoxChange;
end;

procedure TForm.CheckBoxChange(Sender: TField);
var i : Integer;
begin
  for i := 0 to recForm.scrollbox.componentcount -1 do
   if recForm.scrollbox.components[i] is tdbcheckbox then
     if tdbcheckbox(tmpform.scrollbox.components
          [i]).datafield <> Tfield(sender).fieldname then
       tdbcheckbox(tmpform.scrollbox.components
                   [i]).color := clblue
     else
       tdbcheckbox(tmpform.scrollbox.components
                   [i]).color := clbtnface;
end;

Hope this helps

Floyd

Author

Commented:
Hi CSJ
        I did not understand few of your lines. please brief the below which you mentioned above.

// In the TwwRVD.GetInitDialog event:
// Create pointer to the dynamic form that is created

& what is that 'tmpform' & 'recform'.
Thank you.

Author

Commented:
Also I have 'wwRVD1InitDialog' event for my RVD and dont have which you mentioned event 'rvdGetInitDialog'. Thank you.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

CSJ

Commented:
Apologies VENKAT,

The tmpForm should read recForm, so replace these occurences.

The GetInitDialog event should be OnInitDialog event of the RVD component.  In here, the TwwRecordViewForm is passed as a parameter, so put the line

recForm := Form;

in there.

Sorry for not naming the events more logically for you.

Author

Commented:
Helping is great thing here, no need to say sorry sir. Still I did not understand. Sorry sir, How to read tmpform from recform and where to replace. can you please paste full lines of code for me again with all changes. Sorry for distrubing you again. Thank you.
Commented:
There are many ways to do this - here is a slight
alternative that you may understand a little better:

TForm1 = class(TForm)
    procedure rvdInitDialog(Form: TwwRecordViewForm);
    procedure rvdAfterCreateControl(Form: wRecordViewForm;
               curField: TField; Control: TControl);
  private
    recForm : TwwRecordViewForm;
    procedure CheckBoxChange(Sender: TField);

// rvd OnInitDialog Event
procedure TForm1.rvdInitDialog(Form: TwwRecordViewForm);
begin
 recForm := Form; // recForm defined in private section
end;

// rvd AfterCreateControl Event
procedure TForm1.rvdAfterCreateControl(
 Form: TwwRecordViewForm; curField: TField; Control: TControl);
begin
 if curField.DataType = ftBoolean then
   curField.OnChange := CheckBoxChange;
 // CheckBoxChange defined in private section
end;

procedure TForm1.CheckBoxChange(Sender: TField);
var
  i : Integer;
  tmpControl : array [1..2] of Tdbcheckbox;
begin
  j := 1;
  for i := 0 to recForm.scrollbox.componentcount -1 do
    if recForm.scrollbox.components[i] is tdbcheckbox then
    begin
      tmpControl[j] := Tdbcheckbox
                        (recForm.scrollbox.components[i]);
      Inc(j);
    end;
  //
  if Tfield(sender).fieldname =
     tmpControl[1].DataField then
    if tmpControl[1].Checked then begin
      tmpControl[2].Checked := False;
      tmpControl[2].Color   := clBlue;
      tmpControl[1].Color   := clBtnFace;
    end
    else begin
      tmpControl[2].Checked := True;
      tmpControl[1].Color   := clBlue;
      tmpControl[2].Color   := clBtnFace;
    end;

  if Tfield(sender).fieldname =
     tmpControl[2].DataField then
    if tmpControl[2].Checked then begin
      tmpControl[1].Checked := False;
      tmpControl[1].Color   := clBlue;
      tmpControl[2].Color   := clBtnFace;
    end
    else begin
      tmpControl[1].Checked := True;
      tmpControl[2].Color   := clBlue;
      tmpControl[1].Color   := clBtnFace;
    end;
end;

Note - this is assuming you have two tdbcheckbox fields setup.  When first is checked, the other will become unchecked, and coloured blue and vice versa.

Hope this helps

Floyd

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial