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

Langage Delphi Discussion :

(Sender).parent = ?


Sujet :

Langage Delphi

  1. #1
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut (Sender).parent = ?
    Bonjour à toutes et à tous,

    Je ne trouvce pas la syntaxe qui me permettrait de trouver le parent d'un composant.
    J'ai créé un composant qui se nomme ShapeRu, dans l'evenement MouseMove comme je peux savoir de qui il est parent ?
    voilà ce que j'ai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    procedure ShapeRu.ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    Var
      Pt          : Tpoint;
      xCol, xRow  : Integer;
      xMin, xMax  : integer;
      xHeure ,i     : integer;
    begin
      inherited;
    //  if (TStringGridRu is TShapeRu(Sender).Parent) then
    // if TShapeRu(Sender).parent = TStringGridRu then
     
    end;
    je ne trouve pas la condition du parent. La seul chose qui marche c'est quand je nomme directement le parent. Mais à la création du composant je ne connais pas le parent je sais juste que se sera obligatoirement un TStringGrid.

    Merci de votre aide

  2. #2
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    pourquoi il y a un inherited dans ton gestionnaire ?


    sinon tu peux faire :


    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
    procedure ShapeRu.ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    Var
      Shape : TShape;
      StringGrid : TStringGrid;
      Pt          : Tpoint;
      xCol, xRow,
      xMin, xMax,
      xHeure ,i     : integer;
    begin
      if not Assigned(Sender) then
        exit;
      if not (sender is TShape) then
        exit;
     
      Shape := TShape(Sender); 
     
      if not Assigned(Shape.Parent) then
        exit;
      if not (Shape.Parent is TStringGrid) then
        exit;
     
      StringGrid := TStringGrid(Shape.Parent);
     
      ....
     
    end;
    [ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
    Ma messagerie n'est pas la succursale du forum... merci!

  3. #3
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Citation Envoyé par Dr.Who Voir le message
    pourquoi il y a un inherited dans ton gestionnaire ?


    sinon tu peux faire :


    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
    procedure ShapeRu.ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    Var
      Shape : TShape;
      StringGrid : TStringGrid;
      Pt          : Tpoint;
      xCol, xRow,
      xMin, xMax,
      xHeure ,i     : integer;
    begin
      if not Assigned(Sender) then
        exit;
      if not (sender is TShape) then
        exit;
     
      Shape := TShape(Sender); 
     
      if not Assigned(Shape.Parent) then
        exit;
      if not (Shape.Parent is TStringGrid) then
        exit;
     
      StringGrid := TStringGrid(Shape.Parent);
     
      ....
     
    end;
    T'es un as. Merci.

    pourquoi il y a un inherited dans ton gestionnaire ? Je crée un composant et j'ai toujour appris à inherrited; dans les procédures du composant, sinon en conception dans mon projet je ne peux plus utilsier MouseMove ?

  4. #4
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    inherited ne sert que dans l'implementation d'une classe.

    exemple :

    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
    uses Grids, ExtCtrls;
     
     
    type
      TShapeRu = class(TShape)
      private
        fStringGrid : TStringGrid;
        fIsOwned    : boolean;
      protected
        procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;
      public
        constructor create(AOwner: TStringGrid); reintroduce; override;
        destructor destroy; override;
      end;
     
    { TShapeRu }
     
    constructor TShapeRu.create(AOwner: TStringGrid);
    begin
      inherited create(TComponent(AOwner));
     
      fStringGrid := AOwner;
      fIsOwned    := assigned(AOwner);
      if fIsOwned then
      begin
        Parent := fStringGrid;
        fStringGrid.FreeNotification(Self);
      end;
    end;
     
    destructor TShapeRu.destroy;
    begin
      if fIsOwned then
        fStringGrid.RemoveFreeNotification(Self);
      inherited;
    end;
     
    procedure TShapeRu.MouseMove(Shift: TShiftState; X, Y: Integer);
    begin
      { quelque chose avant }
     
      inherited;
     
      { quelque chose aprés }
    end;
     
    procedure TShapeRu.Notification(AComponent: TComponent; Operation: TOperation);
    begin
      if fIsOwned and (AComponent = fStringGrid) and (Operation = opRemove) then
      begin
        fIsOwned    := false;
        fStringGrid := nil;
        Parent      := nil;
      end
      else
        inherited;
    end;

    par contre dans l'utilisation :

    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
     
    type
      TForm20 = class(TForm)
        StringGrid1: TStringGrid;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        fShapeRu: TShapeRu;
      protected
        procedure DoSHPMouseMove(Sender: TObject; ShiftState: TShiftState; X, Y: integer);
      public
      end;
     
     
    ...
    procedure TForm20.DoSHPMouseMove(Sender: TObject; ShiftState: TShiftState; X, Y: integer);
    begin
      if Sender = fShapeRu then
      begin
        // quelque chose //
      end;
    end;
     
    procedure TForm20.FormCreate(Sender: TObject);
    begin
      fShapeRu := TShapeRu.Create(StringGrid1);
      fShapeRu.SetBounds(10, 10, 50, 50);
      fShapeRu.OnMouseMove := DoSHPMouseMove;
    end;
     
     
    procedure TForm20.FormDestroy(Sender: TObject);
    begin
      fShapeRu.Free;
    end;
    [ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
    Ma messagerie n'est pas la succursale du forum... merci!

  5. #5
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 689
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 689
    Points : 13 118
    Points
    13 118
    Par défaut
    L'inherited dans les événements peut être nécessaire s'il y a héritage de fiche.

  6. #6
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Salut Andnotor.. nous voici avec 2 as de Delphi.

    Mon composant est comme cela

    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
    unit ShapeRu;
     
    interface
     
    uses
      Windows, SysUtils, Classes, Controls, ExtCtrls, Graphics, Math;
     
    type
      TShapeRu = class(TShape)
      private
        { Déclarations }
        FStartColor    : Tcolor;
        FEndColor      : Tcolor ;
        fCaption1      : String;
        fCaption2      : String;
        fTailleMini    : Integer;
        fTailleMaxi    : Integer;
        fTailleBlocDep : Byte;
        fLeftMini      : Integer;
        fObjet         : ShortString;
        fDateDebut     : TDate;
        fDatefin       : TDate;
        fHeureDebut    : ShortString;
        fHeureFin      : ShortString;
        fPosition      : Byte;
        fPos           : TPoint;
      protected
        { Déclarations protégées }
        procedure Paint; override;
      public
        { Déclarations publiques }
        constructor Create(AOwner : TComponent); override;
        destructor Destroy; override;
      published
        { Déclarations publiées }
        property Caption;
        property StartColor    : Tcolor read fStartColor write fStartColor ;
        property EndColor      : Tcolor read FEndColor write FEndColor ;
        property Caption1      : String read fCaption1 write fCaption1;
        property Caption2      : String read fCaption2 write fCaption2;
        property TailleMini    : Integer read fTailleMini write fTailleMini;
        property TailleMaxi    : Integer read fTailleMaxi write fTailleMaxi;
        property TailleBlocDep : Byte read fTailleBlocDep write fTailleBlocDep;
        property LeftMini      : Integer read fLeftMini write fLeftMini;
        property Objet         : ShortString read fObjet write fObjet;
        property DateDebut     : TDate read fDateDebut write fDateDebut;
        property Datefin       : TDate read fDatefin write fDatefin;
        property HeureDebut    : ShortString read fHeureDebut write fHeureDebut;
        property HeureFin      : ShortString read fHeureFin write fHeureFin;
        property Position      : Byte read fPosition write fPosition;
        property Pos           : TPoint read fPos write fPos;
      end;
     
    procedure Register;
     
    implementation
     
    constructor TShapeRu.Create(AOwner : TComponent);
    begin
      inherited Create(AOwner);
    end;
     
    destructor TShapeRu.Destroy;
    begin
      inherited Destroy;
    end;
     
    procedure TShapeRu.Paint;
      Procedure Degrader;
      Var
        TailleDuTexte : Integer;
        aBand : TRect;    { Bande rectangulaire de couleur courante }
        i : Integer;  { Compteur pour parcourir la hauteur de la fiche }
        FStartRGB  : Array[0..2] of Byte;    { RGB de la couleur de départ }
        FCurrentRGB : Array[0..2] of Byte;    { RGB de la couleur courante  }
        FDeltaRGB  : Array[0..2] of Integer; { RGB à ajouter à la couleur de départ pour atteindre la couleur de fin }
        nbtranches: integer;
        Rect:TRect;
      Begin
        Rect.Left := 2;
        Rect.Top := 2;
        Rect.Right := Self.Width-2;
        Rect.Bottom := Self.Height-2;
        self.ParentColor := false;
     
        { Calcul des valeurs RGB pour la couleur courante }
        FStartRGB[0] := GetRValue( ColorToRGB( StartColor ) );
        FStartRGB[1] := GetGValue( ColorToRGB( StartColor ) );
        FStartRGB[2] := GetBValue( ColorToRGB( StartColor ) );
        { Calcul des valeurs à ajouter pour atteindre la couleur de fin }
        FDeltaRGB[0] := GetRValue( ColorToRGB( EndColor )) - FStartRGB[0] ;
        FDeltaRGB[1] := GetgValue( ColorToRGB( EndColor )) - FStartRGB[1] ;
        FDeltaRGB[2] := GetbValue( ColorToRGB( EndColor )) - FStartRGB[2] ;
     
        { Initialisation des dimensions de la bande de couleur }
        aBand.Left :=Rect.Left;
        aBand.Right:=Rect.Right;
        nbtranches:=min(256, Rect.Bottom-Rect.Top);
        { Boucle pour remplir la fiche courante en dégradé }
        With Canvas Do
        Begin
          Pen.Style:=psSolid;
          Pen.Mode:=pmCopy;
          For i:= 0 To nbtranches-1 Do
          Begin
              { Dimensions verticales de la bande }
              aBand.Left :=Rect.Left;
              aBand.Right:=Rect.Right;
              aBand.Top := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*i);
              aBand.Bottom := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*(i+1));
     
              { Calcul de la couleur courante }
              FCurrentRGB[0] := (FStartRGB[0] + MulDiv( i , FDeltaRGB[0] , nbtranches )) mod 256;
              FCurrentRGB[1] := (FStartRGB[1] + MulDiv( i , FDeltaRGB[1] , nbtranches )) mod 256;
              FCurrentRGB[2] := (FStartRGB[2] + MulDiv( i , FDeltaRGB[2] , nbtranches )) mod 256;
              { Affichage sur la fiche }
              Brush.color:=RGB(FCurrentRGB[0],FCurrentRGB[1],FCurrentRGB[2]);
              FillRect(aBand);
          End;
          Font.Name := self.Font.Name;
          Font.Size := self.Font.Size;
          Brush.Style := bsClear;
          if Self.Caption1 = '' then DrawText(Canvas.Handle, PChar(Self.Caption) , -1, Rect, DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
          else
          Begin
            DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
            TailleDuTexte := DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
            Rect.Top := Rect.Top + TailleDuTexte + 2;
            Pen.Color := clBlack;
            MoveTo(Rect.Left+2,Rect.Top);
            LineTo(Rect.Right-2,Rect.top);
            Rect.Top := Rect.Top + 2;
            DrawText(Canvas.Handle, PChar(Self.Caption2) , -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
          end;
        End;
      End;
    begin
      inherited Paint;
      Degrader;
    end;
     
    procedure Register;
    begin
      RegisterComponents('RuCompos', [TShapeRu]);
    end;
     
    end.
    Et la procedure ci dessous qui se trouve dans la form principal, affecté au evenement shaperu lors de leur création dynamitique que je n'arrive pas justement à intégrer dans le composant !!

    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
    procedure TFPrincipal.ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    Var
      StringGrid  : TStringGrid;
      Pt          : Tpoint;
      xCol, xRow  : Integer;
      xMin, xMax  : integer;
      xHeure ,i   : integer;
    begin
      if not Assigned(Sender) then exit;
      if not (Sender is TShapeRu) then exit;
      if not Assigned(TShapeRu(Sender).Parent) then  exit;
      if not (TShapeRu(Sender).Parent is TStringGrid) then exit;
      StringGrid := TStringGridRu(TShapeRu(Sender).Parent);
     
      if Y > StringGrid.ClientHeight then exit;
      if (Sender is TShapeRu) then
      begin
        TShapeRu(Sender).Cursor := crSizeAll; //Cursor pour le déplacement
        if X >= TShapeRu(Sender).Width-3 then TShapeRu(Sender).Cursor:=CrHsplit; // Cursor pour l'étirement
        if (TShapeRu(Sender).Position = 2) then // Si on étire le Shape (valeur donnée par MouseDown)
        begin
          if (X > TShapeRu(Sender).TailleMini)
            and (X mod TShapeRu(Sender).TailleBlocDep = 0)
              and (X + TShapeRu(Sender).Left <= TShapeRu(Sender).TailleMaxi)
                then
                begin
                  Pt := TShapeRu(Sender).ClientToParent(point(x,y));
                  StringGrid.MouseToCell(Pt.X, Pt.Y, xCol, xRow);
     
                  xHeure :=(Pt.X - StringGrid.ColWidths[0]
                      - (StringGrid.DefaultColWidth * (xCol-1))) div 6;
     
                  for i := 1 to StringGrid.ColCount do
                  if i <> xCol
                  then StringGrid.Cells[i,1] := ''
                  else if xHeure <> 0 then StringGrid.Cells[i,1] :=RepereHoraires[xHeure];
     
                  TShapeRu(Sender).Width := X;
                end;
        end
        else
          if (TShapeRu(Sender).Position = 3) then // Si on déplace le Shape (valeur donnée par MouseDown)
          begin
            Pt := TShapeRu(Sender).ClientToParent(point(x,y));
            StringGrid.MouseToCell(Pt.X, Pt.Y, xCol, xRow);
            if InRange(xRow, StringGrid.FixedRows, StringGrid.RowCount-1) then
            begin
              TShapeRu(Sender).Top := StringGrid.CellRect(xCol, xRow).Top; //Déplacement du Shape sur la nouvelle ligne
              TShapeRu(Sender).Tag := xRow;
            end;
            xMin := StringGrid.CellRect(StringGrid.FixedCols, xRow).Left; //Position mini. en X (Left 1ère colonne éditable)
            xMax := StringGrid.CellRect(StringGrid.ColCount -1, xRow).Right - TShapeRu(Sender).Width; //Position maxi. en X (Right dernière colonne -Panel.Width)
            if ((TShapeRu(Sender).Left + X - TShapeRu(Sender).Pos.X) mod 6 = 0) then
            if ((TShapeRu(Sender).Left + X - TShapeRu(Sender).Pos.X) mod TShapeRu(Sender).TailleBlocDep = 0) then
              Begin
                X := (TShapeRu(Sender).Left + X - TShapeRu(Sender).Pos.X);
                TShapeRu(Sender).Left := EnsureRange(X, xMin, xMax); //Déplacement en X
              end;
          end;
      end;
    end;
     
    procedure TFPrincipal.ShapeMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if not Assigned(Sender) then exit;
      if not (Sender is TShapeRu) then exit;
      if not Assigned(TShapeRu(Sender).Parent) then  exit;
      if not (TShapeRu(Sender).Parent is TStringGrid) then exit;
      if (not Enabled) or (Button <> mbLeft) then exit;
     
      TShapeRu(Sender).BringToFront;
      TShapeRu(Sender).CustomHint.HideHint;
     
      if (X >= TShapeRu(Sender).Width-3)
      then TShapeRu(Sender).position := 2
      else
        Begin
          TShapeRu(Sender).position := 3;
          TShapeRu(Sender).Pos := Point(X,Y);
        end;
    end;
     
    procedure TFPrincipal.ShapeMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if not Assigned(Sender) then exit;
      if not (Sender is TShapeRu) then exit;
      if not Assigned(TShapeRu(Sender).Parent) then  exit;
      if not (TShapeRu(Sender).Parent is TStringGrid) then exit;
     
      TShapeRu(Sender).Position := 0;
    end;
    et quand je créer le compo je fais cela :

    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
            while not eof do
            begin
              Shape1 := TShapeRu.Create(StringGridSemaine);
              With Shape1 do
              Begin
                ParentFont        := False;
                Name              := 'PANEL'+FieldByName('CodeShape').AsString;
                Caption           := FieldByName('CodeCategorie').AsString;
                DateDebut         := FieldByName('DateDebut').AsDateTime;
                Datefin           := FieldByName('DateFin').AsDateTime;
                HeureDebut        := FieldByName('HeureDebut').AsString;
                HeureFin          := FieldByName('HeureFin').AsString;
                Left              := LeftOfShape(FieldByName('DateDebut').AsString,FieldByName('HeureDebut').AsString,StringGridSemaine);
                Height            := StringGridSemaine.DefaultRowHeight;
                Width             := WidthOfShape(FieldByName('DateDebut').AsString,
                                    FieldByName('HeureDebut').AsString,
                                    FieldByName('DateFin').AsString,
                                    FieldByName('HeureFin').AsString,
                                    StringGridSemaine);
                TailleMini        := 6;
                TailleMaxi        := StringGridSemaine.ColWidths[0] + (StringGridSemaine.DefaultColWidth * (StringGridSemaine.ColCount-1));
                TailleBlocDep     := 6;
                StartColor        := clCream;
                EndColor          := FieldByName('Couleur').AsInteger;
                Parent            := StringGridSemaine;
                OnMouseMove       := Self.ShapeMouseMove;
                OnMouseDown       := Self.ShapeMouseDown;
                OnMouseUp         := Self.ShapeMouseUp;
                Tag               := TagOfSalarie(FieldByName('CodeSalarie').AsString,StringGridSemaine);
                ParentShowHint    := True;
                ParentCustomHint  := True;
                Hint              := HintOfShape(FieldByName('CodeShape').AsString);
                ShowHint          := True;
              end;
    Ma question de départ etait d'avoir le parent du sender, le sender etant le TShapeRu

    vous voyer mieux ?

  7. #7
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 689
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 689
    Points : 13 118
    Points
    13 118
    Par défaut
    C'est pas clair au niveau de la déclaration de tes méthodes. Elles devraient être comme ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    TShapeRu = class(TShape)
    protected
      ...
      procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
      procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
      procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    Et si tu entres dans ces méthodes, c'est que le composant est obligatoirement visible, donc avec un Parent défini !

  8. #8
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    tu veux faire des dégradé ?

    voici l'unité Gradient de Cirec, pur api windows, trés pratique :
    Fichiers attachés Fichiers attachés
    [ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
    Ma messagerie n'est pas la succursale du forum... merci!

  9. #9
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    C'est pas clair au niveau de la déclaration de tes méthodes. Elles devraient être comme cecI !
    Oui, tout a fait, sauf que ce que je présentait plus bas c'est 2 choses.
    1 - le composant (qui ne comprend pas les méthode OnMouse
    2 - une form pricipal dans laquelle j'ai mis ces méthode que je rattache lors de la création du composant
    En fait j'ai séparer cela car je n'arrivais pas à trouver le parent dans la création de mon composant.

    Pour mémoire : Si tu regarde bien la procédure OnMouseMove... c'est toi qui l'avais initié

    Donc ne sachant pas trouver le parent pendant la création de mon composant, je le faisais comme ça. Maintenant si tu me dit que le composant à forcément un parent lorsque je le créé, je vais essayer d'intégrer ces 3 procédures dans mon coposant directement.
    Mais j'ai une question :
    - Est-ce que si dans l'une des 3 procédures j'ai besoin de faire autre chose dois-je le faire obligatoirement dans la création de mon composant ? Exemple dans le onMouseUp (il y a pratiquement rien là) mai au final je vais écrire dans une base de donnée. Donc dois-je le mettre de suite en création de mon composant où est-ce que je le fais avec une autre procédure dans la form principal ?

    Dr Who : Je n'ai pas besoin d'une procédure de gradiant, celle présente fonctionne parfaitement. Au passage le inherited c'est quoi la différence entre écrire des chose avant et des chose après le inherited ?

    Merci.

  10. #10
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 689
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 689
    Points : 13 118
    Points
    13 118
    Par défaut
    Non, au Create, la propriété Parent n'est pas encore renseignée. Mais en voyant le code de création, le Parent = le Owner qui lui est défini (StringGridSemaine dans les deux cas).

    Dans le Create, tu peux donc soit utiliser Owner à la place de Parent ou même directement y assigner le Parent:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    constructor TShapeRu.Create(aOwner :TComponent);
    begin
      inherited;
      Parent := TWinControl(aOwner);
      ...
    end;

  11. #11
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    dans une methode, quand on appel "inherited" seul ou "inherited truc(machin)" on appel simplement une methode de l'ancetre.

    on peu donc faire des choses avant et aprés l'appel de cette methode.

    par exemple, dans Create on appelera de préférence inherited avant et dans Destroy on l'appelera aprés.

    dans une methode de dessin, on pourra preparer des choses avant la methode ancetre et aprés.
    [ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
    Ma messagerie n'est pas la succursale du forum... merci!

  12. #12
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    Non, au Create, la propriété Parent n'est pas encore renseignée. Mais en voyant le code de création, le Parent = le Owner qui lui est défini (StringGridSemaine dans les deux cas).

    Dans le Create, tu peux donc soit utiliser Owner à la place de Parent ou même directement y assigner le Parent:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    constructor TShapeRu.Create(aOwner :TComponent);
    begin
      inherited;
      Parent := TWinControl(aOwner);
      ...
    end;
    J'ai essayé d'ajouter les 2 évenements : OnMouseMove et onMouseDown

    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
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    unit ShapeRu;
     
    interface
     
    uses
      Windows, SysUtils, Classes, Controls, ExtCtrls, Graphics, Math, Grids,
      StringGridRu;
    type
      TShapeRu = class(TShape)
      private
        { Déclarations }
        FStartColor    : Tcolor;
        FEndColor      : Tcolor ;
        fCaption1      : String;
        fCaption2      : String;
        fTailleMini    : Integer;
        fTailleMaxi    : Integer;
        fTailleBlocDep : Byte;
        fLeftMini      : Integer;
        fObjet         : ShortString;
        fDateDebut     : TDate;
        fDatefin       : TDate;
        fHeureDebut    : ShortString;
        fHeureFin      : ShortString;
        fPosition      : Byte;
        fPos           : TPoint;
      protected
        { Déclarations protégées }
        procedure Paint; override;
      public
        { Déclarations publiques }
        constructor Create(AOwner : TComponent); override;
        destructor Destroy; override;
        procedure OnMouseMove(Shift: TShiftState; X, Y: Integer);
        procedure OnMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      published
        { Déclarations publiées }
        property Caption;
        property StartColor    : Tcolor read fStartColor write fStartColor ;
        property EndColor      : Tcolor read FEndColor write FEndColor ;
        property Caption1      : String read fCaption1 write fCaption1;
        property Caption2      : String read fCaption2 write fCaption2;
        property TailleMini    : Integer read fTailleMini write fTailleMini;
        property TailleMaxi    : Integer read fTailleMaxi write fTailleMaxi;
        property TailleBlocDep : Byte read fTailleBlocDep write fTailleBlocDep;
        property LeftMini      : Integer read fLeftMini write fLeftMini;
        property Objet         : ShortString read fObjet write fObjet;
        property DateDebut     : TDate read fDateDebut write fDateDebut;
        property Datefin       : TDate read fDatefin write fDatefin;
        property HeureDebut    : ShortString read fHeureDebut write fHeureDebut;
        property HeureFin      : ShortString read fHeureFin write fHeureFin;
        property Position      : Byte read fPosition write fPosition;
        property Pos           : TPoint read fPos write fPos;
      end;
     
    procedure Register;
     
    implementation
     
    constructor TShapeRu.Create(AOwner : TComponent);
    begin
      inherited;
      Parent := TWinControl(AOwner);
    //  inherited Create(AOwner);
    end;
     
    destructor TShapeRu.Destroy;
    begin
      inherited Destroy;
    end;
     
    procedure TShapeRu.Paint;
      Procedure Degrader;
      Var
        TailleDuTexte : Integer;
        aBand : TRect;    { Bande rectangulaire de couleur courante }
        i : Integer;  { Compteur pour parcourir la hauteur de la fiche }
        FStartRGB  : Array[0..2] of Byte;    { RGB de la couleur de départ }
        FCurrentRGB : Array[0..2] of Byte;    { RGB de la couleur courante  }
        FDeltaRGB  : Array[0..2] of Integer; { RGB à ajouter à la couleur de départ pour atteindre la couleur de fin }
        nbtranches: integer;
        Rect:TRect;
      Begin
        Rect.Left := 2;
        Rect.Top := 2;
        Rect.Right := Self.Width-2;
        Rect.Bottom := Self.Height-2;
        self.ParentColor := false;
     
        { Calcul des valeurs RGB pour la couleur courante }
        FStartRGB[0] := GetRValue( ColorToRGB( StartColor ) );
        FStartRGB[1] := GetGValue( ColorToRGB( StartColor ) );
        FStartRGB[2] := GetBValue( ColorToRGB( StartColor ) );
        { Calcul des valeurs à ajouter pour atteindre la couleur de fin }
        FDeltaRGB[0] := GetRValue( ColorToRGB( EndColor )) - FStartRGB[0] ;
        FDeltaRGB[1] := GetgValue( ColorToRGB( EndColor )) - FStartRGB[1] ;
        FDeltaRGB[2] := GetbValue( ColorToRGB( EndColor )) - FStartRGB[2] ;
     
        { Initialisation des dimensions de la bande de couleur }
        aBand.Left :=Rect.Left;
        aBand.Right:=Rect.Right;
        nbtranches:=min(256, Rect.Bottom-Rect.Top);
        { Boucle pour remplir la fiche courante en dégradé }
        With Canvas Do
        Begin
          Pen.Style:=psSolid;
          Pen.Mode:=pmCopy;
          For i:= 0 To nbtranches-1 Do
          Begin
              { Dimensions verticales de la bande }
              aBand.Left :=Rect.Left;
              aBand.Right:=Rect.Right;
              aBand.Top := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*i);
              aBand.Bottom := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*(i+1));
     
              { Calcul de la couleur courante }
              FCurrentRGB[0] := (FStartRGB[0] + MulDiv( i , FDeltaRGB[0] , nbtranches )) mod 256;
              FCurrentRGB[1] := (FStartRGB[1] + MulDiv( i , FDeltaRGB[1] , nbtranches )) mod 256;
              FCurrentRGB[2] := (FStartRGB[2] + MulDiv( i , FDeltaRGB[2] , nbtranches )) mod 256;
              { Affichage sur la fiche }
              Brush.color:=RGB(FCurrentRGB[0],FCurrentRGB[1],FCurrentRGB[2]);
              FillRect(aBand);
          End;
          Font.Name := self.Font.Name;
          Font.Size := self.Font.Size;
          Brush.Style := bsClear;
          if Self.Caption1 = '' then DrawText(Canvas.Handle, PChar(Self.Caption) , -1, Rect, DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
          else
          Begin
            DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
            TailleDuTexte := DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
            Rect.Top := Rect.Top + TailleDuTexte + 2;
            Pen.Color := clBlack;
            MoveTo(Rect.Left+2,Rect.Top);
            LineTo(Rect.Right-2,Rect.top);
            Rect.Top := Rect.Top + 2;
            DrawText(Canvas.Handle, PChar(Self.Caption2) , -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
          end;
        End;
      End;
    begin
      inherited Paint;
      Degrader;
    end;
     
    procedure TShapeRu.OnMouseMove(Shift: TShiftState; X, Y: Integer);
    Var
      StringGrid  : TStringGridRu;
      Pt          : Tpoint;
      xCol, xRow  : Integer;
      xMin, xMax  : integer;
      xHeure ,i   : integer;
    begin
      if not Assigned(Parent) then  exit;
      if not (Parent is TStringGridRu) then exit;
      StringGrid := TStringGridRu(Parent);
      if Y > StringGrid.ClientHeight then exit;
     
      Cursor := crSizeAll; //Cursor pour le déplacement
      if X >= Width-3 then Cursor:=CrHsplit; // Cursor pour l'étirement
      if (Position = 2) then // Si on étire le Shape (valeur donnée par MouseDown)
      begin
        if (X > TailleMini)
          and (X mod TailleBlocDep = 0)
            and (X + Left <= TailleMaxi)
              then
              begin
                Pt := ClientToParent(point(x,y));
                StringGrid.MouseToCell(Pt.X, Pt.Y, xCol, xRow);
     
                xHeure :=(Pt.X - StringGrid.ColWidths[0]
                    - (StringGrid.DefaultColWidth * (xCol-1))) div 6;
      {
                for i := 1 to StringGrid.ColCount do
                if i <> xCol
                then StringGrid.Cells[i,1] := ''
                else if xHeure <> 0 then StringGrid.Cells[i,1] :=RepereHoraires[xHeure];
     
                Width := X;
                }
              end;
      end
      else
        if (Position = 3) then // Si on déplace le Shape (valeur donnée par MouseDown)
        begin
          Pt := ClientToParent(point(x,y));
          StringGrid.MouseToCell(Pt.X, Pt.Y, xCol, xRow);
          if InRange(xRow, StringGrid.FixedRows, StringGrid.RowCount-1) then
          begin
            Top := StringGrid.CellRect(xCol, xRow).Top; //Déplacement du Shape sur la nouvelle ligne
            Tag := xRow;
          end;
          xMin := StringGrid.CellRect(StringGrid.FixedCols, xRow).Left; //Position mini. en X (Left 1ère colonne éditable)
          xMax := StringGrid.CellRect(StringGrid.ColCount -1, xRow).Right - Width; //Position maxi. en X (Right dernière colonne -Panel.Width)
          if ((Left + X - Pos.X) mod TailleBlocDep = 0) then
          Begin
            X := (Left + X - Pos.X);
            Left := EnsureRange(X, xMin, xMax); //Déplacement en X
          end;
        end;
    end;
     
    procedure TShapeRu.OnMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if not Assigned(Parent) then  exit;
      if not (Parent is TStringGridRu) then exit;
      if (not Enabled) or (Button <> mbLeft) then exit;
     
      BringToFront;
      CustomHint.HideHint;
     
      if (X >= Width-3)
      then position := 2
      else
        Begin
          position := 3;
          Pos := Point(X,Y);
        end;
    end;
     
    procedure Register;
    begin
      RegisterComponents('RuCompos', [TShapeRu]);
    end;
     
    end.
    Mais à l'issu de la création dynamique, rien ne fonctionne.

  13. #13
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 689
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 689
    Points : 13 118
    Points
    13 118
    Par défaut
    Ne pas oublier l'override .

  14. #14
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    Ne pas oublier l'override .
    Purée... le pire je le sais... Merci.

    Alors voici une version presque fini

    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
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    unit ShapeRu;
     
    interface
     
    uses
      Windows, SysUtils, Classes, Controls, ExtCtrls, Graphics, Math, Grids,
      StringGridRu;
    type
      TShapeRu = class(TShape)
      private
        { Déclarations }
        FStartColor    : Tcolor;
        FEndColor      : Tcolor ;
        fCaption1      : String;
        fCaption2      : String;
        fTailleMini    : Integer;
        fTailleMaxi    : Integer;
        fTailleBlocDep : Byte;
        fLeftMini      : Integer;
        fObjet         : ShortString;
        fDateDebut     : TDate;
        fDatefin       : TDate;
        fHeureDebut    : ShortString;
        fHeureFin      : ShortString;
        fPosition      : Byte;
        fPos           : TPoint;
      protected
        { Déclarations protégées }
        procedure Paint; override;
      public
        { Déclarations publiques }
        constructor Create(AOwner : TComponent); override;
        destructor Destroy; override;
        procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
        procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
      published
        { Déclarations publiées }
        property Caption;
        property StartColor    : Tcolor read fStartColor write fStartColor ;
        property EndColor      : Tcolor read FEndColor write FEndColor ;
        property Caption1      : String read fCaption1 write fCaption1;
        property Caption2      : String read fCaption2 write fCaption2;
        property TailleMini    : Integer read fTailleMini write fTailleMini;
        property TailleMaxi    : Integer read fTailleMaxi write fTailleMaxi;
        property TailleBlocDep : Byte read fTailleBlocDep write fTailleBlocDep;
        property LeftMini      : Integer read fLeftMini write fLeftMini;
        property Objet         : ShortString read fObjet write fObjet;
        property DateDebut     : TDate read fDateDebut write fDateDebut;
        property Datefin       : TDate read fDatefin write fDatefin;
        property HeureDebut    : ShortString read fHeureDebut write fHeureDebut;
        property HeureFin      : ShortString read fHeureFin write fHeureFin;
        property Position      : Byte read fPosition write fPosition;
        property Pos           : TPoint read fPos write fPos;
      end;
     
    Const
      RepereHorairesMouseMoveinShape    : Array[0..29] of String =
      ('  6h30','    7h','      7h30','        8h','          8h30',
       '            9h','              9h30','                10h',
       '                10h30','                   11h','                   11h30',
       '                       12h','                       12h30','                           13h',
       '                           13h30', '                               14h',
       '                               14h30','                                   15h',
       '                                   15h30','                                       16h',
       '                                       16h30','                                           17h',
       '                                           17h30','                                               18h',
       '                                               18h30','                                                   19h',
       '                                                   19h30',
       '                                                       20h',
       '                                                    20h30',
       '                                                       21h'
      );
     
    procedure Register;
     
    implementation
     
    constructor TShapeRu.Create(AOwner : TComponent);
    begin
    //  inherited Create(AOwner);
      inherited;
      Parent := TWinControl(AOwner);
    end;
     
    destructor TShapeRu.Destroy;
    begin
      inherited Destroy;
    end;
     
    procedure TShapeRu.Paint;
      Procedure Degrader;
      Var
        TailleDuTexte : Integer;
        aBand : TRect;    { Bande rectangulaire de couleur courante }
        i : Integer;  { Compteur pour parcourir la hauteur de la fiche }
        FStartRGB  : Array[0..2] of Byte;    { RGB de la couleur de départ }
        FCurrentRGB : Array[0..2] of Byte;    { RGB de la couleur courante  }
        FDeltaRGB  : Array[0..2] of Integer; { RGB à ajouter à la couleur de départ pour atteindre la couleur de fin }
        nbtranches: integer;
        Rect:TRect;
      Begin
        Rect.Left := 2;
        Rect.Top := 2;
        Rect.Right := Self.Width-2;
        Rect.Bottom := Self.Height-2;
        self.ParentColor := false;
     
        { Calcul des valeurs RGB pour la couleur courante }
        FStartRGB[0] := GetRValue( ColorToRGB( StartColor ) );
        FStartRGB[1] := GetGValue( ColorToRGB( StartColor ) );
        FStartRGB[2] := GetBValue( ColorToRGB( StartColor ) );
        { Calcul des valeurs à ajouter pour atteindre la couleur de fin }
        FDeltaRGB[0] := GetRValue( ColorToRGB( EndColor )) - FStartRGB[0] ;
        FDeltaRGB[1] := GetgValue( ColorToRGB( EndColor )) - FStartRGB[1] ;
        FDeltaRGB[2] := GetbValue( ColorToRGB( EndColor )) - FStartRGB[2] ;
     
        { Initialisation des dimensions de la bande de couleur }
        aBand.Left :=Rect.Left;
        aBand.Right:=Rect.Right;
        nbtranches:=min(256, Rect.Bottom-Rect.Top);
        { Boucle pour remplir la fiche courante en dégradé }
        With Canvas Do
        Begin
          Pen.Style:=psSolid;
          Pen.Mode:=pmCopy;
          For i:= 0 To nbtranches-1 Do
          Begin
              { Dimensions verticales de la bande }
              aBand.Left :=Rect.Left;
              aBand.Right:=Rect.Right;
              aBand.Top := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*i);
              aBand.Bottom := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*(i+1));
     
              { Calcul de la couleur courante }
              FCurrentRGB[0] := (FStartRGB[0] + MulDiv( i , FDeltaRGB[0] , nbtranches )) mod 256;
              FCurrentRGB[1] := (FStartRGB[1] + MulDiv( i , FDeltaRGB[1] , nbtranches )) mod 256;
              FCurrentRGB[2] := (FStartRGB[2] + MulDiv( i , FDeltaRGB[2] , nbtranches )) mod 256;
              { Affichage sur la fiche }
              Brush.color:=RGB(FCurrentRGB[0],FCurrentRGB[1],FCurrentRGB[2]);
              FillRect(aBand);
          End;
          Font.Name := self.Font.Name;
          Font.Size := self.Font.Size;
          Brush.Style := bsClear;
          if Self.Caption1 = '' then DrawText(Canvas.Handle, PChar(Self.Caption) , -1, Rect, DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
          else
          Begin
            DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
            TailleDuTexte := DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
            Rect.Top := Rect.Top + TailleDuTexte + 2;
            Pen.Color := clBlack;
            MoveTo(Rect.Left+2,Rect.Top);
            LineTo(Rect.Right-2,Rect.top);
            Rect.Top := Rect.Top + 2;
            DrawText(Canvas.Handle, PChar(Self.Caption2) , -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
          end;
        End;
      End;
    begin
      inherited Paint;
      Degrader;
    end;
     
    procedure TShapeRu.MouseMove(Shift: TShiftState; X, Y: Integer);
    Var
      StringGrid  : TStringGridRu;
      Pt          : Tpoint;
      xCol, xRow  : Integer;
      xMin, xMax  : integer;
      xHeure      : integer;
      xColonneDeb, xColonneFin : integer;
      i   : integer;
    begin
      inherited;
      if not Assigned(Parent) then  exit;
      if not (Parent is TStringGridRu) then exit;
      StringGrid := TStringGridRu(Parent);
     
      if Y > StringGrid.ClientHeight then exit;
     
      Cursor := crSizeAll; //Cursor pour le déplacement
      if (X >= Width-3) then Cursor:=CrHsplit; // Cursor pour l'étirement
     
      case Position of
       2:  // Si on étire le Shape (valeur donnée par MouseDown)
        begin
          if (X >= TailleMini)
          and (X mod TailleBlocDep = 0)
          and (X + Left <= TailleMaxi) then
          begin
            Pt := ClientToParent(Point(x,y));
            StringGrid.MouseToCell(Pt.X, Pt.Y, xCol, xRow);
            Width := X;
     
            xColonneDeb:= (Left - StringGrid.ColWidths[0]) div StringGrid.DefaultColWidth;
            xColonneFin:= (Width - 1 + left - StringGrid.ColWidths[0]) div StringGrid.DefaultColWidth;
            xHeure :=((Pt.X - StringGrid.ColWidths[0] - (StringGrid.DefaultColWidth * (xColonneFin))) div 6);
     
            for i := 1 to StringGrid.ColCount do
            if i <> xColonneFin + 1
            then StringGrid.Cells[i,1] := ''
            else StringGrid.Cells[i,1] := RepereHorairesMouseMoveinShape[xHeure-1];
     
          end;
        end;
      3: // Si on déplace le Shape (valeur donnée par MouseDown)
        begin
          Pt := ClientToParent(point(x,y));
          StringGrid.MouseToCell(Pt.X, Pt.Y, xCol, xRow);
          if InRange(xRow, StringGrid.FixedRows, StringGrid.RowCount-1) then
          begin
            Top := StringGrid.CellRect(xCol, xRow).Top; //Déplacement du Shape sur la nouvelle ligne
            Tag := xRow;
          end;
          xMin := StringGrid.CellRect(StringGrid.FixedCols, xRow).Left; //Position mini. en X (Left 1ère colonne éditable)
          xMax := StringGrid.CellRect(StringGrid.ColCount -1, xRow).Right - Width; //Position maxi. en X (Right dernière colonne -Panel.Width)
          if ((Left + X - Pos.X) mod TailleBlocDep = 0) then
          Begin
            X := (Left + X - Pos.X);
            Left := EnsureRange(X, xMin, xMax); //Déplacement en X
          end;
        end;
      end; // End of Case
    end;
     
    procedure TShapeRu.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      inherited;
      if not Assigned(Parent) then  exit;
      if not (Parent is TStringGrid) then exit;
      if (not Enabled) or (Button <> mbLeft) then exit;
     
      BringToFront;
      CustomHint.HideHint;
     
      if (X >= Width-3)
      then position := 2 // On est pret à étirer la tache
      else
        Begin
          position := 3; // on va déplacer la tâches entièrement
          Pos := Point(X,Y);
        end;
    end;
     
    procedure Register;
    begin
      RegisterComponents('RuCompos', [TShapeRu]);
    end;
     
    end.
    Quelque question :
    - Le inherited des procédure MouseMove et MouseDown est-il bien placé ? car comme le mettais dr.Who on peut faire des chose avant et des choses apres.
    - Est-ce que j'ai respecté la bonne procédure dans MouseMove et MouseDown au niveau des premiers test de sortir (exit
    - Si dans une autre form je place se chape,sans passer en création dynamique, ou en passant par une création dynamique, etc-ce que si je mets une metohde OnMouseDown dans l'évenement du shapeRu cela géne la procédure du Tshapru ? est-ce que la procédure du TshapeRu est tout de même exécuté ?

    Merci pour tes lumières.

  15. #15
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 689
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 689
    Points : 13 118
    Points
    13 118
    Par défaut
    Question 1 et 3:
    Lorsqu'on fait un override, il est toujours intéressant de jeter un oeil à la méthode du composant dont on hérite . Comme l'a mentionné Who, inherited ne fait qu'appeler la méthode du même nom dans le composant ancêtre.

    Dans le cas d'un dérivé du TShape, il faut remonter au TControl pour trouver une déclaration des procédures MouseXXX. Et que voit-on ? Simplement que ces procédures génèrent les événements OnMouseXXX. Il n'y a aucun calcul, création ou initialisation. Donc à toi simplement de savoir si tu préfères que le code du composant soit exécuté en premier ou si le code de la fiche (OnMouseXXX) est prioritaire.

    Question 2:
    Au niveau du Parent, je te l'ai déjà dit: Si tu passes dans les méthode MouseXXX, c'est qu'un Parent est défini. Le If Assigned renverra toujours vrai. Donc inutile .

    PS: Je n'ai toujours pas compris pourquoi tu as besoin du Parent dans le constructeur.

  16. #16
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Ok pour tes réponses, grand merci.

    Citation Envoyé par Andnotor Voir le message
    [U]
    PS: Je n'ai toujours pas compris pourquoi tu as besoin du Parent dans le constructeur.
    En fait j'ai besoin du parent uniquement dans l'évènement mousemove et mousedown. Mais c'est toi qui ma proposé de le mettre à la création !. lol

    Sinon j'ai pas encore compris la différence entre faire des déclarations avant où après le inherited d'une procedure ?

  17. #17
    Rédacteur
    Avatar de evarisnea
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Juin 2005
    Messages
    1 957
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2005
    Messages : 1 957
    Points : 4 384
    Points
    4 384
    Par défaut

    Citation Envoyé par BuzzLeclaire Voir le message
    Sinon j'ai pas encore compris la différence entre faire des déclarations avant où après le inherited d'une procedure ?
    en fait, comme cela a été dit, Inherited fait appel à la méthode ancêtre de celle qu'on est entrain d'implémenter.

    un exemple tout simple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    //code de la procédure ancêtre
    procedure TAncetre.AfficheMessage();
    begin
      ShowMessage('Ceci est un message');
    end;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    //code de la procédure enfant
    procedure TAncetre.AfficheMessage();
    begin
      //un code quelconque
      ShowMessage('Un message va être affiché');
     
      //appel a la procédure ancêtre
      Inherited;
     
      //un autre code
      ShowMessage('Un message a été affiché');
    end;
    l'exécution de la procédure AfficheMessage de l'enfant affichera donc 3 boîtes de dialogue.

    cet exemple est tout simple, mais il y a des cas où il faut savoir quand appeler la procédure ancêtre, comme dans le cas du constructeur ou du destructeur de la classe (mentionné par Dr.Who), ou lorsque l'on redéfinit des méthodes qui redessinent le composant par exemple.

    il y a également des fois où l'on décide de ne pas faire appel à la méthode ancêtre tout simplement!

  18. #18
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Merci à vous tous pour votre aide.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Parent et Create
    Par Arrown dans le forum Composants VCL
    Réponses: 4
    Dernier message: 09/10/2003, 11h13
  2. Comment reloader la frame parent?
    Par mythtvtalk.com dans le forum ASP
    Réponses: 3
    Dernier message: 27/08/2003, 11h40
  3. Conception d'une classe parente
    Par VincentB dans le forum Langage
    Réponses: 9
    Dernier message: 24/06/2003, 17h28
  4. DLL, affichage et parent...
    Par KRis dans le forum Composants VCL
    Réponses: 6
    Dernier message: 13/12/2002, 17h01
  5. Un Sender peut-il s'auto-détruire lors d'un onClick?
    Par Flo. dans le forum C++Builder
    Réponses: 2
    Dernier message: 17/07/2002, 10h31

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