Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > Реализация SetParentComponent для десериализации


Автор: demonoide 26.11.2008, 12:59
Программа представляет собой набор список групп, в которых находятся пользователи.

Диаграмма классов:

TGroup List
|-->TUserList
---|-->TStruct

Т.е. список групп содержит -> списки юзеров -> которые содержат в себе структуру каждого юзера.

Вот так выглядят классы:

Код

type TGroupList = class (TComponent)

  private
    List: TObjectList;
    function GetItems(Index: Integer): TUserList;
    procedure SetItems(Index: Integer; const Value: TUserList);

  public
   function Count: Integer;
   procedure Add(Value: TUserList);
   procedure Clear;
   procedure Delete(I:Integer);

   constructor Create;
   destructor  Destroy; override;

   procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
   procedure SetParentComponent(Value: TComponent); override;

   property Items[Index:Integer]: TUserList read GetItems write SetItems;
  default;

  end;


Код

  type TUserList = class (TComponent)

  private
   Name: String;
   List: TObjectList;

   function GetTheName: String;
   procedure SetTheName(const Value: String);

   function GetItems(Index: Integer): TUserStruct;
   procedure SetItems(Index: Integer; const Value: TUserStruct);

  public
   property Items[Index:Integer]: TUserStruct read GetItems write SetItems;

   function Count: Integer;
   procedure Add(Value: TUserStruct);
   procedure Clear;
   procedure Delete(I:Integer);

   procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
   procedure SetParentComponent(Value: TComponent); override;


  constructor Create;
  destructor  Destroy; override;

  published
     property GroupName: String read GetTheName write SetTheName;

  end;


Код

 type
 TUserStruct = class (TComponent)
 private
  ThName:String;               

 protected
  procedure SetTheName(NewName: String);
  function GetTheName: String;

 public
   constructor Create;

 published
  property ItemName: String read GetTheName write SetTheName;
 end;


Сделать высокоуровневую сериализацию - получилось (http://www.rsdn.ru/article/delphi/serialization.xml), а с десериализацией - проблема, в душе не чаю как писать для моей реализации SetParentComponent(Value: TComponent); override;

Если можно приведите пример или дайте что почитать, ибо в Интернете мало чего нашёл по этому поводу. 

Автор: Felan 26.11.2008, 15:09
Никак. 

Делай вручную сохранение и восстановление.

Но, судя по тому, что ты написал, я подозреваю, что ты пытался использовать встроенную сериализацию...
Тогда тебе надо элементы наслеодовать от TCollectionItem, а вместо TObjectList использовать TCollection.

Тогда будетут автоматически сохраняться published свойства.


Автор: demonoide 26.11.2008, 16:55
Всё шикарно сохраняется при моей реализации, но не десериализуется.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)