Child thread has three variables a, b, c, how to pass to the main thread form1 and at the same time, the dynamic load to the Listview, and then the main thread can normal operation, do not feign death? Best can have a collective code shown, thank you
CodePudding user response:
If a, b, c is the normal variables, such as the boolen, such as int, directly using the PostMessage pass variables to the main thread,
If your variable is a string, or to apply for the temporary memory within the thread, best can apply for a structure in the main thread (note that this structure of the life cycle to carry three variables, and then using PostMessage to inform the main thread, structure has changed,
CodePudding user response:
reference 1st floor m617105 response: if a, b, c is the normal variables, such as the boolen, such as int, directly using the PostMessage pass variables to the main thread, If your variable is a string, or to apply for the temporary memory within the thread, it is best to apply for in the main thread of a structure (note that this structure of the life cycle to carry three variables, and then using PostMessage to inform the main thread, structure has changed, Is there a specific code, I like Internet sendmessage a bit better, is not used, CodePudding user response:
Sendmessage hair message, the main form of handle, value is what counts CodePudding user response:
reference ksrsoft reply: 3/f sendmessage hair message, the main form of the handle, just value SendMessage (h1, WM_SETTEXT, 255, an Integer (PChar (IP))); Thread to send, so how to receive in the main thread? CodePudding user response:
It is ok to send messages, 32-bit system can pass two data, a total of 64, if not enough to define a few news, CodePudding user response:
Why not consider, in turn, The main form of ListView when creating the thread object is passed to the child thread, how to operate all of the child thread can, don't have to refresh the main thread interface, real-time display, CodePudding user response:
refer to 6th floor nm_wyh response: why not consider, in turn, The main form of ListView when creating the thread object is passed to the child thread, how to operate all of the child thread can, don't have to refresh the main thread interface, real-time display, how to pass the object to the child thread, the specific implementation code? Thank you CodePudding user response:
reference 4 floor shunshunjoe response: Quote: reference ksrsoft reply: 3/f Sendmessage hair message, the main form of the handle, just value SendMessage (h1, WM_SETTEXT, 255, an Integer (PChar (IP))); Thread to send, so how to receive in the main thread? Interface on processing WM_SETTEXT method can receive treatment, CodePudding user response:
refer to 7th floor shunshunjoe response: Quote: refer to the sixth floor nm_wyh response: Why not consider, in turn, The main form of ListView when creating the thread object is passed to the child thread, how to operate all of the child thread can, don't have to refresh the main thread interface, real-time display, how to pass the object to the child thread, the specific implementation code? Thank you Rewrite the thread constructor and destructor (can be any number of parameters in the constructor) The constructor Create (aList: TListView); The Destructor Destroy; Override. Define a public LIstView object in thread unit, MainListView: TListView; The rewriting in the constructor of the //thread structure function -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- The constructor TDemoThread. Create (aList: TListView); The begin MainListView:=aList; 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 set to False, as soon as you create run end; //destructors //thread destructor -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Destructor TDemoThread. Destroy; The begin MainListView:=nil; Inherited; end; CodePudding user response:
Any place can be operating in thread unit MainListView object CodePudding user response:
refer to 6th floor nm_wyh response: why not consider, in turn, The main form of ListView when creating the thread object is passed to the child thread, how to operate all of the child thread can, don't have to refresh the main thread interface, real-time display, Synchronization issues?