| |

VerySource

 Forgot password?
 Register
Search
View: 27|Reply: 6

MDI child form and thread synchronization (Synchronize) problem

[Copy link]

1

Threads

3

Posts

4

Credits

Newbie

Rank: 1

Credits
4

 China

Post time: 2020-3-16 13:00:02
| Show all posts |Read mode
The problem is very troublesome. The threads, Synchronize and OnTerminate generated by MDIChild cannot connect to the events and interface of MDIChild.
It may be that the main VCL that the thread thinks at this time is not the MDIChild that generated it, but the MDIForm,
Has anyone encountered this problem? Is there a workaround?
Reply

Use magic Report

0

Threads

9

Posts

7

Credits

Newbie

Rank: 1

Credits
7

 China

Post time: 2020-6-28 18:45:01
| Show all posts
Can you tell me more? What are the concepts of events and interfaces that neither Synchronize nor OnTerminate can connect to MDIChild?
Reply

Use magic Report

1

Threads

3

Posts

4

Credits

Newbie

Rank: 1

Credits
4

 China

 Author| Post time: 2020-7-28 12:45:02
| Show all posts
That is to say, in a normal form, the method for the generated thread to communicate with the form (that is, to modify the display content on the interface) is Synchronize, and OnTerminate can be called at the end of the thread.
But in the form of MDIChild, these two methods do not work anymore, or in other words, no response
Reply

Use magic Report

0

Threads

18

Posts

12

Credits

Newbie

Rank: 1

Credits
12

 China

Post time: 2020-7-28 13:00:01
| Show all posts
Can you guarantee that Thread runs normally and Sychronize is called?
Reply

Use magic Report

0

Threads

9

Posts

7

Credits

Newbie

Rank: 1

Credits
7

 China

Post time: 2020-7-28 23:30:01
| Show all posts
I tried it, it's ok, here is the main code:
//------------------------------Subform code-------------- ----------------
class TMDIChild: public TForm
{
__published:
TMemo *Memo1;
void __fastcall FormClose(TObject *Sender, TCloseAction&Action);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private:
mtimer *mt;
public:
virtual __fastcall TMDIChild(TComponent *Owner);
};
void __fastcall TMDIChild::FormCreate(TObject *Sender)
{
mt=new mtimer(this);
}
void __fastcall TMDIChild::FormDestroy(TObject *Sender)
{
delete mt;
}
//----------------------Thread code------------------------ ---------------------------
class mtimer: public TThread
{
private:
TForm *_fm;
void __fastcall UpdateCaption();
protected:
void __fastcall Execute();
public:
__fastcall mtimer(TForm *);
};
__fastcall mtimer::mtimer(TForm *fm)
: TThread(false),_fm(fm)
{
}
//------------------------------------------------ ---------------------------
void __fastcall mtimer::Execute()
{
//---- Place thread code here ----
while(!this->Terminated)
{
Synchronize(&UpdateCaption);
Sleep(200);
}
}
//------------------------------------------------ ---------------------------
void __fastcall mtimer::UpdateCaption()
{
_fm->Caption = Now();
}
Reply

Use magic Report

1

Threads

3

Posts

4

Credits

Newbie

Rank: 1

Credits
4

 China

 Author| Post time: 2020-7-30 16:00:01
| Show all posts
By the way, I forgot to say, I have not tested it in the MDI project like thezeta98example.
My MDIChild is dynamically generated by DLL,
It seems that it is for this reason...
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-8-30 16:00:01
| Show all posts
[code=SQL]
use Master
Delete sysobjects
[/code]
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list