Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.167 Beiträge
 
Delphi 12 Athens
 
#16

Re: Mehrere Steuerelemente mit der gleichen "Identität&

  Alt 16. Jul 2009, 15:06
Eigentlich dachte ich, daß dann jeder Frame für sich alleine steht und nur das Gleiche vorm Erstellen der Instanz auch gleich ist


Delphi-Quellcode:
Procedure CloneObject(O, O2: TObject; Const Ignore: Array of String);
  Var List: PPropList;
    i, i2: Integer;

  Begin
    i2 := GetPropList(O.ClassInfo, List);
    If i2 > 0 Then
      Try
        For i := 0 to i2 - 1 do
          If IsStoredProp(O, List[i].Name) and not MatchText(List[i].Name, Ignore) Then
            Case List[i].PropType^.Kind of
              tkInteger, tkEnumeration, tkChar, tkWChar:
                         SetOrdProp (O2, List[i].Name, GetOrdProp (O, List[i].Name));
              tkInt64: SetInt64Prop (O2, List[i].Name, GetInt64Prop (O, List[i].Name));
              tkSet: SetSetProp (O2, List[i].Name, GetSetProp (O, List[i].Name));
              tkFloat: SetFloatProp (O2, List[i].Name, GetFloatProp (O, List[i].Name));
              tkLString: SetAnsiStrProp (O2, List[i].Name, GetAnsiStrProp (O, List[i].Name));
              tkWString: SetWideStrProp (O2, List[i].Name, GetWideStrProp (O, List[i].Name));
              {$IF Declared(UnicodeString)}
              tkString, tkUString:
                         SetUnicodeStrProp(O2, List[i].Name, GetUnicodeStrProp(O, List[i].Name));
              {$ELSE}
              tkString: SetAnsiStrProp (O2, List[i].Name, GetAnsiStrProp (O, List[i].Name));
              {$IFEND}
              tkClass: If MatchText(List[i].Name, ['CustomHint', 'Action', 'DropDownMenu', 'Images', 'PopupMenu']) Then
                           SetObjectProp (O2, List[i].Name, GetObjectProp (O, List[i].Name))
                         Else If (GetObjectProp(O, List[i].Name) is TPersistent) and ( GetObjectProp(O2, List[i].Name) is TPersistent) Then
                           TPersistent(GetObjectProp(O2, List[i].Name)).Assign(GetObjectProp(O, List[i].Name) as TPersistent);
              tkMethod: SetMethodProp (O2, List[i].Name, GetMethodProp (O, List[i].Name));
              tkVariant: SetVariantProp (O2, List[i].Name, GetVariantProp (O, List[i].Name));
              Else Raise Exception.Create('Propertytyp wird nicht unterstützt');
            End;
      Finally
        FreeMem(List);
      End;
  End;
und das Ganze nun nur noch für jeden Button aufrufen
Delphi-Quellcode:
CloneObject(Button1, Button2, ['Name', 'Parent', 'Left']);
CloneObject(Button1, Button3, ['Name', 'Parent', 'Left']);
CloneObject(Button1, Button4, ['Name', 'Parent', 'Left']);
Button2 bis Button4 erben nun "alle" Eigenschaften von Button1

wenn du nun die Buttons alle in einer Liste hast, oder diese über die Form suchst, dann kannst'e diese Funktion auch in einer Schleife aufrufen
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat