mierlp Posted July 27, 2018 Share Posted July 27, 2018 Hi I have 2 forms, see attachment - form1 contains the datasource (call them DS1 and DS2) for form1 AND form2, - form1 contains information which is store in ds2, see - there\s a master/detail betweens ds1 and ds2 - form2 contains no datasources, is linked to form1 Each datasource contains a .StateChange event with the following code: What it does is checking the state of the table, Based on the state (edit or browse) some of the buttons are enabled/disabled. Just like a dbnavigator works. if dmProduction.ProductionQuickDay.State in [dsBrowse] then begin FormTableProductionQuickDay.UniBitBtn_Add.Enabled := True; FormTableProductionQuickDay.UniBitBtn_Delete.Enabled := True; FormTableProductionQuickDay.UniBitBtn_Save.Enabled := False; FormTableProductionQuickDay.UniBitBtn_Cancel.Enabled := False; end; if dmProduction.ProductionQuickDay.State in [dsInsert,dsEdit] then begin FormTableProductionQuickDay.UniBitBtn_Add.Enabled := False; FormTableProductionQuickDay.UniBitBtn_Delete.Enabled := False; FormTableProductionQuickDay.UniBitBtn_Save.Enabled := True; FormTableProductionQuickDay.UniBitBtn_Cancel.Enabled := True; end; When i click on the button 'Beheren productie dagen' (below the dbgrid on the right side) the form2 will be showed So for so good. When i change a value,- lets say select a other value in the dblookupcombox. At that moment DS2 is in StateChange and some buttons must be enabled/disabled. Because all datasource are on form1 this is not working. Normally in vcl mode you could use some code like if (assigned(Form1) then begin if dmProduction.ProductionQuickDay.State in [dsBrowse] then begin FormTableProductionQuickDay.UniBitBtn_Add.Enabled := True; FormTableProductionQuickDay.UniBitBtn_Delete.Enabled := True; FormTableProductionQuickDay.UniBitBtn_Save.Enabled := False; FormTableProductionQuickDay.UniBitBtn_Cancel.Enabled := False; end; if dmProduction.ProductionQuickDay.State in [dsInsert,dsEdit] then begin FormTableProductionQuickDay.UniBitBtn_Add.Enabled := False; FormTableProductionQuickDay.UniBitBtn_Delete.Enabled := False; FormTableProductionQuickDay.UniBitBtn_Save.Enabled := True; FormTableProductionQuickDay.UniBitBtn_Cancel.Enabled := True; end; end; How can i do this, is there a other way to check if a form is assigned or a other solutions to enable/disable button when the datasource.StateChange is triggerd Link to comment Share on other sites More sharing options...
Wilton Ergon Posted July 27, 2018 Share Posted July 27, 2018 your code can be cleaner as well. FormTableProductionQuickDay.UniBitBtn_Add.Enabled := NOT dmProduction.ProductionQuickDay.State in [dsInsert,dsEdit]; FormTableProductionQuickDay.UniBitBtn_Delete.Enabled := NOT dmProduction.ProductionQuickDay.State in [dsInsert,dsEdit]; FormTableProductionQuickDay.UniBitBtn_Save.Enabled := dmProduction.ProductionQuickDay.State in [dsInsert,dsEdit]; FormTableProductionQuickDay.UniBitBtn_Cancel.Enabled := dmProduction.ProductionQuickDay.State in [dsInsert,dsEdit]; I would put the querys and datasoures and a datamodule to share between different forms Link to comment Share on other sites More sharing options...
mierlp Posted July 28, 2018 Author Share Posted July 28, 2018 Hi Wilton Thats indeed a cleaner peace of code thanks. That works... Within my application i use datamodules and all querys are on the datamodule I have about 120 forms and 14 datamodules. Datasources are on the forms where i need them. Whats not working is that i need to check if the form is active or opened or showed. Otherwise when i open form1 directly and automaticly form2 will be showed Even if datasource.autoedit = false I need a way to check if a form is opened/showed? Link to comment Share on other sites More sharing options...
Ron Posted July 31, 2018 Share Posted July 31, 2018 If form2 can only be accessed through form1, then form1 has to be active if form2 is visible. Unless you have closed form1, that is. But you can then close form2 too, to make sure that form1 is always active before form2 gets shown. Syncronized closing. Otherwise you can save the form visibility state in a global variable, visible or not, updated on OnShow and OnClose. Or you can combine the two interfaces by using an expandable panel or variable form height where hidden parts of the form contain the second interface controls. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now