Q&A

  • 동적생성된 스피드버튼과 팝업메뉴에 대한 질문입니다..
스피드 버튼을 툴바위에 동적으로 생성을 하고

스피드 버튼을 클릭(마우스 왼쪽 버튼)했을때

그 스피드 버튼에 해당하는 팝업을 띄우려고 합니다..





저는 팝업창을 띄우는 마우스 클릭 이벤트를 하나 정의하고

스피드 버튼을 동적 생성할때 그 이벤트를 불러다 썼습니다.





그런데 제일 마지막으로 생성된 팝업메뉴가 모든 버튼에 적용이 되는군요..

각 버튼마다 생성되는 팝업이 틀려야 하거든요...

어떻게 하면 좋을지 방법을 가르쳐 주세요..



아래는 제 소스를 간추린 것입니다..





type



procedure MyButtonClick(Sender: TObject);



.

.

.



implementation



procedure TForm1.MyButtonClick(Sender: TObject);

begin

PopupMenu1.Popup(Left+ToolBar1.Left+TSpeedButton(Sender).Left + 5,

Top+ToolBar1.Top+TSpeedButton(Sender).Height + 47);

end;



.

.

.



while NOT EOF(txt) do //txt는 파일

begin



.

.

.



if aChar[1] = 'S' then

begin

if Row = 1 then

begin

ButtonCaption := Parsing(Line); //Parsing은 제가 만든 함수

NewItem := TMenuItem.Create(PopupMenu1);

NewItem.Caption := ButtonCaption;

PopupMenu1.Items.Add(NewItem);

end

else

begin

with TSpeedButton.Create(Self) do

begin

Parent := ToolBar1;

Flat := True;

Left := MaxInt;

end;

end; //if Row 끝

end; //if 'S' 끝



if aChar[1] = 'X' then

begin

ButtonCaption := Parsing(Line);

PopupMenu1 := TPopupMenu.Create(application);

PopupMenu1.AutoHotkeys := maManual;



with TSpeedButton.Create(Self) do

begin

Parent := ToolBar1;

Flat := True;

Left := MaxInt;

OnClick := MyButtonClick;

end;



Row := Row+1;



end; //if 'X' 끝



if Copy(Line,1,3) = 'E:X' then

begin

Row := Row-1;

end;





end; //while 끝

1  COMMENTS
  • Profile
    홍성락 2001.09.19 22:13
    델초보 wrote:

    > 스피드 버튼을 툴바위에 동적으로 생성을 하고

    > 스피드 버튼을 클릭(마우스 왼쪽 버튼)했을때

    > 그 스피드 버튼에 해당하는 팝업을 띄우려고 합니다..

    >

    >

    > 저는 팝업창을 띄우는 마우스 클릭 이벤트를 하나 정의하고

    > 스피드 버튼을 동적 생성할때 그 이벤트를 불러다 썼습니다.

    >

    >

    > 그런데 제일 마지막으로 생성된 팝업메뉴가 모든 버튼에 적용이 되는군요..

    > 각 버튼마다 생성되는 팝업이 틀려야 하거든요...

    > 어떻게 하면 좋을지 방법을 가르쳐 주세요..

    >

    > 아래는 제 소스를 간추린 것입니다..

    >

    >

    > type

    >

    > procedure MyButtonClick(Sender: TObject);

    >

    > .

    > .

    > .

    >

    > implementation

    >

    > procedure TForm1.MyButtonClick(Sender: TObject);

    > begin

    > PopupMenu1.Popup(Left+ToolBar1.Left+TSpeedButton(Sender).Left + 5,

    > Top+ToolBar1.Top+TSpeedButton(Sender).Height + 47);

    > end;

    >

    > .

    > .

    > .

    >

    > while NOT EOF(txt) do //txt는 파일

    > begin

    >

    > .

    > .

    > .

    >

    > if aChar[1] = 'S' then

    > begin

    > if Row = 1 then

    > begin

    > ButtonCaption := Parsing(Line); //Parsing은 제가 만든 함수

    > NewItem := TMenuItem.Create(PopupMenu1);

    > NewItem.Caption := ButtonCaption;

    > PopupMenu1.Items.Add(NewItem);

    > end

    > else

    > begin

    > with TSpeedButton.Create(Self) do

    > begin

    > Parent := ToolBar1;

    > Flat := True;

    > Left := MaxInt;

    > end;

    > end; //if Row 끝

    > end; //if 'S' 끝

    >

    > if aChar[1] = 'X' then

    > begin

    > ButtonCaption := Parsing(Line);

    > PopupMenu1 := TPopupMenu.Create(application);

    > PopupMenu1.AutoHotkeys := maManual;

    >

    > with TSpeedButton.Create(Self) do

    > begin

    > Parent := ToolBar1;

    > Flat := True;

    > Left := MaxInt;

    > OnClick := MyButtonClick;

    > end;

    >

    > Row := Row+1;

    >

    > end; //if 'X' 끝

    >

    > if Copy(Line,1,3) = 'E:X' then

    > begin

    > Row := Row-1;

    > end;

    >

    >

    > end; //while 끝

    /////////////////////////////////////////////////////////////////

    문제는 버튼은 동적생성을 하나 팝업메뉴는 하나를 사용하게 되므로 일어나는것 같습니다.

    2가지방법을 예시해보겠습니다.

    1. 버튼생성시 팝업메뉴도 같이 생성하세요.

    2.팝업메뉴를 공유하고자할때

    버튼생성은 위와 같이 별도로하되 팝업메뉴 아이템생성부분은 빼구요



    procedure TForm1.MyButtonClick(Sender: TObject);

    begin

    =>이부분에 txt는 파일내용과 TSpeedButton(Sender).Caption을 검색해

    해당버튼 클릭때마다 팝업메뉴아이템을생성하세요

    (위 내용중 반대로 버튼생성코드를 빼서 TSpeedButton(Sender).Caption에 맞게하시면됩니다)

    PopupMenu1.Popup(Left+ToolBar1.Left+TSpeedButton(Sender).Left + 5,

    Top+ToolBar1.Top+TSpeedButton(Sender).Height + 47);

    end;