Home > Back-end >  Delphi dynamically create forms, in the thread form, how to take form the value of a variable in a f
Delphi dynamically create forms, in the thread form, how to take form the value of a variable in a f

Time:09-27

 var 
FormMsg: TForm3;
The begin
//
If assigned (FormMsg) then
The begin
FormMsg:=TForm3. Create (Self);
FormMsg. MsgParm. S_PayId:=IntToStr (FormMsg. Handle);
FormMsg. MsgParm. FormHand:=FormMsg. Handle;
FormMsg. Show;
The end;
The end;


So I can get right to the value in Form3

Head Form3
 unit Unit3. 

Interface

USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. ExtCtrls, Vcl. StdCtrls, Vcl.Com Ctrls;

Type TMsginfo=record
S_Op: string;
FormHand: Integer;
ItemId: Integer;
The end;
PMsginfo=^ TMsginfo;

Type
TForm3=class (TForm)
Memo1: TMemo;
Memo2: TMemo;
Splitter1: TSplitter;
For: TButton;
StatusBar1: TStatusBar;
Procedure Button1Click (Sender: TObject);
Procedure FormClose (Sender: TObject; Var Action: TCloseAction);
Procedure FormShow (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
MsgParm: TMsginfo;
The end;

Var
Form3: TForm3;
MsgThread: Integer;
B_MsgComplent: Boolean;
Implementation




 procedure TForm3. Button1Click (Sender: TObject); 
Var
I: string;
The begin
I:=MsgParm. S_PayId;
The end;


The thread I want how to value below, please help me with the
 procedure TForm3. FormShow (Sender: TObject); 
Var
ThreadID: Cardinal;
The begin
//MsgParm. FormHand:=the Self;
MsgParm. S_Op:='Open';//here can correct values
B_MsgComplent:=True;
//MsgDo (1);
MsgThread:=CreateThread (nil, 0, @ MsgDo, @ MsgParm, 0, ThreadID);
The end;

The function MsgDo (P: Pointer) : Integer;
Var
Payid: string;
The begin
Payid:=PMsgParm (P) ^. S_PayId;//this is less than the
Payid:=MsgParm. S_PayId;//this is less than the
//if not dynamically create
Payid:=Form3. MsgParm. S_PayId;//this also take less than

The end;



How do I value in this thread, pass the value

CodePudding user response:

Create a thread, don't preach MsgParm go in, but to preach the TForm3 instances, such as:
MsgThread:=CreateThread (nil, 0, @ MsgDo, Self , 0, ThreadID);
Again in the thread through the instance MsgParm access the domain variables,

CodePudding user response:

The function MsgDo (P: Pointer) : Integer;
Define error, change to the
The function MsgDo (P: Pointer) : Integer; Stdcall;

CodePudding user response:

Directly to a global variable is bad?
  • Related