procedure TForm1.Pop1_1Click(Sender: TObject);
var a:string;
begin
a:=PopMenu1.PopupComponent.Name;
if a = 'ListView1' then begin
   .......
   exit;
end;
if a = 'ListView2' then begin
   .......
   exit;
end;
if a = 'ListView3' then begin
   .......
   exit;
end;
if a = 'ListView4' then begin
   .......
   exit;
end;
我现在的有没办法共用啊

解决方案 »

  1.   

    就是说能直接使用调用的组件ListView(*)不用去判断
      

  2.   

    procedure TForm1.Pop1_1Click(Sender: TObject);
    begin
      with TListView(PopupMenu1.PopupComponent) do
        begin
        AddItem('DoSomething',nil);//这是举例应用
        //.....
        end;
    end;上面是用的with开域语句。如果不用,就是这样:procedure TForm1.Pop1_1Click(Sender: TObject);
    begin
      TListView(PopupMenu1.PopupComponent).AddItem('DoSomething',nil);
      TListView(PopupMenu1.PopupComponent).Color := clRed;
      //.....上面的AddItem和改变Color等应用,都是举例,你根据自己的需要去做
    end;
      

  3.   

    TListView(PopupMenu1.PopupComponent)的形式与 (PopupMenu1.PopupComponent as TListView)是一样的效果。
      

  4.   

    当然,如果PopupMenu不仅仅与几个TListView关联,应该这样做一下判断:procedure TForm1.Pop1_1Click(Sender: TObject);
    begin
      if PopupMenu.PopupComponent is TListView then //加上这个判断
         with TListView(PopupMenu1.PopupComponent) do
           begin
           AddItem('DoSomething',nil);//这是举例应用
           //.....
           end;
    end;