Forum > General

Assigning members of an array of procedures

(1/1)

dkjMusic:
I have an array of procedures: Handler: array[1..26] of procedure(var Buffer: TStringList);
to process chemical information based on the type of information:
Enthalpy_of_Formation
Other_Thermochemical_Data
Dielectric_Constant
Refractive_Index
...

The Handler procedures are:
procedure Enthalpy_of_Formation(var Buffer: TStringList);
procedure Other_Thermochemical_Data(var Buffer: TStringList);
procedure Dielectric_Constant(var Buffer: TStringList);
procedure Refractive_Index(var Buffer: TStringList);
...

I presently assign the Handler array members "manually", i.e.,
Handler[1] := @Enthalpy_of_Formation;
Handler[2] := @Other_Thermochemical_Data;
Handler[3] := @Dielectric_Constant;
Handler[4] := @Refractive_Index;
...

But the types of information are in PropList: TStringList ([1]:='Enthalpy_of_Formation',
[2]:='Other_Thermochemical_Data',...

So, is there a way to assign the Handler array members based on the array of types of chemical information? e.g., Handler := @Magic_Wand(PropList);

Maybe using the name-value feature of TStringList to store the pointers of the procedures associated with each information type? What would this look like?

User137:
Just throwing out some related ideas:

--- Code: ---type
  THandlerProcedure = procedure(var Buffer: TStringList);
 
  THandlerType = (htNormal, htSomethingElse, htThirdKind);
  THandlerRecord = record
    proc: THandlerProcedure;
    name: string;
    hType: THandlerType;
  end;

var hRecords: array[1..26] of THandlerRecord;
--- End code ---
The record can hold pointer to procedure and also carry information of it, which you can use to analyze if you want to add it to an array in a procedure.

Navigation

[0] Message Index

Go to full version