user2612109
user2612109

Reputation: 225

How to remove [DCC Error] : E2035 Not enough actual parameters

I am a Delphi learner. I was looking for some codes to convert basic colours in Hue, Saturation and Value. I have got it in this forum and I have implemented it like :

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Math;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure HSVToRGB(Const H, S, V: Real; Out R, G, B: Real);
const
  SectionSize = 60/360;
var
  F: real;
  P, Q, T: real;
  Section: real;
  SectionIndex: integer;
begin
  if H < 0 then
    begin
      R:= V;
      G:= R;
      B:= R;
    end
  else
    begin
      Section:= H/SectionSize;
      SectionIndex:= Floor(Section);
      F:= Section - SectionIndex;
      P:= V * ( 1 - S );
      Q:= V * ( 1 - S * F );
      T:= V * ( 1 - S * ( 1 - F ) );
      case SectionIndex of
        0:
          begin
            R:= V;
            G:= T;
            B:= P;
          end;
        1:
          begin
            R:= Q;
            G:= V;
            B:= P;
          end;
        2:
          begin
            R:= P;
            G:= V;
            B:= T;
          end;
        3:
          begin
            R:= P;
            G:= Q;
            B:= V;
          end;
        4:
          begin
            R:= T;
            G:= P;
            B:= V;
          end;
        else
          begin
            R:= V;
            G:= P;
            B:= Q;
          end;
      end;
    end;
end;


procedure RGBToHSV(Const R, G, B: Real; Out H, S, V: Real);
var
  Range: real;
  RGB: array[0..2] of real;
  MinIndex, MaxIndex: integer;
begin
  RGB[0]:= R;
  RGB[1]:= G;
  RGB[2]:= B;

  MinIndex:= 0;
  if G < R then MinIndex:= 1;
  if B < RGB[MinIndex] then MinIndex:= 2;

  MaxIndex:= 0;
  if G > R then MaxIndex:= 1;
  if B > RGB[MaxIndex] then MaxIndex:= 2;

  Range:= RGB[MaxIndex] - RGB[MinIndex];

  if Range = 0 then
    begin
      H:= -1;
      S:= 0;
      V:= R;
    end
    else
      begin
        case MaxIndex of
          0:
            begin
              H:= (G-B)/Range;
            end;
          1:
            begin
              H:= 2 + (B-R)/Range;
            end;
          2:
            begin
              H:= 4 + (R-G)/Range;
            end;
        end;
        S:= Range/RGB[MaxIndex];
        V:= RGB[MaxIndex];
        H:= H * (1/6);
        if H < 0 then H:= 1 + H;
      end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Hue, Saturation, Value: real;
  Red, Green, Blue: integer;
begin
  Red := GetRValue(Label1.Font.Color);
  Green := GetGValue(Label1.Font.Color);
  Blue := GetBValue(Label1.Font.Color);
  Hue := RGBToHSV(GetRValue(Label1.Font.Color), GetGValue(Label1.Font.Color), GetBValue(Label1.Font.Color));
  Saturation := RGBToHSV(GetRValue(Label1.Font.Color), GetGValue(Label1.Font.Color), GetBValue(Label1.Font.Color));
  Value := RGBToHSV(GetRValue(Label1.Font.Color), GetGValue(Label1.Font.Color), GetBValue(Label1.Font.Color));
  ShowMessage (FloatToStr(Hue) +','+ FloatToStr(Saturation)+',' + FloatToStr(Value));
end;

end.

At the time of compilation Delphi is throwing 3 Error as
[DCC Error] Unit1.pas(150): E2035 Not enough actual parameters.
on the lines below :

Hue := RGBToHSV(GetRValue(Label1.Font.Color), GetGValue(Label1.Font.Color), GetBValue(Label1.Font.Color));

Saturation := RGBToHSV(GetRValue(Label1.Font.Color), GetGValue(Label1.Font.Color), GetBValue(Label1.Font.Color));

Value := RGBToHSV(GetRValue(Label1.Font.Color), GetGValue(Label1.Font.Color), GetBValue(Label1.Font.Color));

How to remove the Errors?

Upvotes: 1

Views: 5221

Answers (2)

David Heffernan
David Heffernan

Reputation: 613511

I'm going to attempt to walk you through how to solve such a problem yourself.

Step 1: Work out what the compiler error means

Frankly, this error is self-explanatory.

Not enough actual parameters

Well, you did not pass enough parameters. However, if it's not obvious, then type the error message text, and the error code, E2035 in this case, into your favoured search engine. That will lead you to the documentation for the compiler error which says:

This error message occurs when a call to procedure or function gives less parameters than specified in the procedure or function declaration.

And there are some examples to demonstrate how it can happen. That's all useful information. Take some time to read it carefully.

Step 2: Identify the line of code which leads to the error

There are three instances which all look like this:

Hue := RGBToHSV(GetRValue(Label1.Font.Color), GetGValue(Label1.Font.Color), 
  GetBValue(Label1.Font.Color));

Step 3: Apply what we learnt in step 1 to the failing line of code

There are 4 function/procedure calls. Check the parameters for each one. Check the declaration of the function against parameters you pass when the calling, that is the actual parameters.

For the three inner functions, the parameter counts match. But look at the call to RGBToHSV. That function has six parameters, but you passed only three.


The above is a general procedure to adopt when facing a compiler error that you do not understand. You will be able to apply this technique when you face other, different, compiler errors.

Upvotes: 6

LeleDumbo
LeleDumbo

Reputation: 9340

procedure RGBToHSV(Const R, G, B: Real; Out H, S, V: Real);

You are declaring 6 parameters, without any return value, yet you call it using 3 parameters only, assigning its return value (which doesn't exist) to a variable. You should change the calls to just one:

RGBToHSV(
  GetRValue(Label1.Font.Color),
  GetGValue(Label1.Font.Color),
  GetBValue(Label1.Font.Color),
  <variable that will hold Hue value>,
  <variable that will hold Saturation value>,
  <variable that will hold Value value>
);

Upvotes: 3

Related Questions