小弟在学习Delphi的过程中,有一个问题总是分得不是很清楚,
同样是赋值方法:A:=Assign(B) 和 A:=B ,两者之间有什么区别,
什么情况下用Assign,什么情况下直接用A:=B呢?
请大虾赐教!

解决方案 »

  1.   

    好像没有A:=Assign(B)的用法吧
    Procedure Assign(Source : TPersistent) : Override 
    此方法是把某一类的属性等copy给另一类
    一般都这么使用Series1.Assign( Series2 ) ;而A:=B不就是相同类型的直接赋值吗?
      

  2.   

    Applies to TChart, TDBChart componentsDeclarationProcedure Assign(Source : TPersistent) : Override DescriptionThe Assign method copies all properties from a Series component to another.Only the common properties shared by both source and destination Series are copied.The following code copies all properties from Series2 into Series1:Series1.Assign( Series2 ) ;Some Series types restore property values after assigning them. For example, TPointSeriesrestores the Pointer.Visible property to True after being assigned to a TLineSeries, which hasPointers invisible by default.Note: Series events are not assigned. Series DataSource and FunctionType properties areassigned. Assign is used by CloneChartSeries and ChangeSeriesType methods for example.Assign method exampleThis code uses a button to copy a series from one chart to another.procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    CopySeries(DBChart2,DBChart1, self);
    BitBtn1.Visible:=False;
    end;
    type TChartClass=class of TChart;
    Procedure TForm1.CopySeries(DestChart,SourceChart:TChart; AOwner:TComponent);
    Var tmpSeries:TChartSeries;
      tmpS:TChartSeriesClass;
      t:Longint;
    begin
     for t:=0 to SourceChart.SeriesCount-1 do
     begin
      tmpS:=TChartSeriesClass(SourceChart.Series[t].ClassType);
      tmpSeries:=tmpS.Create(AOwner);
      tmpSeries.Assign(SourceChart.Series[t]);  tmpSeries.Name:=(SourceChart.Series[t].Name) + 'copy';
      DestChart.AddSeries(tmpSeries);
     end;
    end;
      

  3.   

    a:=b;意味着a是b的引用,即,二者是同一对象。
    a.assign(b);其中a是一个独立的对象,但其状态与b相同。
    assign方法可以将对象属性进行深层复制。同样的方法还有assign to.