Конференция "Компоненты" » Сохранение в DFM свойств дочерних компонентов
 
  • TheEd (08.09.11 20:36) [0]
    В двух словах: захотел скомпоновать ряд свойств под общим именем в компоненте который пишу. Получилось примерно это (привожу самое главное):

    unit ButtonPanel;
    ...
    type

     TButtonPanel = class;
     TShifts = class(TPersistent) // класс для хранения группы свойств
     private
       FCaptionDX: integer;
       FCaptionDY: integer;
       FAOwner : TButtonPanel;
       procedure SetCaptionDX(const Value: integer);
       procedure SetCaptionDY(const Value: integer);
     public
       constructor Create(AOwner: TButtonPanel);
       destructor Destroy; override;
       procedure Assign(Source: TPersistent); override;
     published
       property CaptionDX : integer read FCaptionDX write SetCaptionDX;
       property CaptionDY : integer read FCaptionDY write SetCaptionDY;
     end;

     TButtonPanel = class(TPanel)
       ...
     public
       constructor Create(AOwner: TComponent); override;
       destructor Destroy; override;
     protected
       procedure Paint; override; // там будем отрисовывать панельку с учётом смещений
     published
       property Shifts : TShifts read FShifts;
     end;

    procedure Register;

    implementation
    ...

    procedure Register;
    begin
     RegisterComponents('Ed', [TButtonPanel]);
    end;

    constructor TButtonPanel.Create(AOwner: TComponent);
    begin
     inherited;
     FShifts := TShifts.Create(self);
       ...
    end;

    destructor TButtonPanel.Destroy;
    begin
       ...
     FShifts.Free;
     inherited;
    end;

     ...

    procedure TShifts.Assign(Source: TPersistent);
    begin
     inherited Assign(Source);
     if Source is TShifts then
     begin
       FCaptionDX := TShifts(Source).CaptionDX;
       FCaptionDY := TShifts(Source).CaptionDY;
     end;
    end;

    constructor TShifts.Create(AOwner: TButtonPanel);
    begin
     FAOwner := AOwner;
     FCaptionDX := 0;
     FCaptionDY := 0;
    end;

    destructor TShifts.Destroy;
    begin
     inherited;
    end;

    procedure TShifts.SetCaptionDX(const Value: integer);
    begin
     FCaptionDX := Value;
     FAOwner.Invalidate;
    end;

    procedure TShifts.SetCaptionDY(const Value: integer);
    begin
     FCaptionDY := Value;
     FAOwner.Invalidate;
    end;

    end.


    Чего-то не сохраняет CaptionDX и CaptionDY в DFM-файл :(
    Пробовал и
       property CaptionDX : integer read FCaptionDX write SetCaptionDX stored true;
       property CaptionDY : integer read FCaptionDY write SetCaptionDY stored true;


    и
       property CaptionDX : integer read FCaptionDX write SetCaptionDX nodefault;
       property CaptionDY : integer read FCaptionDY write SetCaptionDY nodefault;

    ,
    не помогает.
    Помогите плиз!
  • DimaBr © (08.09.11 23:42) [1]
    Не сохраняет поскольку у вас свойство Shifts - ReadOnle
    property Shifts : TShifts read FShifts write SetShifts;

    procedure SetShifts;
    begin
     FShifts.Assign(Value);
    end;

  • TheEd (09.09.11 02:30) [2]
    Спасибо, помогло!
 
Конференция "Компоненты" » Сохранение в DFM свойств дочерних компонентов
Есть новые Нет новых   [118477   +39][b:0][p:0.002]