.
.
컴포넌트 하나를 폼위에 올려놓고 쓰다가 그 컴포넌트의
protected member를 Access해야 하는 경우가 있습니다.
이미 올려진 컴포넌트를 지우고, 그 컴포넌트를 상속하는 새로운 컴포넌트를
만들어서 등록하고... 의 과정을 거쳐 사용하면 일이많죠. 이런 경우에
사용 해볼만한 팁입니다.
delphi 3000 에서 가져왔습니다.
TWinControl의 Color property 를 예로 설명하면
TWinControlEx = class(TWinControl)
public
property Color; //protected in TWinControl
end;
이렇게 해서 Color property를 Access할 수 있는 class를 만들어서, 실제로 이
컨트롤을 팔레트에 등록하지는 않고 타입캐스트만 해서 사용합니다.
procedure TForm1.ColorControl(Sender: TObject);
var
I : Integer;
begin
for I:= 0 to ControlCount -1 do
begin
if Controls[I] is TWinControl then
begin
if TWinControl(Controls[I]).Focused then
TWinControlEx(Controls[I]).Color := clRed // <- 이 부분이 타입캐스트해서 protected를 Access
else
TWinControlEx(Controls[I]).Color := clWindow; // <- 이 부분이 타입캐스트해서 protected를 Access
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Screen.OnActiveControlChange := ColorControl;
end;
제가 보기에는 제법 쓸만한 방법인것 같은데.
.
.
|