[fpc-pascal] Clone a instance of object

Zaher Dirkey parmaja at gmail.com
Mon Sep 23 15:37:18 CEST 2013


On Mon, Sep 23, 2013 at 4:28 PM, Zaher Dirkey <parmaja at gmail.com> wrote:

> ​The idea is simply than needs to use a stream or RTTI, it is like a
> record, if looked at an object like as a record but it is inheritable.
> ​Compile can now every object body, and do the assigning as record assign.
>> That's the feature I like to have. ​
>
> Best Regards


​This is a funny example about what in my mind about what I talk (I know it
is stupid and unsafe)
If you look it is only for the class that not yet inherited yet, and work
only for the top class, but the compiler can guss all inheited/derived
classes and make the same assign.
If some understand it, maybe give more explain.
​-----------------------------------------------------
type
  TmyRec = record
    s: string;
    i: integer;
  end;
  PmyRec=^TmyRec;

  TmyObj = class(TObject)
    s: string;
    i: integer;
  end;


procedure TForm1.Button1Click(Sender: TObject);
var
  o1, o2: TmyObj;
begin
  o1 := TmyObj.Create;
  o2 := TmyObj.Create;
  o1.s := 'test1';
  o1.i := 122;
  PmyRec(@o2)^ := PmyRec(@o1)^;
  WriteLn(o2.s);
  WriteLn(o2.i);
end;
​-----------------------------------------------------​

Best Regards
Zaher Dirkey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130923/bda4bc1c/attachment.html>


More information about the fpc-pascal mailing list