我自己定义了一个类
type
  CoinImg = class (TImage)
  private
    strImgPath:String;
  public
    function GetImg(strImgName:string):boolean;
end;
然后调用
procedure TForm1.LblSingleOneClick(Sender: TObject);
var
  Coin1:CoinImg;
  bolGetImgFlag:boolean;
begin
  Coin1 := CoinImg.Create(self);
  Coin1.Left :=LblSingleOne.Left + Two;
  Coin1.top :=LblSingleOne.top - Two;
  bolGetImgFlag := Coin1.GetImg('PinkCoin.bmp');
  if bolGetImgFlag=false then
  begin
    showmessage('error');
    exit;
  end;end;
程序执行没问题,但我想要的图片老是不出来,LblSingleOne是一个lable.
大家帮帮忙/

解决方案 »

  1.   

    楼上说的对,你没有指定你的类的parent啊,
      

  2.   

    procedure TForm1.LblSingleOneClick(Sender: TObject);
    var
      Coin1:CoinImg;
      bolGetImgFlag:boolean;
    begin
      Coin1 := CoinImg.Create(self);
      coin1.parent:=form1;//也可是是panel
      Coin1.Left :=LblSingleOne.Left + Two;
      Coin1.top :=LblSingleOne.top - Two;
      bolGetImgFlag := Coin1.GetImg('PinkCoin.bmp');
      if bolGetImgFlag=false then
      begin
        showmessage('error');
        exit;
      end;