1

私は Delphi の学習者です。色相、彩度、明度の基本色を変換するコードを探していました。私はこのフォーラムでそれを手に入れ、次のように実装しました:

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.

コンパイルの時点で、Delphi は
[DCC エラー] Unit1.pas(150): E2035 実パラメータが不足しています。
以下の行で:

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));

エラーを削除するには?

4

2 に答える 2

6

このような問題を自分で解決する方法について説明します。

ステップ 1: コンパイラ エラーの意味を理解する

率直に言って、このエラーは一目瞭然です。

十分な実パラメータがありません

さて、十分なパラメーターを渡しませんでした。ただし、明らかでない場合は、エラー メッセージ テキストとエラー コード (この場合は E2035) をお気に入りの検索エンジンに入力します。これにより、次のようなコンパイラ エラーのドキュメントが表示されます。

このエラー メッセージは、プロシージャまたは関数の呼び出しで、プロシージャまたは関数の宣言で指定されたよりも少ないパラメータを指定した場合に発生します。

そして、それがどのように起こるかを示すいくつかの例があります。それはすべて有益な情報です。時間をかけて注意深く読んでください。

ステップ 2: エラーの原因となっているコード行を特定する

すべて次のように見える 3 つのインスタンスがあります。

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

ステップ 3: ステップ 1 で学んだことを失敗したコード行に適用する

4 つの関数/プロシージャ コールがあります。それぞれのパラメータを確認してください。呼び出し時に渡すパラメーター、つまり実際のパラメーターに対して関数の宣言を確認します。

3 つの内部関数のパラメーター数は一致します。しかし、 への呼び出しを見てくださいRGBToHSV。この関数には 6 つのパラメーターがありますが、3 つしか渡しませんでした。


上記は、理解できないコンパイラ エラーに直面したときに採用する一般的な手順です。この手法は、他の異なるコンパイラ エラーに直面したときに適用できます。

于 2013-07-23T21:07:51.790 に答える
3
procedure RGBToHSV(Const R, G, B: Real; Out H, S, V: Real);

戻り値なしで6 つのパラメーターを宣言していますが、 3 つのパラメーターのみを使用して呼び出し、その戻り値 (存在しない) を変数に割り当てています。呼び出しを 1 つだけに変更する必要があります。

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>
);
于 2013-07-23T20:57:14.593 に答える