Solved

C to Delphi: typedef struct ...

Posted on 2007-11-22
8
1,949 Views
Last Modified: 2010-05-18
I'm trying to convert some of the headers from GSL package written in C, into Delphi.

There are several fields in some structures which I can't interpret, for example: gsl_rng_type.

-----------------------------------------
typedef struct
  {
    const char *name;
    unsigned long int max;
    unsigned long int min;
    size_t size;
    void (*set) (void *state, unsigned long int seed);    // <- ???????
    unsigned long int (*get) (void *state);     // <- ???????
    double (*get_double) (void *state);    // <- ???????
  }
gsl_rng_type;
-----------------------------------------

I got as far as....
-----------------------------------------
  gsl_rng_type = packed record
    name: PChar;
    max: LongInt;
    min: LongInt;
    size: Cardinal;
-----------------------------------------
0
Comment
Question by:den4b
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 300 total points
ID: 20333843
These are function pointers or in other words call back functions.Check what is the replacement for function pointers

void (*set) (void *state, unsigned long int seed);
unsigned long int (*get) (void *state);
double (*get_double) (void *state);
0
 
LVL 6

Author Comment

by:den4b
ID: 20333853
I thought that they might be method pointers, but I'm not sure how to correctly translate them.... That is exactly my question.
0
 
LVL 6

Author Comment

by:den4b
ID: 20333874
Would that be correct translation?
  _gsl_rng_type = packed record
    name: PChar;
    max: LongInt;
    min: LongInt;
    size: Cardinal;
    set_: procedure(state: Pointer; seed: LongInt);
    get_: function(state: Pointer): LongInt;
    get_double: function(state: Pointer): Double;
  end;

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 20334105
Not sure about call backs in Delphi, but have a look
http://delphi.about.com/od/windowsshellapi/a/callback_delphi.htm
0
 
LVL 19

Assisted Solution

by:MerijnB
MerijnB earned 200 total points
ID: 20334177
my guess you'll have to make a type for the functions:
type TProcSet = procedure(state: Pointer; seed: LongInt);
     PProcSet = ^TProcSet
 
     _gsl_rng_type = packed record
       name: PChar;
       max: LongInt;
       min: LongInt;
       size: Cardinal;
       set_: PProcSet;
       ...
     end;

Open in new window

0
 
LVL 6

Author Comment

by:den4b
ID: 20334557
Can't test it yet, because I have to convert a lost more headers first, but it sound good already!

The only uncertain thing left is "set_: TProcSet" or "set_: PProcSet". I thought that "TProcSet" would already be a function pointer in Delphi, in which case I could use just "set_: procedure(state: Pointer; seed: LongInt)".

Anyway, I can check that out later...
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20334568
I'm quite sure you'll need PProcSet, TProcSet is not a pointer itself.
0
 
LVL 6

Author Comment

by:den4b
ID: 20334582
Ohh, the only thing which I forgot to mention is to use "cdecl" calling convention for the functions written in C. For example: procedure(state: Pointer; seed: LongInt); cdecl;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Firemonkey DbLookupComboBox equivalent ? 2 67
Precision Problem in C++ 7 48
DBCtrlGrid, Delphi, Scroll 8 57
Outlook 13 80
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question