Home > Back-end >  Help: window linkage data changes
Help: window linkage data changes

Time:09-17

I have a Form1, combobox is used for displaying the data list which is used for, and there is a button to add operation, when click on this button to open the Form2 (use showModal open, TForm2. Create (Self) showModal;) , I want to be in Form2 after adding the data in the database to close the window to refresh the combobox dropdown in the Form1 showed a gain of data

CodePudding user response:

If form2. Showmodel=mr_OK then
Cbb1. Items. The Add (' a ');

CodePudding user response:

There are two ways: a: write directly in FORM2 close events: FORM1. Cbb1. Items. Add (" ");
Global variables are defined: global variables in the form2 assignment, FROM2 is turned off, quoted in the FORm1,

CodePudding user response:

Said the train of thought:
1, Form2 is responsible for maintaining the data, has nothing to do with Form1
2, after Form2 closed Form1 refresh drop-down box options
The key here
Form1
button eventsForm2. Showmodal;
Freeandnil (Form2);//Form2 add new option to the database is ok, do not operate Form1, finished just released
ComboBox1. Items. The Clear;//remove old option in the drop-down box
AddList events;//the new option was obtained from the database, this event can be in Form1. Used in the Show, to optimize the code

Know what I mean?

CodePudding user response:

In the Form of the declaration of a refresh Combobox1 process,
Form2 closing, calls refresh Combobox1 process of Form1,

CodePudding user response:

More general method can use alerts, save the data to the database in Form2 succeeded, send a message to inform Form1 data has changed, and so can be decoupled Form2 and associated Form1, also can not qualified Form1 refresh data in any event,
Now Delphi support the observer pattern (publish/subscribe), very convenient, the reference System. Messaging unit,

CodePudding user response:

Shut down after the trigger the refresh button

CodePudding user response:

Very simple ah, now that your Form1 USES the Form2, you declare a variable in Form2 Interface, put you need to refresh the values here, in the OnClose Form2 put value in there, Form1 Form2. ShowModal and then fetch the data from the variables

CodePudding user response:

This question is very simple, it is ok to all:
TForm2. Create (Self). ShowModal;
Write directly here you refresh process

CodePudding user response:

Because of ShowModal; Is a modal show, so, shut off the Form2 will perform follow-up code, so, in the ShowModal; After calling the refresh process directly
  • Related