Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Auflisten von Sub-Eigenschaften einer Komponente

  Alt 31. Aug 2017, 12:11
Delphi-Quellcode:
procedure ListComponentProperties(ATypeInfo: PTypeInfo; Strings: TStrings); overload;
var
  Count, I: Integer;
  List: PPropList;
  PropInfo: PPropInfo;
  PropOrEvent: string;
begin
  List := nil;
  Count := GetPropList(ATypeInfo, List);
  try
    for I := 0 to Count - 1 do
    begin
      PropInfo := List^[I];
      case PropInfo.PropType^.Kind of
        TTypeKind.tkMethod:
          PropOrEvent := 'Event';
        TTypeKind.tkClass:
          begin
            ListComponentProperties(PropInfo.PropType^, Strings)
          end;
      else
        PropOrEvent := 'Property';
      end;
// PropValue := VarToStr(GetPropValue(Component, PropInfo^.Name)); <--- hier noch Gehirnschmalz reinstecken, da ja die Instanz fehlt

      Strings.Add('- - -' + Format('[%s] %s: %s = %s', [PropOrEvent, PropInfo^.Name, PropInfo^.PropType^.Name, '']));
    end;
  finally
    FreeMem(List);
  end;
end;

procedure ListComponentProperties(Component: TObject; Strings: TStrings); overload;
var
  Count, Size, I: Integer;
  List: PPropList;
  PropInfo: PPropInfo;
  PropOrEvent, PropValue: string;
begin
  List := nil;
  Count := GetPropList(Component, List);
  try
    for I := 0 to Count - 1 do
    begin
      PropInfo := List^[I];
      case PropInfo.PropType^.Kind of
        TTypeKind.tkMethod:
          PropOrEvent := 'Event';
        TTypeKind.tkClass:
          begin
            ListComponentProperties(PropInfo.PropType^, Strings)
          end;
      else
        PropOrEvent := 'Property';
      end;

      PropValue := VarToStr(GetPropValue(Component, PropInfo^.Name));

      Strings.Add(Format('[%s] %s: %s = %s', [PropOrEvent, PropInfo^.Name, PropInfo^.PropType^.Name, PropValue]));
    end;
  finally
    FreeMem(List);
  end;
end;
  Mit Zitat antworten Zitat