Got some error in Delphi 7

I'm making a delphi program which contains frames...and in one frame i've got the following function :

function GetDecimal(VAR tdecimal : integer) : string;

Var dp : string;

begin

Case tdecimal Of
0 : dp := '0';
1 : dp := '0.0';
2 : dp := '0.00';
3 : dp := '0.000';
4 : dp := '0.0000';
5 : dp := '0.00000';
6 : dp := '0.000000';
7 : dp := '0.0000000';
8 : dp := '0.00000000';
9 : dp := '0.000000000';
10 : dp := '0.0000000000';
11 : dp := '0.00000000000';
12 : dp := '0.000000000000';
13 : dp := '0.0000000000000';
14 : dp := '0.00000000000000';
15 : dp := '0.000000000000000';
16 : dp := '0.0000000000000000';
end; {end case}
Getdecimal := dp;

end;

Later in the program I call the function with the following line :

checkdp := GetDecimal(decimaldigit); {check decimal place function}

checkdp is of type string, and decimaldigit is integer.
However when I run the program, an error occurs when I call the function, saying too many actual parameters. I just can't find the solution for it (and probably it will be some stupid mistake).

I would greatly appreciate your help.
Thank you
Andrew

Comments

  • : I'm making a delphi program which contains frames...and in one frame i've got the following function :
    :
    : function GetDecimal(VAR tdecimal : integer) : string;
    :
    : Var dp : string;
    :
    : begin
    :
    : Case tdecimal Of
    : 0 : dp := '0';
    : 1 : dp := '0.0';
    : 2 : dp := '0.00';
    : 3 : dp := '0.000';
    : 4 : dp := '0.0000';
    : 5 : dp := '0.00000';
    : 6 : dp := '0.000000';
    : 7 : dp := '0.0000000';
    : 8 : dp := '0.00000000';
    : 9 : dp := '0.000000000';
    : 10 : dp := '0.0000000000';
    : 11 : dp := '0.00000000000';
    : 12 : dp := '0.000000000000';
    : 13 : dp := '0.0000000000000';
    : 14 : dp := '0.00000000000000';
    : 15 : dp := '0.000000000000000';
    : 16 : dp := '0.0000000000000000';
    : end; {end case}
    : [red]Getdecimal := dp;[/red]
    :
    : end;
    :
    : Later in the program I call the function with the following line :
    :
    : checkdp := GetDecimal(decimaldigit); {check decimal place function}
    :
    : checkdp is of type string, and decimaldigit is integer.
    : However when I run the program, an error occurs when I call the function, saying too many actual parameters. I just can't find the solution for it (and probably it will be some stupid mistake).
    :
    : I would greatly appreciate your help.
    : Thank you
    : Andrew
    :
    In Delphi you don't use the function name to set the return value of the function, but you must use the implicitly defined variable: Result. So the red part should read:
    [code]
    Result := dp;
    [/code]
    Also here is a much better way to code this:
    [code]
    function GetDecimal(VAR tdecimal : integer) : string;
    var
    i: integer;
    begin
    if tdecimal < 0 then
    Result := '0'
    else
    begin
    Result := '0.';
    for i := 1 to tDecimal do
    Result := Result + '0';
    end;
    end;
    [/code]
  • [b][red]This message was edited by abcfantasy at 2005-4-20 0:51:32[/red][/b][hr]
    Ok i did as you said but strangely enough i still get the same error :S

    Ok somehow i fixed the error. Thankx :)

  • : [b][red]This message was edited by abcfantasy at 2005-4-20 0:51:32[/red][/b][hr]
    : Ok i did as you said but strangely enough i still get the same error :S
    :
    : Ok somehow i fixed the error. Thankx :)
    :
    :
    Perhaps GetDecimals() already exists as a method. Try calling your function: MyGetDecimals(), or something completely outrageous like GetDecimals12345(). This way you can see if it already exists.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories