如何复制一个对象 , 复制后的对象与源对象相互独立?Assign 方法怎么用?

解决方案 »

  1.   

    要自己写代码的,覆盖一个Assign方法的!
        procedure Assign(Source: TPersistent); override;
    procedure TFont.Assign(Source: TPersistent);
    begin
      if Source is TFont then
      begin
        Lock;
        try
          TFont(Source).Lock;
          try
            FontManager.AssignResource(Self, TFont(Source).FResource);
            Color := TFont(Source).Color;
            if PixelsPerInch <> TFont(Source).PixelsPerInch then
              Size := TFont(Source).Size;
          finally
            TFont(Source).Unlock;
          end;
        finally
          Unlock;
        end;
        Exit;
      end;
      inherited Assign(Source);
    end;
      

  2.   

    TPersistent中的是个需方法,没用的!
    这个方法必须字类继承的!