IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants VCL Delphi Discussion :

[D2010] TCollection inclus dans un TPersistent lui même dans un composant


Sujet :

Composants VCL Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Inscrit en
    Juillet 2009
    Messages
    9
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 9
    Par défaut [D2010] TCollection inclus dans un TPersistent lui même dans un composant
    Bonjour,
    Je souhaite faire un composant dans ce genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    TMaCollection = class(TCollection)
      ...
    end;
     
    TMonPersistent = class(TPersistent)
    private
      FCollection: TMaCollection;
    published
      property Collection: TMaCollection read FCollection;
    end;
     
    TMonComposant = class(TCustomControl)
    private
      FPersistent: TMonPersistent;
    published
      property Persistent: TMonPersistent read FPersistent;
    end;
    Tout va bien sauf que la fenêtre de manipulation de la collection n'apparraît pas dans l'EDI. Je ne peux donc pas ajouter ou supprimer d'élément dans ma collection.

    Est ce que quelqu'un a une idée pour permettre de manipuler la collection incluse dans le persistent ?

    Merci

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2010
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2010
    Messages : 71
    Par défaut
    Salut,
    avec ce morceau de code pas facile de ce faire un avis sur les erreurs possibles...
    des pistes TCollection va souvent avec TCollectionItem, manipulation Items, SetItem, GetItem, GetOwner, Assign(Source:TPersitent)...
    Beaucoup de causes possibles en gros...
    @+

  3. #3
    Membre habitué
    Inscrit en
    Juillet 2009
    Messages
    9
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 9
    Par défaut
    Voilà mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    type
      TGridRow = class(TCollectionItem)
      private
        FTop: Integer;
        FHeight: Integer;
        FText: String;
      protected
        function GetBottom: Integer;
        function GetHeight: Integer;
        procedure SetHeight(const Value: Integer);
        function GetText: String;
        procedure SetText(const Value: String);
        function GetDisplayName: String; override;
      public
        constructor Create(ACollection: TCollection); override;
        destructor Destroy; override;
      published
        property Top: Integer read FTop;
        property Bottom: Integer read GetBottom;
        property Height: Integer read GetHeight write SetHeight;
        property Text: String read GetText write SetText;
      end;
     
      TGridRows = class(TOwnedCollection)
      private
        function GetItem(Index: Integer): TGridRow;
        procedure SetItem(Index: Integer; Value: TGridRow);
      protected
        procedure Update(Item: TCollectionItem); override;
      public
        constructor Create(AOwner: TPersistent);
        destructor Destroy; override;
        function Add: TGridRow;
        function AddItem(Item: TGridRow; Index: Integer): TGridRow;
        function Insert(Index: Integer): TGridRow;
        procedure Delete(Index: Integer);
        property Items[Index: Integer]: TGridRow read GetItem write SetItem; default;
      end;
     
      TGridColumn = class(TCollectionItem)
      private
        FLeft: Integer;
        FWidth: Integer;
        FText: String;
      protected
        function GetRight: Integer;
        function GetWidth: Integer;
        procedure SetWidth(const Value: Integer);
        function GetText: String;
        procedure SetText(const Value: String);
        function GetDisplayName: String; override;
      public
        constructor Create(ACollection: TCollection); override;
        destructor Destroy; override;
      published
        property Left: Integer read FLeft;
        property Right: Integer read GetRight;
        property Width: Integer read GetWidth write SetWidth;
        property Text: String read GetText write SetText;
      end;
     
      TGridColumns = class(TOwnedCollection)
      private
        function GetItem(Index: Integer): TGridColumn;
        procedure SetItem(Index: Integer; Value: TGridColumn);
      protected
        procedure Update(Item: TCollectionItem); override;
      public
        constructor Create(AOwner: TPersistent);
        destructor Destroy; override;
        function Add: TGridColumn;
        function AddItem(Item: TGridColumn; Index: Integer): TGridColumn;
        function Insert(Index: Integer): TGridColumn;
        procedure Delete(Index: Integer);
        property Items[Index: Integer]: TGridColumn read GetItem write SetItem; default;
      end;
     
      TGridCell = class(TObject)
      private
        FValue: String;
      public
        property Value: String read FValue write FValue;
      end;
     
      TGridCells = class(TObjectGrid<TGridCell>);
     
      TGridHeader = class(TPersistent)
      private
        FOwner: TComponent;
        FFont: TFont;
        FColor: TColor;
        FShowColumnHeader: Boolean;
        FShowRowHeader: Boolean;
        FColHeaderHeight: Integer;
        FRowHeaderWidth: Integer;
        function GetColHeaderHeight: Integer;
        function GetRowHeaderWidth: Integer;
        procedure SetColHeaderHeight(const Value: Integer);
        procedure SetRowHeaderWidth(const Value: Integer);
      protected
        function GetFont: TFont;
        function GetColor: TColor;
        function GetShowColHeader: Boolean;
        function GetShowRowHeader: Boolean;
        procedure SetFont(const Value: TFont);
        procedure SetColor(const Value: TColor);
        procedure SetShowColHeader(const Value: Boolean);
        procedure SetShowRowHeader(const Value: Boolean);
      public
        constructor Create(AOwner: TComponent);
        destructor Destroy; override;
      published
        property Font: TFont read GetFont write SetFont;
        property Color: TColor read GetColor write SetColor;
        property ShowColumnHeader: Boolean read GetShowColHeader write SetShowColHeader;
        property ShowRowHeader: Boolean read GetShowRowHeader write SetShowRowHeader;
        property ColumnHeaderHeight: Integer read GetColHeaderHeight write SetColHeaderHeight;
        property RowHeaderWidth: Integer read GetRowHeaderWidth write SetRowHeaderWidth;
      end;
     
      TCoolGrid = class(TCustomControl)
      private
        FCols: TGridColumns;
        FRows: TGridRows;
        FHeaders: TGridHeader;
        FCells: TGridCells;
        FSelectedCell: TGridCell;
        procedure SetCols(const Value: TGridColumns);
        procedure SetRows(const Value: TGridRows);
        procedure SetHeaders(const Value: TGridHeader);
      protected
        procedure Loaded; override;
        procedure Paint; override;
        procedure PaintBackground;
        procedure PaintCell(const ColIndex, RowIndex: Integer);
        procedure PaintGrid;
        procedure PaintHeaders;
        procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        procedure AddCol;
        procedure AddRow;
      published
        property Cols: TGridColumns read FCols write SetCols;
        property Headers: TGridHeader read FHeaders write SetHeaders;
        property Rows: TGridRows read FRows write SetRows;
      end;
    Ce que je veux faire c'est mettre mes collections dans le TGridHeader. Seulement quand je le fais, je n'ai plus accès à la boite de manipulation des collections en édition.

    Quelqu'un a t il une idée ?

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2010
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2010
    Messages : 71
    Par défaut
    Salut,
    dans ton code utilise Item et Collection dans les termes c'est vachement
    plus rapide pour si retrouver après ex TGridRow = TGridRowItem
    L'autre truc la collection doit être dans TGridHeader ???
    C'est pas plutôt les collections dans TCoolGrid et TGridHeader dans les CollectionItem...
    Donc ton code sur les Rows...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    TGridRowItem = class(TCollectionItem)
      private
        FTop: Integer;
        FHeight: Integer;
        FText: String;
        FGridHeader : TGridHeader;
        procedure SetGridHeader(Value : TGridHeader);
      protected
        function GetBottom: Integer;
        function GetHeight: Integer;
        procedure SetHeight(const Value: Integer);
        function GetText: String;
        procedure SetText(const Value: String);
        function GetDisplayName: String; override;
      public
        constructor Create(ACollection: TCollection); override;
        destructor Destroy; override;
        procedure Assign(Source: TPersistent);override;
      published
        property Top: Integer read FTop;
        property Bottom: Integer read GetBottom;
        property Height: Integer read GetHeight write SetHeight;
        property Text: String read GetText write SetText;
        property GridHeader: TGridHeader read FGridHeader write SetGridHeader;
      end;
     
      TGridRowCollection = class(TCollection)
        FCoolGrid : TCoolGrid;
      private
        function GetItem(Index: Integer): TGridRowItem;
        procedure SetItem(Index: Integer; Value: TGridRowItem);
      protected
        function GetOwner: TPersistent; override;
        procedure Update(Item: TCollectionItem); override;
      public
        constructor Create(CCoolGrid: TCoolGrid); virtual;
        destructor Destroy; override;
        function Add: TGridRowItem;
        function AddItem(Item: TGridRowItem; Index: Integer): TGridRowItem;
        function Insert(Index: Integer): TGridRowItem;
        procedure Delete(Index: Integer);
        property Items[Index: Integer]: TGridRowItem read GetItem write SetItem; default;
      end;
    Avec ceci, si j'ai bien compris, tu devrais t'en sortir maintenant.
    @+

  5. #5
    Membre habitué
    Inscrit en
    Juillet 2009
    Messages
    9
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 9
    Par défaut
    Merci Nuxtay, c'est sympa, mais je confirme c'est bien les collections dans le header et le header dans le composant.

  6. #6
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2010
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2010
    Messages : 71
    Par défaut
    ben j'avais bien compris du départ en fait, mais j'espèrai pour toi...
    Si ta TCollection est dans un TPersistent, l'inspecteur d'objet ne réagira pas,
    visuellement tu verra bien [...] mais en cliquant dessus il n'y aura aucune réaction
    Pourquoi, parce que l'éditeur de propriété des collections est limité et ne peut travailler que sur des TComponent...
    En plus si tu te dis "je transforme mon TPersistent en TComponent et voilà", ben pas gagné parce que maintenant tu n'auras plus [+] mais une liste déroulante.
    Donc la seule solution à mon avis est de gratter du coté éditeur de propriété,
    à moins que quelqu'un connaisse une solution plus simple ?
    @+

Discussions similaires

  1. Réponses: 0
    Dernier message: 11/11/2011, 20h45
  2. Réponses: 0
    Dernier message: 26/02/2009, 23h04
  3. Réponses: 4
    Dernier message: 13/05/2008, 11h35
  4. Réponses: 5
    Dernier message: 07/09/2007, 17h23
  5. [VB2005] Se copier lui même dans un répértoire
    Par Nico128 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 03/03/2007, 00h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo