1

I was looking through an application being ported from C to PASCAL (win32 API) and cannot understand, why the type PAINTSTRUCT in C changes to TpaintStruct in PASCAL.

Here are the snippets where it could be seen:

long FAR PASCAL ClientWndProc(HWND hwnd, UINT msg, UINT mp1, LONG mp2)
{
    static int cxClient, cyClient;
    HBITMAP hbm;
    BITMAP bm;
    PAINTSTRUCT ps;
    ...

turns into

function ClientWndProc(hwnd: WinTypes.HWND; msg: Word; mp1: Word; mp2: Longint): Longint; export;

var
    hdc: WinTypes.HDC;
    hdcMem: WinTypes.HDC;
    hbm: WinTypes.HBITMAP;
    bm: TBITMAP;
    ps: TpaintStruct;
    ...

I need to port one app myself. Should the same thing apply to TEXTMETRIC type as well? Should I call it TtextMetric in PASCAL?

1
  • 1
    Pascal says nothing about Windows. Are you talking about Delphi? Or perhaps Borland TurboPascal? Nov 13, 2011 at 19:30

3 Answers 3

3

Delphi (and Turbo Pascal before it, IIRC) has always had the custom of prefixing types with T, as in TStringList, TButton, TCustomForm, TDateTime, and so forth.

You can find TTextMetric (and TPaintStruct) declared for you already in the Windows.pas unit, along with many of the standard WinAPI functions.

(WinTypes is deprecated, by the way. It's an old carryover from Delphi 1 for 16 bit apps, and is automatically replaced by Windows in later versions of Delphi.)

5
  • So the Windows.pas unit basically takes every single function of the API and re-declares it with a prefixed "T"? Isn't that completely negating the purpose of language independent win32 API functions?
    – joncys
    Nov 13, 2011 at 18:58
  • The Win32 API declarations are suitable only for C compilers. Nov 13, 2011 at 19:02
  • @joncys, no, that's not what I said at all. The API functions are defined as you'd expect. Types are prefixed with T, not functions. And it's impossible to "take every single function of the API" anywhere; Windows.pas declares many, but in no way all, of the ones most commonly used.
    – Ken White
    Nov 13, 2011 at 19:05
  • @KenWhite I'm sorry, I've foolishly mistaken types for functions in my comment. Still doesn't make sense for me why you would have them named differently. Oh, and this university task involves porting OS/2 apps to win32 API, so everything "deprecated" adds to the irony.
    – joncys
    Nov 13, 2011 at 19:19
  • @joncys, it's a compatibility/custom issue. Since all Borland Pascal (Turbo or Delphi) declared types as starting with T (to make them more easily recognizable as such, I'd suspect), and there are thousands of those T type declarations in the VCL and RTL, it only made sense to add the T to WinAPI types as well for consistency. (At least that would be my guess, anyway).
    – Ken White
    Nov 13, 2011 at 19:24
1

It's just so it will fit better with Pascal's naming convention. You can follow it if you want and your code will look more Pascal-like, but nothing bad will happen if you don't.

1

Pascal originally had an unified namespace for identifiers. That means that X as a type and X as an variablename, field etc would clash.

To remedy APIs that exploited the fact that this works differently in C (and thus failed to be truely language agnostic), a convention was introduced to prefix types with T.

Afaik this was already done for Turbo Vision, the package for which OOP was added to (Turbo)Pascal. Which, afaik, was a port from C++.

Later, in Delphi this was scheme was expanded. (using e.g. "A" for parameter names). But some of the hungarian notation in Delphi might have been for the GUI designer's benefit too.

Afaik only in D4, Delphi allowed fieldtype identifiers to be the same as fieldnames.

1
  • Sorry. not record names, but field names vs field types. I corrected it. Nov 17, 2011 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.