Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

what is C float in Delphi? how to transfer parametrs by value?

Posted on 1998-11-23
10
Medium Priority
?
577 Views
Last Modified: 2010-04-04
Hi,

I am trying to access a C .dll from Delphi.
If a function in the .dll receives "float" is it "Real" in Delphi?
if the C function recieves a pointer to float (float * fuu) what should be my decleration?

Thanks,
Tommy
0
Comment
Question by:tommyq
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1347709
A C float is a single in Delphi (ie 4byte IEEE float)

Your function would translate exactly to:

Type
  PtrFloat = ^Single;

procedure MyFunction(MyPtrFloatArg: PtrFloat);

However, if it is a pointer to a float because you want to modify the float and return it it will look like this:

procedure MyFunction(var MyArg : Single);

Cheers,

Raymond.  
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1347710
Oh yeah...

The complete declaration would look like this for the DLL protoype...

procedure MyFunction(var MyArg : Single); external 'TheDLL.DLL';

Cheers,

Raymond.
0
 

Author Comment

by:tommyq
ID: 1347711
Raymond,

Thanks for your prompt reply.
I'll try it out and let you know.

Tommy
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:tommyq
ID: 1347712
Why can't I use Double?

Tommy

(Raymond, I am reopening the question only in order to get an answer)
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347713
You can't use a double because it is 8 bytes in size. I may compile given that it is bigger than float, but you are definitely not guaranteed a sensible result.

If your app deals in doubles, then you could do some casting before and after calling the dll function.

Also, the complete declaration should be like this:
procedure MyFunction(PMyArg : ^Single); stdcall; external 'TheDLL.DLL';
It was missing the stdcall in Ray's solution.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1347714
The float constructor in C is exactly the same as the single type in Delphi. They use 4 bytes each.

You can also use the 8 bytes long floating point values known as double in both Delphi and C.

The delphi types float (6 bytes) and Extended (10 bytes) does not seem to be supported in C (Watcom v11.0)

/Williams
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1347715
Tommyq,

I believe my answer is the first correct one. Will you now select and accept an answer? (If you want to award the points to me you will need to reject Williams2 answer).

Cheers,

Raymond.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1347716
Sorry Raymond,

You are absolutely right. I was a bit fast asnwering, and didn't read your comment.

So Toomyq, please reject my answer!

Regards,
Williams
0
 

Author Comment

by:tommyq
ID: 1347717
Rejecting in order to give points to Raymond.

Thank you Williams.
Raymond, come and collect your points!

Tommy
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 1347718
Here I am!

Cheers,

Raymond.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

926 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