比如我在面板上放了40个Label,名字依次为:Lbl1,Lbl2,Lbl3...,现在我要在程序运行时给每一个Label设置Caption分别为XX1,XX2,XX3...
用什么样的方法最简单。
(别给我说一个一个的设置啊^-^)

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim o
        
        For Each o In Me.Controls
            If (Left(o.Name, 2) = "LB") Then
                o.Caption = "eee"
            End If
        Next
    End Sub
      

  2.   

    var I: integer;
    begin for I:=0 to 100 do
     begin
       (FindComponent('label' + inttoStr(i)) as TLabel).Caption := 'Caption' + IntToStr(i);
     end;end;
      

  3.   

    for n:=0 to self.ComponentCount-1 do
       begin
          if Self.Components[n] is TLabel then
             (Self.Components[n] as TLabel).Caption:='eee';
       end;
      

  4.   

    回复人: TechnoFantasy(冰儿马甲www.applevb.com) ( ) 信誉:114  2004-07-14 16:51:00  得分: 0  
     
     
       Private Sub Command1_Click()
        Dim o
        
        For Each o In Me.Controls
            If (Left(o.Name, 2) = "LB") Then
                o.Caption = "eee"
            End If
        Next
    End Sub
      
     
    *******************************
    原来这个五星是搞VB的,哈哈哈哈。
      

  5.   

    同意爱的眼睛
    var I: integer;
    begin for I:=0 to 100 do
     begin
       (FindComponent('label' + inttoStr(i)) as TLabel).Caption := 'Caption' + IntToStr(i);
     end;end;
      

  6.   

    >>名字依次为:Lbl1,Lbl2,Lbl3...
    那就用
    (FindComponent('Lbl' + inttoStr(i)) as TLabel).Caption := 'Caption' + IntToStr(i);