Einzelnen Beitrag anzeigen

barf00s
(Gast)

n/a Beiträge
 
#4

Re: Object teilweise kopieren

  Alt 2. Jun 2005, 09:55
Delphi-Quellcode:
type
  ICloneable = interface
    function Clone: TObject;
  end;

type
  TDeineKlasse = class(TInterfacedObject, ICloneable)
  private
    FInteger: integer;
    FString: string;
    FDouble: double;
  public
    function Clone: TObject;
    property AsInteger: integer read FInteger write FInteger;
    property AsString: string read FString write FString;
    property AsDouble: double read FDouble write FDouble;
  end;

function TDeineKlasse.Clone: TObject;
begin
  Result := TDeineKlasse.Create;
  with TDeineKlasse(Result) do begin
    AsInteger := Self.AsInteger; // oder Self.FInteger;
    AsString := Self.AsString;
    AsDouble := Self.AsDouble;
  end;
end;

... so würd ichs machen

var
  xClone: TDeineKlasse;

begin
  xClone := TDeineKlasse(deineOriginalKlasse.Clone);
end;
öhm ja
  Mit Zitat antworten Zitat