Re: Convert C-Builder program to Delphi?

From: W. D. (NewsGroups_at_US-Webmasters.com)
Date: 01/28/05

  • Next message: Enrico: "Update Contacts Outlook"
    Date: Fri, 28 Jan 2005 16:58:53 -0600
    
    

    Maarten Wiltink wrote:
    >
    > "W. D." <NewsGroups@US-Webmasters.com> wrote in message
    > news:41F9DEB9.428@US-Webmasters.com...
    > [...]
    > > // C++: DLLFUNC(int) SomeDLL_Open();
    > > Function SomeDLL_Open(): Integer; StdCall;
    > > Exports SomeDLL_Open Name 'SomeDLL_Open';
    > >
    > > // Apparently, the 'Exports' keyword can be placed anywhere, so
    > > // why not just after the Function is declared?
    >
    > It can? I didn't know that. It seems to be customary to have
    > all the exports together in the project file. There are things
    > to be said for both.

    Yep. From the help file:

    "An exports clause can appear anywhere and any number of
    times in the declaration part of a program or library,
    or in the interface or implementation section of a unit.
    Programs seldom contain an exports clause."

    >
    > [...]
    > > Now I have a few more questions: Even though this format
    > > compiles, will I have any problems with the pointers that
    > > I pretty much ignored in these translations? If so, how
    > > should I alter this code?
    >
    > Yes, that's one ugly habit you have. A pointer to something is
    > something decidedly different from the thing itself. You cannot
    > treat them as anything close to interchangeable.

    Understood. Delphi is supposed to automatically handle the
    pointers in various data types, so I am perplexed when to use
    them when C requires manual handling.

    >
    > If T is a type identifier, ^T is a type for pointers to items
    > of type T. For many types TX, a corresponding type PX already
    > exists which is a pointer to TX. The issue is muddied by the
    > fact the in C, an array is declared as a pointer to the first
    > element and further elements are accessed through pointer
    > arithmetic.

    Exactly. Can anyone 'point' to a cheat *** on pointer
    arithmetic in Delphi?

    >
    > > Also, Type definitions 1, & 2, below seem to make sense,
    > > but #3 has multiple data types as arguments. And #4 has
    > > that extra parameter, 'BOOL'. What should I do in this
    > > case?
    > >
    > > // (1) C++: typedef int (__stdcall *FUNC_OPEN)();
    > > Type FUNC_OPEN = Function(): Integer; StdCall;
    > >
    > > // (2) C++: typedef void (__stdcall *FUNC_CLOSE)();
    > > Type FUNC_CLOSE = Function(): Integer; StdCall;
    > >
    > > // (3) C++: typedef int (__stdcall *FUNC_GET)(BYTE*,PBYTE*,DWORD*);
    > > Type FUNC_GET = Function({ ???? }): Integer; StdCall;
    > >
    > > // (4) C++: typedef void (__stdcall *FUNC_SHOWICON)(BOOL);
    > > Type FUNC_SHOWICON = Procedure(); StdCall;
    >
    > You know what a procedure prototype looks like in Pascal, right?
    > In C, you're allowed to leave out the parameter names because they
    > don't need to match anyway. Pascal makes you include formal names
    > because otherwise it wouldn't look like Pascal or something.

    Right. That's why I like Pascal--it keeps you out of run-time
    trouble.

    In these cases, is *ANYTHING* needed inside parentheses, or will
    Delphi allow any type of data types?

    Also, when there is a parameter at the end, should I just ignore
    it as is the case with '(BOOL)'?

    >
    > As for "BOOL", see "LongBool".

    Hmmm. LongBool -- that's a new one for me. I wonder why more
    than 1 type of boolean would be needed. I guess just for type
    matching. In this conversion, I've just been using 'Boolean'.
    According to the Help file a LongBool takes up 4 bytes:

    A Boolean variable occupies one byte of memory, a ByteBool
    variable also occupies one byte, a WordBool variable
    occupies two bytes (one word), and a LongBool variable
    occupies four bytes (two words).

    It's also interesting that Dr. Bob's HeadConv page shows
    'Bool', which doesn't exist in Delphi/Pascal as far as I
    know:

    http://www.drbob42.com/delphi/headconv.htm

    >
    > Groetjes,
    > Maarten Wiltink


  • Next message: Enrico: "Update Contacts Outlook"
  • Quantcast