clonar un objeto
Publicado por diego Gutierrez (15 intervenciones) el 21/09/2007 00:53:43
hola, estoy intentando clonar un objeto para un desarrollo algo loco, estuve leyendo eninternet y al parecer, la mejor forma es usar Memory Stream para cargar el objeto y luego escribirlo en otro nuevo, pero no lo logro conseguir, ya que siempre me marca stream read error, alguien tiene idea de que es lo que pasa, anexo un codigo ejemplo:
procedure TFrmTableroAlmacen.ChartDiasDeInventarioDblClick(Sender: TObject);
var
ms: TMemoryStream;
s: string;
p, temp: TPanel;
x,y: Integer;
caliz: TDBChart;
begin
ms := TMemoryStream.Create;
try
ms.WriteComponent(ChartDiasDeInventario);
caliz:=TDBChart(ms.ReadComponent(ChartDiasDeInventario)); ///aqui es donde me marca el error
ChartDiasDeInventario.Name:='ChartDiasDeInventarioOrigina';
temp := panel1;
s := panel1.Name;
panel1.Name := '';
try
ms.WriteComponent(temp);
ms.Position := 0;
p := TPanel.Create(Self);
ms.ReadComponent(p);
with p do
begin
x := panel1.Left;
y := panel1.Top;
Inc(x, 5);
Inc(y, 5);
SetBounds(x, y, Width, Height);
Parent := Self;
Name := Format('Panel%d_%d', [x, y]);
end;
finally
temp.Name := s;
panel1 := temp;
end
finally
ms.Free;
end; { finally }
end;
garcias por leer
procedure TFrmTableroAlmacen.ChartDiasDeInventarioDblClick(Sender: TObject);
var
ms: TMemoryStream;
s: string;
p, temp: TPanel;
x,y: Integer;
caliz: TDBChart;
begin
ms := TMemoryStream.Create;
try
ms.WriteComponent(ChartDiasDeInventario);
caliz:=TDBChart(ms.ReadComponent(ChartDiasDeInventario)); ///aqui es donde me marca el error
ChartDiasDeInventario.Name:='ChartDiasDeInventarioOrigina';
temp := panel1;
s := panel1.Name;
panel1.Name := '';
try
ms.WriteComponent(temp);
ms.Position := 0;
p := TPanel.Create(Self);
ms.ReadComponent(p);
with p do
begin
x := panel1.Left;
y := panel1.Top;
Inc(x, 5);
Inc(y, 5);
SetBounds(x, y, Width, Height);
Parent := Self;
Name := Format('Panel%d_%d', [x, y]);
end;
finally
temp.Name := s;
panel1 := temp;
end
finally
ms.Free;
end; { finally }
end;
garcias por leer
Valora esta pregunta


0