[TRUCO DELPHI] Listar todas las Propiedades y Eventos de un Componente.
Hay que adicionar esta unidad
delphi
uses TypInfo;
delphi
procedure ListComponentProperties(Component: TComponent; Strings: TStrings); var Count, Size, I: Integer; List: PPropList; PropInfo: PPropInfo; PropOrEvent, PropValue: string; begin Count := GetPropList(Component.ClassInfo, tkAny, nil); Size := Count * SizeOf(Pointer); GetMem(List, Size); try Count := GetPropList(Component.ClassInfo, tkAny, List); for I := 0 to Count - 1 do begin PropInfo := List^[I]; if PropInfo^.PropType^.Kind in tkMethods then PropOrEvent := 'Evento' else PropOrEvent := 'Propiedad'; 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;
Ejemplo de uso:
delphi
procedure TForm1.Button1Click(Sender: TObject); begin ListComponentProperties(Button1, ListBox1.Items); end;
Saludos!