Home > Back-end >  The incoming parameter data types
The incoming parameter data types

Time:09-16

 

///thinking about a program, there are several solutions, in want to these solutions by thread initialization parameter is passed in,

//but the field these solutions are common, there are different: how to write?

//such as:

//there are parameters:
Fname: string;
FType: TSchemeType;

//plan 1:
Procedure Run;

//solution 2:
Procedure Car;

//solution 3:
Procedure the airLine;

//thread initialization time transfer scheme,

WorkThread. Create (Scheme);//here's how to define data types, the Scheme can be compatible with the above several programs?


//if you can, please give an example, thank you, thank you very much,


CodePudding user response:

You don't have to define TSchemeType, generally can be enumerated type

CodePudding user response:

Structure or custom classes

CodePudding user response:

I this is just an example above,
Specific implementation, not just the three process, maybe there are a lot of fields,
Want to have different plan content into different classes to operate, then incoming parameters through a data type,

The equivalent of

Procedure sample (strList: TStrings);

When using can pass in TStringList or TStringStream types,

CodePudding user response:

It is recommended to use TStringList into parameters,

CodePudding user response:

Configuration of the scheme is more, with bad TStringList lane,

Want to use a custom class incoming parameters, and judgment to deal with in the thread,

CodePudding user response:

 
Type
TMyParamStru=record
RunProc: TProcedure;
OtherParam: an array of Integer [0.. 1];
end;

TWorkThread=class (TThread)
Private
FInitPm: TMyParamStru;
Protected
Procedrue Execute; Override.
Public
The constructor Create (InitPm: TMyParamStru);
end;

The constructor TWorkThread. Create (InitPm: TMyParamStru);
The begin
FInitPm:=InitPm;
Inherited the Create (True, True);
end;

Procedure TWorkThread. Execute;
The begin
If Assigned (FInitPm. RunProc) then the begin
FInitPm. RunProc;
end;
end;

CodePudding user response:

Can consider to use generic
  • Related