Ir al contenido


Foto

[TRUCO DELPHI] Listar todas las Propiedades y Eventos de un Componente.


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 sir.dev.a.lot

sir.dev.a.lot

    Advanced Member

  • Miembros
  • PipPipPip
  • 545 mensajes
  • Location127.0.0.1

Escrito 26 agosto 2016 - 08:35

[TRUCO DELPHI] Listar todas las Propiedades y Eventos de un Componente.

 

Hay que adicionar esta unidad


delphi
  1. uses TypInfo;


delphi
  1. procedure ListComponentProperties(Component: TComponent; Strings: TStrings);
  2. var
  3. Count, Size, I: Integer;
  4. List: PPropList;
  5. PropInfo: PPropInfo;
  6. PropOrEvent, PropValue: string;
  7. begin
  8. Count := GetPropList(Component.ClassInfo, tkAny, nil);
  9. Size := Count * SizeOf(Pointer);
  10. GetMem(List, Size);
  11. try
  12. Count := GetPropList(Component.ClassInfo, tkAny, List);
  13. for I := 0 to Count - 1 do
  14. begin
  15. PropInfo := List^[I];
  16. if PropInfo^.PropType^.Kind in tkMethods then
  17. PropOrEvent := 'Evento'
  18. else
  19. PropOrEvent := 'Propiedad';
  20. PropValue := VarToStr(GetPropValue(Component, PropInfo^.Name));
  21. Strings.Add(Format('[%s] %s: %s = %s', [PropOrEvent, PropInfo^.Name,
  22. PropInfo^.PropType^.Name, PropValue]));
  23. end;
  24. finally
  25. FreeMem(List);
  26. end;
  27. end;

Ejemplo de uso:


delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3. ListComponentProperties(Button1, ListBox1.Items);
  4. end;

Saludos!


  • 1




IP.Board spam blocked by CleanTalk.