//AB/ Project Button Event Code Share Demo //AB/ Object prj is a View_Project //AB/ Set Size to 446 681 //AB/ Set ProjectName to "Button Event Code Share Demo" //AB/ Set ProjectFileName to "ButtonEventCodeShare.vw" //AB/ Set GenerateFileName to "NONAME" // Project Object Structure // oNewView is a dbView // oSample1Group is a Group // oSayHelloGroup1Button is a Button // oSayHelloTooGroup1Button is a Button // oSayGoodbyeGroup1Button is a Button // oSayGoodbyeTooGroup1Button is a Button // oSample2Group is a Group // oSayHelloGroup2Button is a Button // oSayHelloTooGroup2Button is a Button // oSample3Group is a Group // oSayHelloGroup3Button is a Button // oSayHelloTooGroup3Button is a Button // oSayGoodbyeGroup3Button is a Button // oSayGoodbyeTooGroup3Button is a Button // Register all objects Register_Object oNewView Register_Object oSample1Group Register_Object oSample2Group Register_Object oSample3Group Register_Object oSayGoodbyeGroup1Button Register_Object oSayGoodbyeGroup3Button Register_Object oSayGoodbyeTooGroup1Button Register_Object oSayGoodbyeTooGroup3Button Register_Object oSayHelloGroup1Button Register_Object oSayHelloGroup2Button Register_Object oSayHelloGroup3Button Register_Object oSayHelloTooGroup1Button Register_Object oSayHelloTooGroup2Button Register_Object oSayHelloTooGroup3Button //AB-IgnoreStart Use dfClient.pkg Use Windows.pkg //AB-IgnoreEnd DEFERRED_VIEW Activate_oNewView FOR ; ; Object oNewView is a dbView Set Border_Style to Border_Thick Set Icon to "Default.Ico" Set Label to "Code Share" Set Location to 2 2 Set Size to 173 165 //AB-DDOStart //AB-DDOEnd Object oSample1Group is a Group Set Size to 44 145 Set Location to 12 10 Set Label to "Sample 1:" Object oSayHelloGroup1Button is a Button Set Label to "Say Hello" Set Size to 14 60 Set Location to 10 5 //AB-StoreStart Procedure OnClick Send SayHelloGroup1 End_Procedure // OnClick //AB-StoreEnd End_Object // oSayHelloGroup1Button Object oSayHelloTooGroup1Button is a Button Set Label to "Say Hello Too" Set Size to 14 60 Set Location to 26 5 //AB-StoreStart Procedure OnClick Send SayHelloGroup1 End_Procedure // OnClick //AB-StoreEnd End_Object // oSayHelloTooGroup1Button Object oSayGoodbyeGroup1Button is a Button Set Label to "Say Goodbye" Set Size to 14 70 Set Location to 10 70 //AB-StoreStart Procedure OnClick Send SayGoodByeGroup1 End_Procedure // OnClick //AB-StoreEnd End_Object // oSayGoodbyeGroup1Button Object oSayGoodbyeTooGroup1Button is a Button Set Label to "Say Goodbye too" Set Size to 14 70 Set Location to 26 70 //AB-StoreStart Procedure OnClick Send SayGoodByeGroup1 End_Procedure // OnClick //AB-StoreEnd End_Object // oSayGoodbyeTooGroup1Button //AB-StoreStart Procedure SayHelloGroup1 Send Info_Box "Hello there!" "Group 1" End_Procedure // SayHello Procedure SayGoodByeGroup1 Send Info_Box "Goodbye you all!" "Group 1" End_Procedure // SayGoodbyeGroup1 // While you share the methods SayHelloGroup1 and SayGoodByeGroup1 you need // to individually send them from the OnClick event //AB-StoreEnd End_Object // oSample1Group Object oSample2Group is a Group Set Size to 44 145 Set Location to 58 10 Set Label to "Sample 2:" Object oSayHelloGroup2Button is a Button Set Label to "Say Hello" Set Size to 14 60 Set Location to 10 5 //AB-StoreStart Procedure OnClick Delegate Send OnClick End_Procedure // OnClick //AB-StoreEnd End_Object // oSayHelloGroup2Button Object oSayHelloTooGroup2Button is a Button Set Label to "Say Hello Too" Set Size to 14 60 Set Location to 26 5 //AB-StoreStart Procedure OnClick Delegate Send OnClick End_Procedure // OnClick //AB-StoreEnd End_Object // oSayHelloTooGroup2Button //AB-StoreStart Procedure OnClick Send Info_Box "Hello there!" "Group 2" End_Procedure // OnClick // In this example group we create a new method called OnClick // (The class Group does not define this) and execute this method // via a delegate send. As you can see there are only two buttons // (and not four) and this is because OnClick to say "Hello" is // not different from a OnClick to say "Goodbye". Technically there // is even a very thin diffence between the first group and this // one because both use delegation. Group 1 is using automatic // delegation and the Group 2 is using explicit delegation. //AB-StoreEnd End_Object // oSample2Group Object oSample3Group is a Group Set Size to 44 145 Set Location to 104 10 Set Label to "Sample 3:" Object oSayHelloGroup3Button is a Button Set Label to "Say Hello" Set Size to 14 60 Set Location to 10 5 //AB-StoreStart Set Message Item 0 To SayHelloGroup3 //AB-StoreEnd End_Object // oSayHelloGroup3Button Object oSayHelloTooGroup3Button is a Button Set Label to "Say Hello Too" Set Size to 14 60 Set Location to 26 5 //AB-StoreStart Set Message Item 0 To SayHelloGroup3 //AB-StoreEnd End_Object // oSayHelloTooGroup3Button Object oSayGoodbyeGroup3Button is a Button Set Label to "Say Goodbye" Set Size to 14 70 Set Location to 10 70 //AB-StoreStart Set Message Item 0 To SayGoodByeGroup3 //AB-StoreEnd End_Object // oSayGoodbyeGroup3Button Object oSayGoodbyeTooGroup3Button is a Button Set Label to "Say Goodbye too" Set Size to 14 70 Set Location to 26 70 //AB-StoreStart Set Message Item 0 To SayGoodByeGroup3 //AB-StoreEnd End_Object // oSayGoodbyeTooGroup3Button //AB-StoreStart Procedure SayHelloGroup3 Send Info_Box "Hello there!" "Group 3" End_Procedure // SayHelloGroup3 Procedure SayGoodByeGroup3 Send Info_Box "Goodbye you all!" "Group 3" End_Procedure // SayGoodbyeGroup3 // A button object does have one item. Each item does have a property called // Message. That property is used to store the identifier of the message // that gets executed when the ENTER key is pressed or the item is clicked. // The Button class defaults the message to the method OnClick. // OnClick is declared as an event in the button class and if you - as // programmer - do not intercept the event at object level nothing happens. // The button class also has a method called KeyAction. This is the method // you can use from On_Key statements. You use the KeyAction instead of // OnClick since the mouse click in a disabled button (enabled_state = false) // will not execute the OnClick while a On_Key (sending OnClick) would do // this. So if we - instead of in this example group - create a special // button class we need to augment both KeyAction and OnClick. It is not // done to augment an event at class level so we would need to define a new // click event. To do that we better use the technique shown in this // example group which alters the message to be send when the button is // clicked or receives the message KeyAction. //AB-StoreEnd End_Object // oSample3Group CD_End_Object // oNewView //AB/ End_Object // prj