AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Überprüfung ob Objekt eine generische Liste ist
Thema durchsuchen
Ansicht
Themen-Optionen

Überprüfung ob Objekt eine generische Liste ist

Ein Thema von Neutral General · begonnen am 16. Apr 2010 · letzter Beitrag vom 3. Jan 2011
 
Benutzerbild von stahli
stahli

Registriert seit: 26. Nov 2003
Ort: Halle/Saale
4.358 Beiträge
 
Delphi 11 Alexandria
 
#18

AW: Überprüfung ob Objekt eine generische Liste ist

  Alt 3. Jan 2011, 21:34
Folgende Eigenschaften und Felder konnte ich ermitteln:
Code:
=> Todl<odNumerator.TodNumerator>:
 
  *****PROP*****
  Items
  Items: TObjectList<odNumerator.TodNumerator>
   
    *****PROP*****
    OwnsObjects
    Capacity
    Count
    OnNotify
   
    *****VAR*****
    FOwnsObjects
    FItems
    FCount
    FComparer
    FOnNotify
   
  odName
  odClass
  odId
  odCT
  ComponentCount
  ComponentIndex
  ComponentState
  ComponentStyle
  DesignInfo
  VCLComObject
  Name
  Tag
 
  *****VAR*****
  FItems
  FItems: TObjectList<odNumerator.TodNumerator>
  FodName
  FodClass
  FodId
  FodCT
  FOwner
  FName
  FTag
  FComponents
  FFreeNotifies
  FFreeNotifies: TList
  FDesignInfo
  FComponentState
  FVCLComObject
  FComponentStyle
  FSortedComponents
Ich habe jetzt keine Idee, wie ich an die einzelnen Items heran komme und werde in dem Fall doch auf Generics verzichten.
Vielleicht könnte man auf eine Funktion zugreifen, aber das wird mir dann zu kompliziert.

Falls jemand damit herumspielen möchte, hier meine Funktion (schnell gestrickt und etwas unsauber):
Delphi-Quellcode:
function TodProp.GetProps(O: TObject; Deep: Integer): String;
var
  Context: TRttiContext;
  RttiType: TRttiType;
  PropInfo: TRttiProperty;
  FieldInfo: TRttiField;
  Attr: TCustomAttribute;
  Value: TValue;
  SO: TObject;

  procedure Write(S: String);
  begin
    S := DeepString(Deep) + S;
    Result := Result + S + #13#10;
    OutputDebugString(PChar(S));
  end;
  
begin
  Result := '';
  if (not Assigned(O)) then
    Exit;

  if Deep = 0 then
    Write('=> ' + O.ClassName + ':');
  Inc(Deep);

  Write('');
  Write('*****PROP*****');

  Context := TRttiContext.Create;
  RttiType := Context.GetType(O.ClassType);

  if Assigned(RttiType) then
  begin
    for PropInfo in RttiType.GetProperties do
    begin
      if PropInfo.Name = 'ComObjectthen
        Continue;
      if PropInfo.Name = 'Ownerthen
        Continue;
      if PropInfo.Name = 'Parentthen
        Continue;
      if PropInfo.Name = 'Sportthen
      begin
        Beep;
      end;
      Write(PropInfo.Name);
      case PropInfo.PropertyType.TypeKind of
        tkClass:
          begin
            Value := PropInfo.GetValue(O);
            if (not Value.IsEmpty) then
            begin
              SO := Value.AsObject;
              if (Assigned(SO)) and ((not(SO is TComponent)) or ((SO as TComponent).Owner = O)) then
              begin
                Write(PropInfo.Name + ': ' + SO.ClassName);
                Result := Result + GetProps(SO, Deep);
              end;
            end;
          end;
      end;
    end;
  end;

  Write('');
  Write('*****VAR*****');

  Context := TRttiContext.Create;
  RttiType := Context.GetType(O.ClassType);

  if Assigned(RttiType) then
  begin
    for FieldInfo in RttiType.GetFields do
    begin
      if FieldInfo.Name = 'ComObjectthen
        Continue;
      if FieldInfo.Name = 'Ownerthen
        Continue;
      if FieldInfo.Name = 'Parentthen
        Continue;
      if FieldInfo.Name = 'Sportthen
      begin
        Beep;
      end;
      Write(FieldInfo.Name);
      case FieldInfo.FieldType.TypeKind of
        tkClass:
          begin
            Value := FieldInfo.GetValue(O);
            if (not Value.IsEmpty) then
            begin
              SO := Value.AsObject;
              if (Assigned(SO)) and ((not(SO is TComponent)) or ((SO as TComponent).Owner = O)) then
              begin
                Write(FieldInfo.Name + ': ' + SO.ClassName);
// Result := Result + GetFields(SO, Deep);
              end;
            end;
          end;
      end;
    end;
  end;

  Write('');
  Dec(Deep);
  
  Context.Free;
end;
Stahli
http://www.StahliSoft.de
---
"Jetzt muss ich seh´n, dass ich kein Denkfehler mach...!?" Dittsche (2004)
  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 12:35 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-2025 by Thomas Breitkreuz