Skip to main content
GameDev.net gamedev.net
🔒 Locked

Delphi function results

Started by Sappharos Aug 24, 2008 at 7:05 AM 4 replies 1.4k views
Original Post
Sappharos
Sappharos
I'm a newbie with programming, and indeed this is my first post on these forums, so please excuse my ignorance. Question is (and I hope it makes sense): In Delphi, how do you use a function with two parts to the result, such as DivMod?
nb
nb
you are probably after something like...

Procedure MyDivMod(A,B : Extended; var Div : Integer; var Mod : Extended);
begin
end;

the important parts are that it's not a 'function', but just a normal procedure... and that the div and mod variable you pass to it will also come back out to however they are altered within the procedure. So pass it the variables 'a,b, div, mod' and then look at the div and mod variables to see what they read as.

edit : crap, i forgot to make note of the 'var' declaration before div and mod. that's what makes them a 'two way street' so to speak instead of just taking a value in and then doing whatever with no consequence to the original.
Marmin
Marmin
as function this:

typedivmod = recorddiv_ : integer;mod_ : extended;end;function _divmod_ (input, input2 : extended): divmod;begin result.div_  := input DIV input2; result.mod_  := input MOD input2;end;procedure Test;vartester : divmod;begintester := _divmod_ (var1, var2);end;
Sappharos
Sappharos
Thanks, :) I tried this:

DivMod (MainMap [X, Y], 2, 0, 0);


It comes up with this error: "Types of actual and formal var parameters must be identical."

I'm posting the Delphi help file on the DivMod function to make more sense of this, hopefully...

DivMod procedure:

Returns the result of an integer division, including the remainder.

procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: Word);


Description:

Call DivMod to perform 16-bit integer division and fetch the remainder as well, all in one operation.

Dividend is the integer into which you are dividing.

Divisor is the value by which to divide Dividend.

Result returns the result of the integer division.

Remainder returns the remainder (the difference between Result * Divisor and Dividend).
Marmin
Marmin
You have to put variables at the last two. How else can it return something.
See an example here: http://delphi.about.com/library/rtl/blrtlDivMod.htm

divmod is a procedure and not a function.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.