Home > Back-end >  A let I don't know how to describe the multi-thread problem
A let I don't know how to describe the multi-thread problem

Time:10-02

//thread class the following
Type
Tusercj=class (TThread)
User: string;
Pass: a string;
Name: string;//the nickname
Date_str: string;//acquisition date
Date_t: tDate;//acquisition date
Date_curr: TDate;//date collection and the current date now
Get_day: Integer;//need to collect the number of days
Htmlcode: string;
STR: string;
Error_count: Integer;//error statistics
TAB: TTabSheet;
Memo: TmxMemo;//log dialog
Param: TStringList;//POST submission parameter
Idssl: TIdSSLIOHandlerSocket;//SSL need
Idhttp: TIdHTTP;//POST to get the data controls
Vercode: TMemoryStream;//verification code file bytes
Qry qry1, qry2: TADOQuery;
Protected
Procedure the Execute; Override.//thread and make
Procedure the main ();//acquisition main function
Procedure data_count ();//data statistics
Procedure save_xml ();//generate XML
Procedure log (STR: string);//log
The function get_data () : Integer;//get data specified date
The function check_error () : a Boolean;//check whether achieve maximum error
The function selectuser () : a Boolean;//check if the date data exist
The function get_vercode () : string;//to get verification code
The end;

The Execute; With the Create TAB and M
TAB:=TTabSheet. Create (Form1. Pgc1);
TAB. Caption:=the self. The user;
TAB. Parent:=Form1. Pgc1;
TAB. PageControl:=Form1. Pgc1;
TAB. The Align:=alClient;
Memo:=tmxmemo. Create (TAB);
Memo. Parent:=TAB;
Memo. The Align:=alClient;

Problem is to create the MEMO does not receive any news and events, such as the above write a MEMO to normal display. But add a MEMO on lines. The add (" text "); MEMO field on your form is showed not to come out, use sendmessage sending messages to also do not accept, but if you are creating manual MEMO opens at the form, after reoccupy sendmessage sending messages, and can receive,

Question is why MEMO will not display properly

CodePudding user response:

This is a thread safety,
Should not be created in the thread and access interface element,

Suggestion: after the data is ready, through SendeMessage message to main form, tell the main form has been processed, the main form can hang up the thread (see your needs), structural interface elements and reads the data thread class prepared...

CodePudding user response:

Thank you moderator's adult, but I now the question is, memo is thread execution logs to reality, you can see there is a LOG process, is it sendmessage send used to create a memo data, processed to build is certainly not

CodePudding user response:

refer to the second floor lmjloavcj response:
thank moderator's adult, but I now the question is, memo is thread execution logs to reality, you can see there is a LOG process, is it sendmessage send used to create a memo data, processed to build is certainly not

The log data acquisition process?
Anyhow, you create and access interface, must not be in the thread,
If you consider the log process, then it should be before the thread starts, advance the interface ready to go,
Threads execute when the postmessage with reading data submitted to the main thread, main form processing this message, add data to the Memo,

CodePudding user response:

Initialize all sorts of data and control the execute
The main is Lord of the acquisition process
Under the log is a sendmessage send log message is sent to the MEMO under this thread class of

I am writing to well control, if the MEMO to create good, first thread don't know what to send logs to which will use again on MEMO loop to read the MEMO on the data to determine which MEMO sent to such efficiency is too slow

CodePudding user response:

The
reference 4 floor lmjloavcj reply:
execute is initialized all sorts of data and control
The main is Lord of the acquisition process
Under the log is a sendmessage send log message is sent to the MEMO under this thread class of

I am writing to well control, if the MEMO to create good, first thread don't know what to send logs to which will use again on MEMO loop to read the MEMO on the data to determine which MEMO sent to such efficiency is too slow

First, and then explain don't do that in the thread interface Settings;
Second, "if the MEMO to create a good first, thread don't know what to send logs to which" on the MEMO, you can with the identity of the thread when sending a message, determined by the logo MEMO (interface initialization and thread creation, can be treated in the same location and associated),

Problem actually not complex, think more, don't cry because it is a little small problems, "detour" to go, but when we come back

CodePudding user response:

Delphi threads access UI controls, to synchronize ~ ~ ~ ~ ~ ~ to synchronization

CodePudding user response:

Control belong to the UI, to return to the main thread to update content,

CodePudding user response:

Consult TTimer code,
After receiving the message, update Memo,

CodePudding user response:

refer to 6th floor linuxpingwangping response:
Delphi threads access UI controls, to synchronize ~ ~ ~ ~ to synchronize ~ ~

The classmate say for thread synchronization function interface is used, appears to be syncronize function, check your help

CodePudding user response:

Threads do not use interface elements directly, the window of the Delphi, controls should be in the main thread. Syncronize is possible, because it is sending a message to the main thread, in the main thread of execution

CodePudding user response:

Overloading thread constructor, in the heart of the constructor memo as arguments to the threads in the main interface, and then use, there is no problem, you create these in your thread execution function is certainly not!

CodePudding user response:

In the thread object defines a Memo
_Memo: TMemo;

Overloaded unit thread constructor
Public
//overloaded constructor here (just how many parameters you can
The constructor Create (aMemo: TMemo);
//reloading the destructor
The Destructor Destroy; Override.

//thread structure function (all of the parts need to be initialized wrote it)
The constructor TNetThread. Create (aMemo: TMemol);
The begin
_Memo:=aMemo;
FreeOnTerminate:=true;//marks after the thread execution, automatic release resources
Inherited the Create (true);//thread creation does not perform the specified operation is performed (if it is false, immediately after creating executed)
The end;

//thread destructor (thread after releasing resources)
Destructor TNetThread. Destroy;
The begin
_Memo:=nil;
Inherited;
The end;

//thread execution function
Procedure TNetThread. Execute;
The begin
_memo. Lines. The add (' execution success);
The end;

CodePudding user response:

Estimate you modify the Execute memo also add, after application. The intrinsic processMessage to send the message to the main thread to update the interface

CodePudding user response:

reference 13 floor luxuewei5214 reply:
estimate you modify the Execute memo also add, after the application. The intrinsic processMessage to send the message to the main thread to update interface

Don't need the Application. The intrinsic processMessage, change can be seen directly, I often use, so the Application. The intrinsic processMessage is in the same main thread need to refresh the control is used when (at this time there may be a loss of operation in the execution).

CodePudding user response:

SendMessage to Memo directly!
  • Related