AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TPagecontrol klonen - irgendwie unsichtbar

Ein Thema von API · begonnen am 10. Sep 2006 · letzter Beitrag vom 12. Sep 2006
 
API

Registriert seit: 18. Apr 2004
637 Beiträge
 
#1

TPagecontrol klonen - irgendwie unsichtbar

  Alt 10. Sep 2006, 16:13


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 <> 'TToolButtonthen
          CloneComponent(Controls[I], nil, nil, TWinControl(Result), Options);

  if Index < MAXINT then Inc(Index) else Index := 0;
end;
Angehängte Dateien
Dateityp: zip clonetest_144.zip (4,0 KB, 10x aufgerufen)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:45 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