For a Delphi project (built with RAD Studio XE7), I want to create a dictionary of brushes. Each dictionary item contains a TMyBrush object as key, that describes the brush to retrieve, and a GDI+ brush as value.
The TMyBrush class contains 3 fields
- An enumerated type to determine the kind of brush (solid, gradient, ...)
- A TBrushInfo class that describes the brush content (color, wrap mode, ...)
- A TRect that represents a clamp field
In my dictionary, I want to retrieve a brush based on his characteristics, and not on his instance. For example, I want to get a black solid brush from my dictionary by creating a local TMyBrush instance, configuring it to black solid, and getting the matching GDI+ value using the TryGetValue() function. For that, I created a TMyBrushComparer.
Writing the Equals() function isn't a problem for me. However I don't know what is the best practice to write the GetHashCode() function. I would tend to write a function like this:
function TMyBrushComparer.GetHashCode(const pValue: TMyBrush): Integer;
begin
Result := BobJenkinsHash(pValue, SizeOf(TMyBrush), 0);
end;
however I feel that is not a very good practice, it is correct? So, what is the best practice to write a good GetHashCode() function for my TMyBrushComparer?
Regards