Forms Delphi

Title: DialogUnits To Pixels
Question: How to convert dialogs units in pixels if the dialog do not use system font
Answer:
function DialogUnitsToPixels(DialogUnits: Integer; Canvas: TCanvas; Font: TFont):Integer;
var
A : Array[0..52] of char;
Z : Integer;
U : Word;
begin
// select the current font
SelectObject(Canvas.Handle,Font.Handle);
// Get DialogBaseUnit for system font
U := HiWord(GetDialogBaseUnits) div 4;
// compute mean width of characters in current font
// as recommended by Microsoft
A := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
Z := (Canvas.TextWidth(A) Div 26 + 1) Div 2 ;
// Compute result and adjust for screen resolution
Result := DialogUnits * Z Div U * Screen.PixelsPerInch div 96;
end;