Pixel of the reference class instance in BCB implementation

xiaoxiao2021-03-06  48

In the implementation of the class, especially the subclass implementation of the FORM class of BCB, one of the cases often appear: In the implementation of the class, the variables in one instance implementation implementation, In some cases, this use does not have a system error, but in additional cases, there may be an error, and the following detailed analysis of this problem. Open the BCB, create a new application engineering (that is, the default), then add a new form (TFORM2) to it, add two buttons button1, button2, separately Double-click to write the following code in the Click event (to first include TFORM2's header file unit2.h): void __fastcall tform1 :: button1click (TOBJECT * Sender) {form2-> showModal ();} // -------------------------------------------------- ------------------------- void __fastcall tform1 :: button2click (TOBJECT * Sender) {TFORM2 * FORM2; FORM2 = New TFORM2 (Application); Form2 -> ShowModal (); delete form2; form2 = null; = NULL;} where Button1 is the instance of instances of automatically generated TFORM2 classes; button2 is a newly created instance, and then run. On TFORM2 form, add 3 buttons and 1 text box, add the following event function: void __fastcall tform2 :: button1click (TOBJECT * Sender) {Application-> MessageBoxa (edit1-> text.c_str (), " Tips ", MB_OK);} // ----------------------------------------- --------------------------------- void __fastcall tform2 :: button2click (TOBJECT * Sender) {Application-> MessageBoxa ("Calling Button1 Click Events by Class Variables!", "Tips", MB_OK); Button1Click (Sender); // or button1-> click ();} // ------------ -------------------------------------------------- ------------- void __fastcall tform2 :: button3click (TOBJECT * Sender) {Application-> MessageBoxa ("Cable Events of Button1 by class instance!", "Tips", MB_OK); Form2 -> Button1Click (sender); // or FORM2-> Button1-> Click ();} Run the program, click on Button1 on the main form, change the contents of the pop-up form from 2 Edit1, click on each button, everything is normal, Make a note of the content in Edit1 and close the FORM2.

转载请注明原文地址:https://www.9cbs.com/read-110177.html

New Post(0)