Topic: Conditional Enable/Disable via button action

Could somebody tell me why the script below is not working please?


procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
  Form2.CheckBox1.Checked := True;
end;

I'm trying to get checkbox on form2 checked, when button1 on form1 clicked. I need to have the button and checkbox on different forms.

Adam
God... please help me become the person my dog thinks I am.

2 (edited by ehwagner 2017-06-12 20:26:08)

Re: Conditional Enable/Disable via button action

You need to place that statement inside the Form2 OnShow event. And it should be inside an If statement for the button clicked on Form1. Something like this


procedure Form2_OnShow (Sender: string; Action: string);
begin
   If Form1Button = 'Some value' then Form2.CheckBox1.Checked := True;
end;

Re: Conditional Enable/Disable via button action

Thanks a lot EHW..........................


I got it working partially thanks to your kind help.
When added new records, editing etc it seems to be loosing its checkbox logic, more likely I couldn't work out the logic properly or implemented incorrectly. It may look strange on sample project as to why I'm using checkboxes as radio buttons instead of combobox. I need to do something with checkboxes (radiobuttons) as it suits the part of the project better.


There is another issue on doubleclick. If the record selected with mouse click on tGrid (active focus) it seems to be working OK most of the time. However, when double clicked while there is a passive focus on tGrid record (when leaving the form and coming back to it after save etc)  then it looses it's logic to show correct checkbox checked. I added set focus on show to avoid passive focus but didn't help much.

https://s29.postimg.org/ihwhlegnr/zzzzz_Temp39.png


Please see the attached sample project:

Post's attachments

Attachment icon Conditional Endable Disable onBtnAction.zip 8.11 kb, 378 downloads since 2017-06-13 

Adam
God... please help me become the person my dog thinks I am.

Re: Conditional Enable/Disable via button action

When added new records, editing etc it seems to be loosing its checkbox logic


One thing that I saw that could be problematic with the checkbox logic is that the "Begin" and "End" statements are missing inside the "IF" statements for each of the checkbox Onclick events. Multiple statements should be inside "Begin" and "End" statements for an "If".

Re: Conditional Enable/Disable via button action

Thanks a lot EHW.....


One thing that I saw that could be problematic with the checkbox logic is that the "Begin" and "End" statements are missing inside the "IF" statements for each of the checkbox Onclick events. Multiple statements should be inside "Begin" and "End" statements for an "If".


Tried it but issue still remains. I think there is a problem with my implementation of second edit  (Add particulars to selected) button.

Adam
God... please help me become the person my dog thinks I am.

Re: Conditional Enable/Disable via button action

Adam, After putting in the Begin and End statements, the checkbox logic seems to be working on my end. As far as the doubleclick edit on the passive focus, I could not duplicate your problem. If these are still issues, maybe you can walk through the steps you take to show the problem. Regarding the "Add Particulars", it looks like you are trying to set all the checkboxes to "True" during the Form2 OnShow event. However, when you try to force the setting of the checkbox, MVD will trigger the checkbox OnClick event. So in your case, MVD will execute each of the checkbox events and ultimately result in only the last one being checked.

Re: Conditional Enable/Disable via button action

Hi EHW,


Thanks to your kind help, I think it works OK now. Hopefully it won't break.


I put on Add Particular button showRecord action and changed the code as follows.

procedure Form1_btnParticulars_OnClick (Sender: string; var Cancel: boolean);
begin
  Form1Button := 'Particulars';
  //Form1.btnEdit.Click;
end;

procedure Form2_OnShow (Sender: string; Action: string);
begin
Form2OnShow01;
Form2OnShow02;
Form2OnShow03;
end;

procedure Form2OnShow01;
begin
   If Form2.dbAction = 'NewRecord' then
   begin
   Form2.GroupBoxParticulars.Enabled:= False;
   Form2.GroupBoxCheckboxCategory.Enabled:= True;
   Form2.GroupBoxDetails.Enabled:= True;
   end;
end;

procedure Form2OnShow02;
begin
   If Form2.dbAction = 'ShowRecord' then
   begin
   Form2.GroupBoxParticulars.Enabled:= False;
   Form2.GroupBoxCheckboxCategory.Enabled:= True;
   Form2.GroupBoxDetails.Enabled:= True;
   end;
end;

procedure Form2OnShow03;
begin
   If (Form2.dbAction = 'ShowRecord') and (Form1Button = 'Particulars') then
   begin
   Form2.GroupBoxParticulars.Enabled:= True;
   Form2.GroupBoxCheckboxCategory.Enabled:= False;
   Form2.GroupBoxDetails.Enabled:= False;
   end;
end;
Adam
God... please help me become the person my dog thinks I am.