2
votes

Im new to Delphi, trying to make debug on a project which is implemented years ago. My ide is Delphi 2010 and the code with error;

function DrawTextExW(hDC: HDC; lpString: PWideChar; nCount: Integer; var lpRect:
TRect; uFormat: UINT; dtp: PDRAWTEXTPARAMS): Integer;

const
   MAX_STATIC_BUFFER = 8192;
const
   STATIC_BUFFER_LEN: integer = 8192;
const
   DT_PREFIXONLY = $00200000;

var
...
  tm: TTextMetricA;
...

begin
  ...

  GetTextMetrics(hDC, tm);    //Error Line
  if (uFormat and DT_EXTERNALLEADING) = DT_EXTERNALLEADING then
    lh := tm.tmHeight + tm.tmExternalLeading
  else
    lh := tm.tmHeight;

  ...
end

Getting "[DCC Error] ElVCLUtils.pas(3555): E2033 Types of actual and formal var parameters must be identical" error in that line. What is wrong with this code?

1
The compiler tells you exactly what's wrong with the code. Identify the var parameter, and then check the types of the actual and formal parameters in question. You'll see they don't match.Rob Kennedy
Have you considered whether this function even needs to exist anymore? DrawTextExW is already provided by the OS. Maybe your project comes from a time when you were targeting Ansi versions of Windows, like Windows 98. Those versions aren't supported by Microsoft or Embarcadero, so maybe you don't need to support them, either. Then you could delete all this code instead of fixing it.Rob Kennedy
Rob, you must be right about support, the project coming before christ :) I will write project again in a different platform so trying to read and understanding the algorithm. Serg's answer is enough for a quick fix. thanks for your answer ;)ffffffff

1 Answers

7
votes

You should use either

var
...
  tm: TTextMetric;
...

begin
  ...

  GetTextMetrics(hDC, tm);

or

var
...
  tm: TTextMetricA;
...

begin
  ...

  GetTextMetricsA(hDC, tm);

the first version is preferable.