As the TFrame is dynamically created at run time, it runs some code to calculate the TextWidth. However, at this time, the parent of frame is not assigned yet. Hence, for some reason, if the TFrame has no parent (probably has to be a visual control), its canvas property is nil. I have moved the code to calculate the TextWidth away from the Create section.
Lesson: TFrame seems to depend on a parent for its canvas property, and any access to canvas of any objects on TFrame should not be done in Create.