I implemented the following class:
type
TUtilProcedure = procedure(var AJsonValue: TJSONObject);
TCallback = class
private
FName: string;
FProcedure: TUtilProcedure;
FAnnotation: string;
public
constructor Create(AName: string; AProcedure: TUtilProcedure; AAnnotation: string); overload;
constructor Create(ACallback: TCallback); overload;
property Name: string read FName;
property Proc: TUtilProcedure read FProcedure;
property Annotation: string read FAnnotation;
end;
Then I have a global variable:
procedures: TDictionary<string, TCallback>;
In OnFormActivate
procedure I initalize the procedures
variable:
procedures := TDictionary<string, TCallback>.Create();
procedures.Add('something', TCallback.Create('sth', @proc, 'annotation'));
// ....
And then in OnFormClose
I free it:
procedures.Clear;
procedures.Free;
Does my code leak memory? If so what is the correct way to free the dictionary
?
From what I know iteration is not good idea.