问题如下:
    for x:=1 to j do 
    begin
     for y:=1 to b do 
     begin
      if checkbox1.checked then 
      begin
        label1:=tlabel.create(self);
        label1.parent:=image[x][y]
        label2:=tlabel.create(self);
        label2.parent:=image[x][y]
        label1.caption:='adfd';  
        label2.caption:='asdfds';
      end else begin
        label1.caption:='';
        label2.caption:=''; 
      end;
     end;
    end;     现在界面上有两幅图像,当checkbox1.checked:=true时,两幅图像上都有label的值,但当checkbox1.checked:=false时,只有第二幅上的label没值,预想的结果是两幅图上的label都没值显示
各位帮忙试一下就知道了

解决方案 »

  1.   

    if checkbox1.checked then 
          begin
            label1:=tlabel.create(self);
            label1.parent:=image[x][y]
            label2:=tlabel.create(self);
            label2.parent:=image[x][y]
            label1.caption:='adfd';  
            label2.caption:='asdfds';
          end else begin
            label1:=tlabel.create(self);
            label1.parent:=image[x][y]
            label2:=tlabel.create(self);
            label2.parent:=image[x][y]
            label1.caption:=''; //还没有创建
            label2.caption:=''; 
          end;
      

  2.   

    to wjlsmail(计算机质子)
     还是这样的
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        CheckBox1: TCheckBox;
        Label1: TLabel;
        Label2: TLabel;
        procedure CheckBox1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CheckBox1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if CheckBox1.Checked then
      begin
        Label1.Caption := 'Cheched' ;
        Label2.Caption := 'Cheched' ;
      end
      else
      begin
        Label1.Caption := '' ;
        Label2.Caption := '' ;
      end;end;end.
      

  4.   

    噢,是我没说清楚,label的知识没错我的意思是,当checkbox1.checked:=true时,两幅图像都有label的值显示出来,但当checkbox1.checked:=false时,原本想两幅图像上的label的值都为空,但结果是第二幅中的label的值为空,第一幅中的值仍存在的
      

  5.   

    这样试试 :for x:=1 to j do 
        begin
         for y:=1 to b do 
         begin       label1:=tlabel.create(self);
           label1.parent:=image[x][y]
           label2:=tlabel.create(self);
           label2.parent:=image[x][y]
           label1.caption:='';  //
           label2.caption:='';  //       if checkbox1.checked then 
           begin
             label1.caption:='adfd';  
             label2.caption:='asdfds';
           end else begin
             label1.caption:='';
             label2.caption:=''; 
          end;
         end;
        end;     
      

  6.   

    label1.parent:=image[x][y]
    //这个... ,这儿的Image[x][y] : TImage 吗 ?
      

  7.   

    image[x][y]:array [0..40]of array [0..40]of timage;
    就像用反白这种处理方式,按一按钮,两幅图像同时反白,再按一下,两幅图像的反白效果同时消失。但现在是再按一下,只有第二幅的反白效果消失。我觉得是因为在进行上述操作后,x:=2,y:=2,就指向了第二幅图像。有没有什么办法?
      

  8.   

    if CheckBox1.Checked=true then
      begin
        Label1.Caption := 'Cheched' ;
        Label2.Caption := 'Cheched' ;
      end
      else
      begin
        Label1.Caption := '' ;
        Label2.Caption := '' ;
      end;
      

  9.   

    楼主 :    你的代码 ,     image[x][y]:array [0..40]of array [0..40]of timage;
        label1.parent:=image[x][y] ; 这可以吗 ?TWinControl ?  
     
      

  10.   

    你所说的:
    ----------------
    当checkbox1.checked:=true时,两幅图像都有label的值显示出来,但当checkbox1.checked:=false时,原本想两幅图像上的label的值都为空,但结果是第二幅中的label的值为空,第一幅中的值仍存在的------------------------------------------------------------------这样应该可以 :for x:=1 to j do 
        begin
         for y:=1 to b do 
         begin       label1:=tlabel.create(self);
           label1.parent:=image[x][y]
           label2:=tlabel.create(self);
           label2.parent:=image[x][y]
           label1.caption:='';  // 先置空
           label2.caption:='';  //       if checkbox1.checked then 
           begin
             label1.caption:='adfd';  
             label2.caption:='asdfds';
           end else begin
             label1.caption:='';
             label2.caption:=''; 
          end;
         end;
        end;     
      

  11.   

    供您参考 :---------------------------unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        CheckBox1: TCheckBox;
        procedure CheckBox1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CheckBox1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      Label1,Label2 : TLabel ;
    begin  Label1 := TLabel.Create(self) ;
      Label1.Parent := Self ;
      Label1.Left := 10 ;
      Label1.Top := 20 ;
      Label1.Caption := '' ;  Label2 := TLabel.Create(Self) ;
      Label2.Parent := Self ;
      Label2.Left := 10 ;
      Label2.Top := 40 ;
      Label2.Caption := '' ;  if CheckBox1.Checked then
      begin
        Label1.Caption := 'Cheched' ;
        Label2.Caption := 'Cheched' ;
      end
      else
      begin
        Label1.Caption := '' ;
        Label2.Caption := '' ;
      end;
    end;end.
      

  12.   

    to  wjlsmail(计算机质子) ( ) 
    应该是 lab1.parent:=image[x][y].parent;
      

  13.   

    很明显的,你指向到第一幅画的两个label无法用label1,label2来指向了:
    因为现在它指向的是第二幅画中的两个label!
      

  14.   

    也做两个相应的label数组吧。
    label1[x][y]:array [0..40]of array [0..40]of Tlabel;
    label2[x][y]:array [0..40]of array [0..40]of Tlabel;
    for x:=1 to j do 
        begin
         for y:=1 to b do 
         begin
          if checkbox1.checked then 
          begin
            label1[x][y]:=tlabel.create(self);
            label1[x][y].parent:=image[x][y]
            label2[x][y]:=tlabel.create(self);
            label2[x][y].parent:=image[x][y]
            label1[x][y].caption:='adfd';  
            label2[x][y].caption:='asdfds';
          end else begin
            label1[x][y].caption:='';
            label2[x][y].caption:=''; 
          end;
         end;
        end;
      

  15.   

    应该是你的意思吧-----------------------
    unit Unit19;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        CheckBox1: TCheckBox;
        Image1: TImage;
        Image2: TImage;
        procedure CheckBox1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CheckBox1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      Label1,Label2 : TLabel ;
    begin  Label1 := TLabel.Create(self) ;
      Label1.Parent := Image1.Parent ;
      Label1.Left := Image1.Left ;
      Label1.Top := Image1.Top + 10 ;
      Label1.Caption := '' ;
      Label2 := TLabel.Create(Self) ;
      Label2.Parent := Image2.Parent ;
      Label2.Left := Image2.Left ;
      Label2.Top := Image2.Top + 10  ;
      Label2.Caption := '' ;  if CheckBox1.Checked then
      begin
        Label1.Caption := 'Cheched' ;
        Label2.Caption := 'Cheched' ;
      end
      else
      begin
        Label1.Caption := '' ;
        Label2.Caption := '' ;
      end;
    end;end.
      

  16.   

    谢谢 NightCloud(),照你的方法已解决。
     
    to  wjlsmail(计算机质子) ( ) 
    谢谢你的帮助。但我的image一定得用二维数组。我将另开贴感谢二位