LAzarus и TypeInfo - не получается получить все свойства.

Вопросы программирования и использования среды Lazarus.

Модератор: Модераторы

Ответить
CynicRus
постоялец
Сообщения: 106
Зарегистрирован: 28.06.2012 14:31:11

LAzarus и TypeInfo - не получается получить все свойства.

Сообщение CynicRus »

Приветствую уважаемых форумчан. Возникла проблема при работе с TypInfo, наваял функцию получения свойств компонента:

Код: Выделить всё

 Procedure GetProperties( Kinds: TTypeKinds; Source: TPersistent; List: TStrings);
 var
   pList: PPropList;
   Total, Props, i: Integer;
 begin
   Total := GetTypeData(Source.ClassInfo).PropCount;
   GetMem(pList, sizeof(PPropInfo) * Total);
   try
    Props := GetPropList( Source.ClassInfo, Kinds, pList );
      for i := 0 to Props-1 do
        begin
          List.AddObject(pList[i].Name, TObject(pList[i]) );
        end;
  finally
    FreeMem(pList, sizeof(PPropInfo) * Total);
  end;
 end;           

Затем использую -

Код: Выделить всё

PropList:=TStringList.Create;
  curitem:=TPersistent(Sender);
  GetProperties([tkInteger,tkString, tkChar, tkEnumeration, tkFloat,
     tkSet, tkWChar, tkLString,tkUString,tkUChar, tkWString,
    tkVariant, tkArray, tkInt64 ],curitem, PropList);
  PropList.SaveToFile('C:/test.txt');         

Смотрю вывод, а там только часть свойств компонента:

Код: Выделить всё

Align
AlphaBlendValue
Anchors
BiDiMode
BorderIcons
BorderStyle
BorderWidth
ClientHeight
ClientWidth
Color
Cursor
DefaultMonitor
DragKind
DragMode
FormStyle
Height
HelpContext
HelpType
Left
PixelsPerInch
PopupMode
Position
ShowInTaskBar
Tag
Top
Width
WindowState
вместо всех свойств...В чем может быть проблема?
Аватара пользователя
B4rr4cuda
энтузиаст
Сообщения: 693
Зарегистрирован: 28.12.2007 06:48:35

Сообщение B4rr4cuda »

Попробуйте воспользоваться классом TPropInfoList.
CynicRus
постоялец
Сообщения: 106
Зарегистрирован: 28.06.2012 14:31:11

Сообщение CynicRus »

Попробовал.

Код: Выделить всё

Procedure GetProperties( Kinds: TTypeKinds; Source: TObject; List: TStrings);
 var
   pList: PPropList;
   pInfo: TPropInfoList;
   Total, Props, i: Integer;
 begin
   PInfo:=TPropInfoList.Create(Source,Kinds);
  // Total := GetTypeData(Source.ClassInfo).PropCount;
//   GetMem(pList, sizeof(PPropInfo) * Total);
   try
   // Props := GetPropList( Source.ClassInfo, Kinds, pList );
     Props:=pInfo.Count;
      for i := 0 to Props-1 do
        begin
          //List.AddObject(pList[i].Name, TObject(pList[i]) );
            List.AddObject(Pinfo.Items[i].Name, TObject(Pinfo.Items[i]));
        end;
  finally
 //   FreeMem(pList, sizeof(PPropInfo) * Total);
pInfo.free;
  end;
 end;         
- результат аналогичен предыдущему-(

Добавлено спустя 9 часов 39 минут 55 секунд:
Re: LAzarus и TypeInfo - не получается получить все свойства.
tkProperties - вот решение моей проблемы-)
Ответить