![]() |
TPagecontrol klonen - irgendwie unsichtbar
Liste der Anhänge anzeigen (Anzahl: 1)
:hi:
Versuche gerade, ein TPagecontrol (2 TTabsheets + Controls darauf) zu klonen. Das Klonen funktioniert soweit, nur die Controls auf den TTabsheets sind nicht sichtbar.. Habe schon versucht, die geklonten Controls sichtbar zu machen (visible = True). Bringt aber nichts. Auch liegen die Controls IMO innerhalb des sichtbaren Bereichs...Was läuft hier falsch? Anbei ein Demoprojekt zum selber nachvollziehen. Nachtrag: Selbt wenn ich nach dem Klonen z.B einen TButton auf eines der neu erstellten TTabsheets setze, wird es nicht angezeigt... Codeauszug:
Delphi-Quellcode:
function CloneComponent(Source: TComponent;
aInstance: TComponent = nil; aOwner: TComponent = nil; aParent: TWinControl = nil; Options: TCloneOptions = []): TComponent; const Index: Integer = 0; // static, needs $J+ state var I: Integer; OrgName: string; Stream: TMemoryStream; begin Result := nil; if not Assigned(Source) then Exit; // Create new instance when needed (or just use the one given). if aInstance = nil then begin if aOwner = nil then aOwner := Source.Owner; Result := TComponentClass(Source.ClassType).Create(aOwner) end else if aInstance.ClassType = Source.ClassType then Result := aInstance else raise Exception.Create('<aInstance> = ' + aInstance.ClassName + ' is not the same component class as' + ' <Source> = ' + Source.ClassName); // Although registering of normal classes shouldn't be neccessary // it is required for some of the children like TToolButton, etc. if Source is TWinControl then with TWinControl(Source) do for I := 0 to ControlCount - 1 do begin try RegisterClass(TPersistentClass(Controls[I].ClassType)); except end; end; try // Use new parent when one was given, otherwise use the one from <Source>. if Source is TControl then with TControl(Result) do if aParent <> nil then Parent := aParent else Parent := TControl(Source).Parent; // Clone published properties. OrgName := Source.Name; Stream := TMemoryStream.Create; try Source.Name := 'CloneComponent' + IntToStr(Index) + OrgName; Stream.WriteComponent(Source); Source.Name := OrgName; Stream.Position := 0; Result := Stream.ReadComponent(Result); finally Stream.Free; end; // Try to set caption/text when <Source> is a control // to the same caption/text as that of the <Source> control. if Source is TControl then if IsPublishedProp(Result, 'Caption') or IsPublishedProp(Result, 'Text') then with TControlCracker(Result) do if (csSetCaption in ControlStyle) and (Name = Text) then Text := OrgName; except // If something went wrong only free the clone // when it was created by this function. if aInstance = nil then Result.Free; raise; end; // Clone all Children to the new instance as well? if (coIncludeChildren in Options) and (Source is TWinControl) then with TWinControl(Source) do for I := 0 to ControlCount - 1 do if Controls[I].ClassName <> 'TToolButton' then CloneComponent(Controls[I], nil, nil, TWinControl(Result), Options); if Index < MAXINT then Inc(Index) else Index := 0; end; |
Re: TPagecontrol klonen
Hallo,
nicht dass ich mich mit diesem Problem eingehend beschäftigt hätte, aber eine allgemeine Lösung scheint das trotz des Aufwandes nicht zu sein. WriteComponent() und ReadComponent() verarbeiten grundsätzlich auch child components - unabhängig von der Option coIncludeChildren. Und mit dem PageControl (und einigen anderen Komponenten) dürfte es auf jeden Fall ein Problem geben, wenn Tabsheets behandelt werden, als wären sie mit herkömmlichen Komponenten (TButton, TEdit, etc.) vergleichbar. Der original author ist wohl selbst nicht von der Universalität seines Codes überzeugt gewesen - siehe TToolButton. Grüße vom marabu |
Re: TPagecontrol klonen
Dann müsste ich wohl die Tabsheets einzeln klonen.
D.h ein neues Pagecontrol mit den Tabsheets erstellen (per Create Methode) und dann die Controls einzeln klonen. |
Re: TPagecontrol klonen
Zitat:
Zitat:
auf den geklonten Tabsheets, nur irgendwie unsichtbar... Der Beweis (durch Auflistung aller Controls) Zitat:
|
Re: TPagecontrol klonen - irgendwie unsichtbar
*PUSH*
Hat sonst niemand eine Idee? habe ja extra ein Beispiel Projekt gemacht, welches nur 3 Personen heruntergeladen haben....;( |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:30 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz