Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Los mejores trucos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-06-2006
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.233
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Mostrar las propiedades de un componente en runtime

Podemos listar todas las propiedades published de un componente utilizando RTTI. Para ver el funcionamiento podemos crear un formulario con un componente TMemo y un Botón.

El procedimieno que utilizamos para obtener las propiedades es el siguiente:

Código Delphi [-]
//: Lista las propiedades/eventos de un componente.
procedure ListComponentProperties(Componente:TComponent; Strings: TStrings);
var
 Count, Size, j: Integer;
 lista: PPropList;
 PropInfo: PPropInfo;
 PropOrEvent, PropValue: String;
begin
 // Obtener el número de props. -- Number of props.
 Count := GetPropList(Componente.ClassInfo, tkAny, nil);
 Size := Count * SizeOf(Pointer);
 // reservar memoria
 GetMem(lista, Size);
 // Bloque de proteccion -- protection block
 try
   Count := GetPropList(Componente.ClassInfo, tkAny, lista);
   // recorrer la lista de prop.
   for j := 0 to Count - 1 do begin
     PropInfo := lista^[j];
     // Tipo?
     if (PropInfo^.PropType^.Kind in tkMethods) then begin
       PropOrEvent := 'Event'
     end
     else begin
       PropOrEvent := 'Property';
     end;
     // Obtener el valor de la propiedad -- Get the prop. value
     PropValue := VarToStr(GetPropValue(Componente, PropInfo^.Name));
     // Añadirla a la lista
     Strings.Add(Format('[%s] Nombre:%s     Tipo:%s     Valor:%s',
       [PropOrEvent, PropInfo^.Name, PropInfo^.PropType^.Name, PropValue]));
   end;
 finally
   FreeMem(lista);
 end;
end;

Para utilizarlo podemos usar el siguiente código:

Código Delphi [-]
   Memo1.Lines.BeginUpdate;
   Memo1.Lines.Clear;
   ListComponentProperties(Button1, Memo1.Lines);
   Memo1.Lines.EndUpdate;

Se debe añadir la Unit TypInfo al USES.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 04:13:22.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi