콤보박스를 하나 올려놓고 이벤트 핸들러를 폼과 콤보박스에 해당되는 이벤트를 만들었습니다. 그런데 에러가 생기는데 왜 그런건지요?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Add(IntToStr(clRed));
ComboBox1.Items.Add(IntToStr(clFuchsia));
ComboBox1.Items.Add(IntToStr(clBlue));
ComboBox1.Items.Add(IntToStr(clGreen));
ComboBox1.Items.Add(IntToStr(clYellow));
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
with Control as TComboBox,Canvas do
begin
Brush.Color := clWhite;
FillRect(Rect);
// then reduce it and fill it with the color
InflateRect(Rect,-2,-2);
Brush.Color := StrToInt(Items[Index]);
FillRect(Rect);
end;
end.
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin --- > 요기
with Control as TComboBox,Canvas do
begin
Brush.Color := clWhite;
FillRect(Rect);
// then reduce it and fill it with the color
InflateRect(Rect,-2,-2);
Brush.Color := StrToInt(Items[Index]);
FillRect(Rect);
end;
end; --- > 요기