Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>have a read of this page</p> <p><a href="http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm" rel="nofollow noreferrer"><strong>Run-Time Type Information In Delphi - Can It Do Anything For You?</strong></a></p> <p>Noting the section <a href="http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm#CopyingPropertiesFromAComponentToAnother" rel="nofollow noreferrer">Copying Properties From A Component To Another</a></p> <p>which has a unit, RTTIUnit with a Procedure, which seems to do part of what you want but i don't think it will copy any child components with out extra code. <em>(i think its ok to paste it here...)</em></p> <pre><code>procedure CopyObject(ObjFrom, ObjTo: TObject); var PropInfos: PPropList; PropInfo: PPropInfo; Count, Loop: Integer; OrdVal: Longint; StrVal: String; FloatVal: Extended; MethodVal: TMethod; begin //{ Iterate thru all published fields and properties of source } //{ copying them to target } //{ Find out how many properties we'll be considering } Count := GetPropList(ObjFrom.ClassInfo, tkAny, nil); //{ Allocate memory to hold their RTTI data } GetMem(PropInfos, Count * SizeOf(PPropInfo)); try //{ Get hold of the property list in our new buffer } GetPropList(ObjFrom.ClassInfo, tkAny, PropInfos); //{ Loop through all the selected properties } for Loop := 0 to Count - 1 do begin PropInfo := GetPropInfo(ObjTo.ClassInfo, PropInfos^[Loop]^.Name); // { Check the general type of the property } //{ and read/write it in an appropriate way } case PropInfos^[Loop]^.PropType^.Kind of tkInteger, tkChar, tkEnumeration, tkSet, tkClass{$ifdef Win32}, tkWChar{$endif}: begin OrdVal := GetOrdProp(ObjFrom, PropInfos^[Loop]); if Assigned(PropInfo) then SetOrdProp(ObjTo, PropInfo, OrdVal); end; tkFloat: begin FloatVal := GetFloatProp(ObjFrom, PropInfos^[Loop]); if Assigned(PropInfo) then SetFloatProp(ObjTo, PropInfo, FloatVal); end; {$ifndef DelphiLessThan3} tkWString, {$endif} {$ifdef Win32} tkLString, {$endif} tkString: begin { Avoid copying 'Name' - components must have unique names } if UpperCase(PropInfos^[Loop]^.Name) = 'NAME' then Continue; StrVal := GetStrProp(ObjFrom, PropInfos^[Loop]); if Assigned(PropInfo) then SetStrProp(ObjTo, PropInfo, StrVal); end; tkMethod: begin MethodVal := GetMethodProp(ObjFrom, PropInfos^[Loop]); if Assigned(PropInfo) then SetMethodProp(ObjTo, PropInfo, MethodVal); end end end finally FreeMem(PropInfos, Count * SizeOf(PPropInfo)); end; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload