不准确的别乱说哦~
A.picture.bitmap.assign(B.picture.bitmap)
它们是共用的一个指针地址吗?

解决方案 »

  1.   

    assign,我看了DELPHI本身的源码,很多用了assign,我不知道那些地方可以用,也不太明白,请各位高手指示.
      

  2.   

    当然不共用的一个指针地址,Assign是复制,A.picture.bitmap=B.picture.bitmap这样赋值二者才共用同一个指针地址,要权威的说明当然有:
    In general, the statement "Destination := Source" is not the same as the statement "Destination.Assign(Source)" The statement "Destination := Source" makes Destination reference the same object as Source, whereas "Destination.Assign(Source)" copies the contents of the object referenced by Source into the object referenced by Destination.
    Delphi的帮助,够权威吧?
      

  3.   

    首先,不是共用
    assign后相当于完全复制到另一个里面,这是基本原理,看看TPersistent的该方法
    不过基本上每个类自己都会重写(override)该方法,看看里面代码就知道
      

  4.   

    去看DELPHI的源码和帮助,如果说帮助还有错误,那么源码是最权威的了
    procedure TBitmap.Assign(Source: TPersistent);
    var
      DIB: TDIBSection;
    begin
      if (Source = nil) or (Source is TBitmap) then
      begin
        EnterCriticalSection(BitmapImageLock);
        try
          if Source <> nil then
          begin
            TBitmap(Source).FImage.Reference;
            FImage.Release;
            FImage := TBitmap(Source).FImage;
            FTransparent := TBitmap(Source).FTransparent;
            FTransparentColor := TBitmap(Source).FTransparentColor;
            FTransparentMode := TBitmap(Source).FTransparentMode;
          end
          else
          begin
            FillChar(DIB, Sizeof(DIB), 0);
            NewImage(0, 0, DIB, False);
          end;
        finally
          LeaveCriticalSection(BitmapImageLock);
        end;
        PaletteModified := Palette <> 0;
        Changed(Self);
      end
      else inherited Assign(Source);
    end;procedure TPersistent.Assign(Source: TPersistent);
    begin
      if Source <> nil then Source.AssignTo(Self) else AssignError(nil);
    end;procedure TPersistent.AssignTo(Dest: TPersistent);
    begin
      Dest.AssignError(Self);
    end;procedure TPersistent.AssignError(Source: TPersistent);
    var
      SourceName: string;
    begin
      if Source <> nil then
        SourceName := Source.ClassName else
        SourceName := 'nil';
      raise EConvertError.CreateResFmt(@SAssignError, [SourceName, ClassName]);
    end;
      

  5.   

    TPersistent类才有assign函数,但是TPersistent类并没有真正实现此方法,它的子类都重写了此方法,来实现复制一个对象的功能,复制出来的结果和源是两个不同的对象.