Procedure tform1.button1click (Sender: tobject); var STR: string; Wh: tsize; W, H: integer; begin {previously used canvas. textwidth, canvas. textheight} STR: = 'wan'; W: = canvas. textwidth (STR); H: = canvas. textheight (STR); showmessage (format ('width: % d; Height: % d', [W, H]); {width: 12; height: 13 }{ equal width font, the width of multiple characters must be a multiple relationship} STR: = 'case'; W: = canvas. textwidth (STR); H: = canvas. textheight (STR); showmessage (format ('width: % d; Height: % d', [W, H]); {width: 24; height: 13} {canvas. the textextent function can obtain the font height and width at the same time, But it returns a tsize structure} wh: = canvas. textextent (STR); W: = Wh. CX; H: = Wh. cy; showmessage (format ('width: % d; Height: % d', [W, H]); {width: 24; height: 13 }{ if the font size changes, the height and width will also change} canvas. font. size: = 16; Wh: = canvas. textextent (STR); W: = Wh. CX; H: = Wh. cy; showmessage (format ('width: % d; Height: % d', [W, H]); {width: 42; Height: 25} {font. height is writable} canvas. font. height: = 32; Wh: = canvas. textextent (STR); W: = Wh. CX; H: = Wh. cy; showmessage (format ('width: % d; Height: % d', [W, H]); {width: 52; Height: 32} end;