1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87:
| procedure CloneAttributes(master, addicted: TObject; newName: String = ''); var count, size: Integer; propList: PPropList; i: Integer;
masterObj: TObject; addictedObj: TObject; compName: String; compIdx: Integer;
const kinds: TTypeKinds = [tkInteger, tkChar, tkEnumeration, tkFloat, tkString, tkSet, tkClass, tkMethod, tkWChar, tkLString, tkWString, tkInt64]; begin if not (master = nil) and not (addicted = nil) then begin if master.ClassType = addicted.ClassType then begin count := GetPropList(master.ClassInfo, kinds, nil); size := count * SizeOf(Pointer); GetMem(propList, size); GetPropList(master.ClassInfo, kinds, propList); for i:=0 to count-1 do begin if IsPublishedProp(master, PropList[i].Name) then begin try case PropList[i].PropType^.Kind of tkString, tkLString, tkWString: begin try SetStrProp(addicted, PropList[i].Name, GetStrProp(master, PropList[i].Name)); except on EComponentError do begin if LowerCase(PropList[i].Name) = 'name' then begin compName := newName; compIdx := 0; if compName = '' then begin compName := GetStrProp(master, PropList[i].Name); compIdx := 1; end; while True do begin try if compIdx = 0 then SetStrProp(addicted, PropList[i].Name, compName) else SetStrProp(addicted, PropList[i].Name, compName+IntToStr(compIdx)); Break; except inc(compIdx); end; end; end; end; end; end; tkEnumeration: begin SetEnumProp(addicted, PropList[i].Name, GetEnumProp(master, PropList[i].Name)); end; tkInteger, tkChar, tkWChar, tkSet: begin SetOrdProp(addicted, PropList[i].Name, GetOrdProp(master, PropList[i]. Name)); end; tkFloat: begin SetFloatProp(addicted, PropList[i].Name, GetFloatProp(master, PropList[i].Name)); end; tkInt64: begin SetInt64Prop(addicted, PropList[i].Name, GetInt64Prop(master, PropList[i].Name)); end; tkMethod: begin SetMethodProp(addicted, PropList[i], GetMethodProp(master, PropList[i].Name)) end; tkClass: begin masterObj := GetObjectProp(master, PropList[i].Name); addictedObj := GetObjectProp(addicted, PropList[i].Name); if addictedObj = nil then begin SetObjectProp(addicted, PropList[i].Name, masterObj); end else begin CloneAttributes(masterObj, addictedObj); end; end; end; except end; end; end; FreeMem(propList, size); end; end; end; |