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

C++Builder Discussion :

Ajouter l'écriture verticale à un TLabel


Sujet :

C++Builder

  1. #1
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut Ajouter l'écriture verticale à un TLabel
    Bonsoir:
    Je souhaite ajouter une commande a un TLabel pour ecrire ou non verticalement, j'ai lu les Tutoriels de CGI, et j'ai commence a me familiariser avec l'editeur de nouveaux composants, j'ai cependant quelques questions, si j'ai bien compris si l'on veu conserver l'integralite des proprietes du composant il faut les redefinir, ma premiere question est y a t'il un moyen de le faire automatiquement, la seconde question si on doit le faire manuellement, les proprietes qui on des sous-proprietes doit on les redefinir et comment le faire
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 376
    Points
    376
    Par défaut
    Bonjour,

    Si ton composant descend d'une classe de base abstraite (ex: TCustom ...), oui, il est nécessaire de redéclarer les propriétés que tu veux conserver. Cela permet notamment de supprimer les propriétés inutiles, il suffit de ne pas les déclarer.

    Pour les déclarer, une simple ligne __property dans la rubrique __published de la définition de ta classe suffit. Pas besoin de déclarer les sous-propriétés, elles sont implicites.

    Si ton composant descend d'une classe non abstraite (ex: TListBox), pas besoin de redéclarer les propriétés, ton composant en hérite automatiquement.

  3. #3
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci pour ta reponse josse95:
    Je suppose qu'il en est de meme pour les evenements OnClick...., ils se declarent dans la meme liste que les proprietees, et l'on declare ce que l'on veu conserver.
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 376
    Points
    376
    Par défaut
    Oui, c'est la même chose. ex: __property OnClick;

  5. #5
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci josse95:
    Je teste tout cela ce soir et je reposterai
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  6. #6
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Dans le composant je voudrais ajouter le code qui ajoute sur le Caption le saut de ligne, ce code fonctionne sur un TLabel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    //#include "StrUtils.hpp"
     
    AnsiString c;
    AnsiString d;
    AnsiString a = Label1->Caption;
    int b = (Label1->Caption).Length();
    for (int i = 1;i <= b;i++)
    {
    c = MidStr(a, i, 1);
    c = c + "\n";
    d = d + c;
    }
    Label1->Caption = d;
    Mais je ne sais pas recuper "Label1->Caption", je n'ai rien trouve comme renseignement a ce sujet
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 376
    Points
    376
    Par défaut
    Je ne sais pas si c'est ce que tu recherches, mais tu as deux fonctions privées:

    GetTextLen() qui te renvoie la longueur du Caption (sans le '\0') et GetTextBuf qui te permet de retrouver le texte du Caption:

    ex (à placer dans une fonction membre de ta classe dérivée):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    int len = GetTextLen();
    char *capt = new char(len+1);
    GetTextBuf(capt,len+1);
    ...
    delete capt;
    Tu as aussi SetTextBuf qui te permet de modifier le Caption.

  8. #8
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci josse95:
    Je ne suis vraiment pas doue
    Je n'ai pas teste mais quelque chose comme ceci devrait fonctionner.
    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
     
    // variables temporaires
    AnsiString tempc;
    AnsiString tempd;
     
    // on lit la longueur du Caption
    int Size = GetTextLen();
     
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
     
    // on reecrit la chaine du Caption
    for (int i = 1;i <= Size;i++)
    {
    tempc = MidStr(capt, i, 1);
    tempc = tempc + "\n";
    tempd = tempd + tempc;
    }
     
    // on ecrit le Caption
    SetTextBuf(tempd);
     
    delete capt;
    Le fait d'utiliser des AnsiString vat il poser probleme, car capt est en char et tempc et tempd sont des AnsiString?
    Y a t'il autre chose que capt a detruire?
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 376
    Points
    376
    Par défaut
    Effectivement, tu ne peux pas utiliser MidStr avec un char *.

    Cependant, il y a plus simple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    for (i=0;i<Size;i++)
    {
      tempd += capt[i];
      tempd += '\n';
    }

  10. #10
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Alors voila ou j'en suis:
    Le code .cpp:
    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
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "StrUtils.hpp"
    #include "LabelVertical.h"
    #pragma package(smart_init)
    //---------------------------------------------------------------------------
    // ValidCtrCheck is used to assure that the components created do not have
    // any pure virtual functions.
    //
    static inline void ValidCtrCheck(TLabelVertical *)
    {
            new TLabelVertical(NULL);
    }
    //---------------------------------------------------------------------------
    __fastcall TLabelVertical::TLabelVertical(TComponent* Owner)
            : TCustomLabel(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TLabelVertical::SetVertical(bool AVertical);
    // SetVertical modifie la variable FVertical qui est la valeur
    // renvoyee par la propriete
    if (AVertical != FVertical)
            {
            FVertical = AVertical;
            Invalidate();
            AdjustBounds();
            }
    //---------------------------------------------------------------------------
    AnsiString __fastcall TLabelVertical::GetLabelText();
    // redefinition de la fonction GetLabelText
    AnsiString tempc;
    if (FVertical)
    {
    // variable temporaire
    AnsiString tempd;
    // on lit la longueur du Caption
    int Size = GetTextLen();
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
    // on reecrit la chaine du Caption
    tempc = capt;
    tempd = "";
    for (i=0;i<Size;i++)
    {
      tempd += capt[i];
      tempd += '\n';
    }
    // on ecrit le Caption
    //SetTextBuf(tempd);
    delete capt;
    return tempd;
    }
    else
    {
    return capt;
    }
    //---------------------------------------------------------------------------
    // enregistrement du composant et affichage de son icone dans la^palette.
    // ici il est mis dans l'onglet "MesComposants"
    namespace Labelvertical
    {
            void __fastcall PACKAGE Register()
            {
                     TComponentClass classes[1] = {__classid(TLabelVertical)};
                     RegisterComponents("MesComposants", classes, 0);
            }
    }
    //---------------------------------------------------------------------------
    le code .h:
    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
     
    //---------------------------------------------------------------------------
    #ifndef LabelVerticalH
    #define LabelVerticalH
    //---------------------------------------------------------------------------
    #include <SysUtils.hpp>
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    //---------------------------------------------------------------------------
    class PACKAGE TLabelVertical : public TCustomLabel
    {
    private:
            // variable qui memorise la nouvelle propriete.
            bool FVertical;
    protected:
            // fonction qui modifie la nouvelle propriete.
            void __fastcall SetVertical(bool AVertical);
            AnsiString __fastcall GetLabelText();
    public:
            __fastcall TLabelVertical(TComponent* Owner);
    __published:
    // on reporte integralement les proprietes du TLabel
    // Properties
     __property Align;
     __property Alignment;
     __property Anchors;
     __property AutoSize;
     __property BiDiMode;
     __property Caption;
     __property Color;
     __property Constraints;
     __property Cursor;
     __property DragCursor;
     __property DragKind;
     __property DragMode;
     __property Enabled;
     __property FocusControl;
     __property Font;
     __property Height;
     __property HelpContext;
     __property HelpKeyword;
     __property HelpType;
     __property Hint;
     __property Layout;
     __property Left;
     __property Name;
     __property ParentBiDiMode;
     __property ParentColor;
     __property ParentFont;
     __property ParentShowHint;
     __property PopupMenu;
     __property ShowAccelChar;
     __property ShowHint;
     __property Tag;
     __property Top;
     __property Transparent;
     __property Visible;
     __property Width;
     __property WordWrap;
    // nouvelle propriete
     __property bool Vertical = (read=FVertical, write=SetVertical
    // Events
     __property FocusControl;
     __property OnClick;
     __property OnContextPopup;
     __property OnDblClick;
     __property OnDragDrop;
     __property OnDragOver;
     __property OnEndDock;
     __property OnEndDrag;
     __property OnMouseDown;
     __property OnMouseEnter;
     __property OnMouseLeave;
     __property OnMouseMove;
     __property OnMOuseUp;
     __property OnStartDock;
     __property OnStartDrag;
     __property PopupMenu;
    };
    //---------------------------------------------------------------------------
    #endif
    Je relis tout cela demain a tete reposee et je ferais une tentative de compilation.
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  11. #11
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 376
    Points
    376
    Par défaut
    ok, ce serait sympa si tu postais ton code définitif.

    Sinon, je pense à une chose. Cette semaine, j'ai posté un message pour écrire verticalement dans un TTabControl.

    http://www.developpez.net/forums/sho...d.php?t=323657

    La réponse qui m'a été donnée peut être utilisée pour ton problème à mon avis.

    En effet, en jouant sur lfEscapement et lfOrientation, tu peux faire en sorte que TextOut écrive verticalement comme tu le souhaites.

  12. #12
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci pour ta reponse josse95:
    Je ne saurais pas readapter ton code pour mon probleme (je ne le comprend pas)
    Je me suis apercu que j'ai declare des variables au mauvais endroit, et il faut que je revois mon ecriture normale.
    Si j'ai une solution qui fonctionne je la posterais
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  13. #13
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Voila les modifs que j'ai fait:
    Dans le .h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    protected:
            // fonction qui modifie la nouvelle propriete.
            void __fastcall SetVertical(bool AVertical);
            AnsiString __fastcall GetLabelText();
    // variable temporaire
    AnsiString tempc;
    AnsiString tempd;
    int Size;
    Dans le .cpp
    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
     
    // redefinition de la fonction GetLabelText
    if (FVertical)
    {
    // on lit la longueur du Caption
    Size = GetTextLen();
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
    // on reecrit la chaine du Caption
    tempc = capt;
    tempd = "";
    for (i=0;i<Size;i++)
    {
      tempd += capt[i];
      tempd += '\n';
    }
    // on ecrit le Caption
    //SetTextBuf(tempd);
    delete capt;
    return tempd;
    }
    else
    {
    // on lit la longueur du Caption
    Size = GetTextLen();
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
    // on reecrit la chaine du Caption
    tempc = "";
    tempd = "";
    for (i=0;i<Size;i++)
    {
    tempd = capt[i];
    switch (tempd)
    {
    case '\' :
    break;
    case 'n' :
    break;
    default :
    tempc += capt[i];
    }
    }
    delete capt;
    return tempc;
    }
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  14. #14
    Membre actif Avatar de Mattetfamilly
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    182
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 182
    Points : 201
    Points
    201
    Par défaut
    est ce que le code suivant ne serait pas plus simple?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    AnsiString Travail;
    int index;
    for(index=Label1->Caption.Length;index>1;index--)
    {
    Travail=Label1->Caption;
    Label1->Caption=Travail.Insert(index,"\n");
    }
    on aura tout vu...
    Mais où est-ce???...
    ------------------------------------------------------
    n'oublies pas les balises [code ][/code ]
    et le Tag

  15. #15
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Salut Mattetfamilly:
    Je m'inspire des exemples sur la creation d'un composant de CGI
    Ce n'est pas evident et l'on ne trouve pas grand chose comme renseignement.
    Je ne pense pas pouvoir appeler "Label1->Caption" car le composant n'est pas encore cree je cherche a ajouter conformement a l'inspecteur d'objets une commende true/false qui fasse basculer l'ecriture du TLabel soit horizontalement soit verticalement.
    J'ai du mal a comprendre comment les commandes sont captees et envoyees
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  16. #16
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Je n'arrive pas a compiler il me reste une double erreur sur une ligne.
    Code .cpp
    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
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "StrUtils.hpp"
    #include "LabelVertical.h"
    #pragma package(smart_init)
    //---------------------------------------------------------------------------
    // ValidCtrCheck is used to assure that the components created do not have
    // any pure virtual functions.
    //
    static inline void ValidCtrCheck(TLabelVertical *)
    {
            new TLabelVertical(NULL);
    }
    //---------------------------------------------------------------------------
    __fastcall TLabelVertical::TLabelVertical(TComponent* Owner)
            : TCustomLabel(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TLabelVertical::SetVertical(bool AVertical)
    // SetVertical modifie la variable FVertical qui est la valeur
    // renvoyee par la propriete
    if (AVertical != FVertical) <----Erreur ici
            {
            FVertical = AVertical;
            Invalidate();
            AdjustBounds();
            }
    //---------------------------------------------------------------------------
    AnsiString __fastcall TLabelVertical::GetLabelText()
    // on recupere le Caption du TLabel
    // redefinition de la fonction GetLabelText
    if (FVertical)
    {
    // on lit la longueur du Caption
    Size = GetTextLen();
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
    // on reecrit la chaine du Caption
    tempd = "";
    for (i=0;i<Size;i++)
    {
      tempd += capt[i];
      tempd += '\n';
    }
    // on ecrit le Caption
    //SetTextBuf(tempd);
    delete capt;
    return tempd;
    }
    else
    {
    // on lit la longueur du Caption
    Size = GetTextLen();
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
    // on reecrit la chaine du Caption
    tempc = "";
    tempd = "";
    for (i=0;i<Size;i++)
    {
    tempd = capt[i];
    switch (tempd)
    {
    case '\\' :
    break;
    case 'n' :
    break;
    default :
    tempc += capt[i];
    }
    }
    delete capt;
    return tempc;
    }
    //---------------------------------------------------------------------------
    // enregistrement du composant et affichage de son icone dans la^palette.
    // ici il est mis dans l'onglet "MesComposants"
    namespace Labelvertical
    {
            void __fastcall PACKAGE Register()
            {
                     TComponentClass classes[1] = {__classid(TLabelVertical)};
                     RegisterComponents("MesComposants", classes, 0);
            }
    }
    //---------------------------------------------------------------------------
    Code .h
    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
     
    //---------------------------------------------------------------------------
    #ifndef LabelVerticalH
    #define LabelVerticalH
    //---------------------------------------------------------------------------
    #include <SysUtils.hpp>
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    //---------------------------------------------------------------------------
    class PACKAGE TLabelVertical : public TCustomLabel
    {
    private:
            // variable qui memorise la nouvelle propriete.
            bool FVertical;
    protected:
            // fonction qui modifie la nouvelle propriete.
            void __fastcall SetVertical(bool AVertical);
            AnsiString __fastcall GetLabelText();
    // variable temporaire
    AnsiString tempc;
    AnsiString tempd;
    int Size;        
    public:
            __fastcall TLabelVertical(TComponent* Owner);
    __published:
    // on reporte integralement les proprietes du TLabel
    // Properties
     __property Align;
     __property Alignment;
     __property Anchors;
     __property AutoSize;
     __property BiDiMode;
     __property Caption;
     __property Color;
     __property Constraints;
     __property Cursor;
     __property DragCursor;
     __property DragKind;
     __property DragMode;
     __property Enabled;
     __property FocusControl;
     __property Font;
     __property Height;
     __property HelpContext;
     __property HelpKeyword;
     __property HelpType;
     __property Hint;
     __property Layout;
     __property Left;
     __property Name;
     __property ParentBiDiMode;
     __property ParentColor;
     __property ParentFont;
     __property ParentShowHint;
     __property PopupMenu;
     __property ShowAccelChar;
     __property ShowHint;
     __property Tag;
     __property Top;
     __property Transparent;
     __property Visible;
     __property Width;
     __property WordWrap;
    // nouvelle propriete
     __property bool Vertical = {read=FVertical, write=SetVertical, default=false};
    // Events
    // __property FocusControl;
     __property OnClick;
     __property OnContextPopup;
     __property OnDblClick;
     __property OnDragDrop;
     __property OnDragOver;
     __property OnEndDock;
     __property OnEndDrag;
     __property OnMouseDown;
     __property OnMouseEnter;
     __property OnMouseLeave;
     __property OnMouseMove;
     __property OnMouseUp;
     __property OnStartDock;
     __property OnStartDrag;
    // __property PopupMenu;
    };
    //---------------------------------------------------------------------------
    #endif
    les erreurs se produisent sur cette ligne if (AVertical != FVertical)
    [C++ Error] LabelVertical.cpp(30): E2333 Class member '_fastcall TLabelVertical::SetVertical(bool)' declared outside its class
    [C++ Error] LabelVertical.cpp(30): E2141 Declaration syntax error
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  17. #17
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 376
    Points
    376
    Par défaut
    Je ne sais pas si c'est ton code original, mais il manque une accolade { avant la ligne en question (ainsi qu'à la fin de la fonction d'ailleurs).

    Même chose pour GetLabelText.

  18. #18
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci josse95:
    C'est effectivement les accolades qui manquaient et quelques erreurs mineures maintenant cela fonctionne, apres avoir pose le TLabelVertical sur la Form en selection true ou false de la propriete Verticale le TLabelVertical s'ecrit soit Horizontalement soit Verticalement.
    Le code .cpp
    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
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "StrUtils.hpp"
    #include "LabelVertical.h"
    #pragma package(smart_init)
    //---------------------------------------------------------------------------
    // ValidCtrCheck is used to assure that the components created do not have
    // any pure virtual functions.
    //
    static inline void ValidCtrCheck(TLabelVertical *)
    {
            new TLabelVertical(NULL);
    }
    //---------------------------------------------------------------------------
    __fastcall TLabelVertical::TLabelVertical(TComponent* Owner)
            : TCustomLabel(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TLabelVertical::SetVertical(bool AVertical)
    // SetVertical modifie la variable FVertical qui est la valeur
    // renvoyee par la propriete
    {
    if (AVertical != FVertical)
            {
            FVertical = AVertical;
            Invalidate();
            AdjustBounds();
            }
    }
    //---------------------------------------------------------------------------
    AnsiString __fastcall TLabelVertical::GetLabelText()
    // on recupere le Caption du TLabel
    // redefinition de la fonction GetLabelText
    {
    if (FVertical)
    {
    // on lit la longueur du Caption
    Size = GetTextLen();
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
    // on reecrit la chaine du Caption
    tempd = "";
    for (i=0;i<Size;i++)
    {
      tempd += capt[i];
      tempd += '\n';
    }
    // on ecrit le Caption
    //SetTextBuf(tempd);
    delete capt;
    return tempd;
    }
    else
    {
    // on lit la longueur du Caption
    Size = GetTextLen();
    // on recupere le Caption
    char *capt = new char(Size+1);
    GetTextBuf(capt,Size+1);
    // on reecrit la chaine du Caption
    tempd = "";
    for (i=0;i<Size;i++)
    {
    switch (capt[i])
    {
    case '\\' :
    break;
    case 'n' :
    break;
    default :
    tempd += capt[i];
    }
    }
    delete capt;
    return tempd;
    }
    }
    //---------------------------------------------------------------------------
    // enregistrement du composant et affichage de son icone dans la^palette.
    // ici il est mis dans l'onglet "MesComposants"
    namespace Labelvertical
    {
            void __fastcall PACKAGE Register()
            {
                     TComponentClass classes[1] = {__classid(TLabelVertical)};
                     RegisterComponents("MesComposants", classes, 0);
            }
    }
    //---------------------------------------------------------------------------
    Le code .h
    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
     
    //---------------------------------------------------------------------------
    #ifndef LabelVerticalH
    #define LabelVerticalH
    //---------------------------------------------------------------------------
    #include <SysUtils.hpp>
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    //---------------------------------------------------------------------------
    class PACKAGE TLabelVertical : public TCustomLabel
    {
    private:
            // variable qui memorise la nouvelle propriete.
            bool FVertical;
    protected:
            // fonction qui modifie la nouvelle propriete.
            void __fastcall SetVertical(bool AVertical);
            AnsiString __fastcall GetLabelText();
    // variable temporaire
    AnsiString tempd;
    int Size;
    int i;        
    public:
            __fastcall TLabelVertical(TComponent* Owner);
    __published:
    // on reporte integralement les proprietes du TLabel
    // Properties
     __property Align;
     __property Alignment;
     __property Anchors;
     __property AutoSize;
     __property BiDiMode;
     __property Caption;
     __property Color;
     __property Constraints;
     __property Cursor;
     __property DragCursor;
     __property DragKind;
     __property DragMode;
     __property Enabled;
     __property FocusControl;
     __property Font;
     __property Height;
     __property HelpContext;
     __property HelpKeyword;
     __property HelpType;
     __property Hint;
     __property Layout;
     __property Left;
     __property Name;
     __property ParentBiDiMode;
     __property ParentColor;
     __property ParentFont;
     __property ParentShowHint;
     __property PopupMenu;
     __property ShowAccelChar;
     __property ShowHint;
     __property Tag;
     __property Top;
     __property Transparent;
     __property Visible;
     __property Width;
     __property WordWrap;
    // nouvelle propriete
     __property bool Vertical = {read=FVertical, write=SetVertical, default=false};
    // Events
    // __property FocusControl;
     __property OnClick;
     __property OnContextPopup;
     __property OnDblClick;
     __property OnDragDrop;
     __property OnDragOver;
     __property OnEndDock;
     __property OnEndDrag;
     __property OnMouseDown;
     __property OnMouseEnter;
     __property OnMouseLeave;
     __property OnMouseMove;
     __property OnMouseUp;
     __property OnStartDock;
     __property OnStartDrag;
    // __property PopupMenu;
    };
    //---------------------------------------------------------------------------
    #endif
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  19. #19
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    La c'est la deception mon composant a fonctionne une fois correctement maintenant quand je le place sur la Form j'ai de suite le message "abnormal programme terminaison"
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  20. #20
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 376
    Points
    376
    Par défaut
    La nuit porte conseil !
    Revois ça à tête reposée et ça ira mieux.

Discussions similaires

  1. l'écriture verticale et horizontale ?
    Par messahel dans le forum QuickReport
    Réponses: 2
    Dernier message: 10/10/2009, 18h00
  2. Mauvaise écriture verticale HTML
    Par ruru9 dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 07/05/2008, 00h02
  3. Ajouter une ligne verticale dans un graphique
    Par slayer23 dans le forum MATLAB
    Réponses: 18
    Dernier message: 17/07/2007, 09h01
  4. Réponses: 3
    Dernier message: 09/05/2007, 12h11
  5. Écriture verticale automatique avec css
    Par troumad dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 20/12/2006, 09h58

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