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 :

Problème de création de composant FMX


Sujet :

C++Builder

  1. #1
    Membre émérite
    Avatar de Gouyon
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    1 137
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 137
    Billets dans le blog
    5
    Par défaut Problème de création de composant FMX
    Bonjour à tous

    Voilà je suis en train de développer un composant FireMonkey. Il s'agit d'un composant qui affiche une courbe défilante. J'ai souhaité faire ce composant car j'ai besoin d'un affichage rapide et l'utilisation de TChart ne répondait pas au besoin.
    Je me suis inspiré de plusieurs tutoriels (https://sjrd.developpez.com/delphi/tutoriel/composants/ et http://docwiki.embarcadero.com/RADSt...osant_existant )

    Je suis parvenu à faire une première version de mon composant mais quand je le dépose sur une fiche j'ai systématiquement cette erreur qui s'affiche: Verrou d'objet non possédé

    Voici l'entête
    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
     
    //---------------------------------------------------------------------------
     
    #ifndef GraphicDefilantH
    #define GraphicDefilantH
    //---------------------------------------------------------------------------
    #include <System.SysUtils.hpp>
    #include <System.Classes.hpp>
    #include <FMX.Controls.hpp>
    #include <FMX.Types.hpp>
    //---------------------------------------------------------------------------
    class PACKAGE TGraphicDefilant : public TStyledControl
    {
    private:
    	String FFormatX;
    	String FFormatY;
        void __fastcall SetFormatX(const String Value);
    	void __fastcall SetFormatY(const String Value);
    protected:
    public:
    	__fastcall TGraphicDefilant(TComponent* Owner);
        void __fastcall Paint();
    __published:
    	__property String FormatX = {read = FFormatX, write = SetFormatX};
    	__property String FormatY = {read = FFormatY, write = SetFormatY};
    };
    //---------------------------------------------------------------------------
    #endif
    et 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
    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
     
    // ---------------------------------------------------------------------------
     
    #include <fmx.h>
     
    #pragma hdrstop
     
    #include "GraphicDefilant.h"
    #pragma package(smart_init)
    // ---------------------------------------------------------------------------
    // ValidCtrCheck est utilisée pour garantir que les composants créés n'ont pas
    // de fonctions virtuelles pures.
    //
     
    static inline void ValidCtrCheck(TGraphicDefilant *) {
    	new TGraphicDefilant(NULL);
    }
     
    // ---------------------------------------------------------------------------
    __fastcall TGraphicDefilant::TGraphicDefilant(TComponent* Owner)
    	: TStyledControl(Owner) {
    	FFormatX = "%3.2f";
    	FFormatY = "%3.2f";
    }
     
    // ---------------------------------------------------------------------------
    namespace Graphicdefilant {
    	void __fastcall PACKAGE Register() {
    		TComponentClass classes[1] = {__classid(TGraphicDefilant)};
    		RegisterComponents(L"Samples", classes, 0);
    	}
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TGraphicDefilant::Paint() {
    	TStyledControl::Paint();
     
    	double minY = -1;
    	double maxY = 1;
    	double minX = 0;
    	double maxX = 200;
    	TVarRec arga[1] = {(long double)minY};
    	String stYmin = Format(FormatY, arga, 0);
    	TVarRec argb[1] = {(long double)maxY};
    	String stYmax = Format(FormatY, argb, 0);
    	TVarRec argc[1] = {(long double)minX};
    	String stXmin = Format(FormatX, argc, 0);
    	TVarRec argd[1] = {(long double)minY};
    	String stXmax = Format(FormatX, argd, 0);
     
    	int marge = 4;
     
    	Canvas->Fill->Color = claWhite;
    	Canvas->FillRect(TRectF(0, 0, Width, Height), 0, 0, AllCorners, 100);
     
    	float HXtxt = Canvas->TextHeight(stXmin);
    	if (Canvas->TextHeight(stXmax) > HXtxt)
    		HXtxt = Canvas->TextHeight(stXmax);
     
    	float LYtxt = Canvas->TextWidth(stYmin);
    	if (Canvas->TextWidth(stYmax) > LYtxt)
    		LYtxt = Canvas->TextWidth(stYmax);
     
    	float HYtxt1 = Canvas->TextHeight(stYmax);
    	float HYtxt0 = Canvas->TextHeight(stYmin);
    	float LXtxt1 = Canvas->TextWidth(stXmax);
    	float LXtxt0 = Canvas->TextWidth(stXmin);
     
    	float Ay = marge + HYtxt1 / 2;
    	float Ax = marge + LYtxt + marge;
    	float Ox = Ax;
    	float Oy = Height - marge - HXtxt - marge;
    	float By = Oy;
    	float Bx = Width - marge - LXtxt1 / 2 - marge;
     
    	Canvas->Stroke->Color = claBlack;
    	Canvas->DrawRect(TRectF(Ax, Ay, Bx, By), 0, 0, AllCorners, 100);
     
    	Canvas->Fill->Color = claBlack;
    	Canvas->FillText(TRectF(marge, marge, marge + LYtxt, marge + HYtxt1),
    		stYmax, false, 1, TFillTextFlags() << TFillTextFlag::RightToLeft,
    		TTextAlign::Center, TTextAlign::Center);
    	Canvas->FillText(TRectF(marge, Oy - HYtxt0 / 2, marge + LYtxt,
    		Oy - HYtxt0 / 2 + HYtxt0), stYmin, false, 1,
    		TFillTextFlags() << TFillTextFlag::RightToLeft, TTextAlign::Center,
    		TTextAlign::Center);
    	Canvas->FillText(TRectF(Ox - LXtxt0 / 2, Oy + marge, Ox + LXtxt0 / 2,
    		Oy + marge + HXtxt), stXmin, false, 1,
    		TFillTextFlags() << TFillTextFlag::RightToLeft, TTextAlign::Center,
    		TTextAlign::Center);
    	Canvas->FillText(TRectF(Bx - LXtxt1 / 2, Oy + marge, Bx + LXtxt1 / 2,
    		Oy + marge + HXtxt), stXmax, false, 1,
    		TFillTextFlags() << TFillTextFlag::RightToLeft, TTextAlign::Center,
    		TTextAlign::Center);
    	Canvas->EndScene();
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TGraphicDefilant::SetFormatX(const String Value) {
    	FFormatX = Value;
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TGraphicDefilant::SetFormatY(const String Value) {
    	FFormatY = Value;
    }
    // ---------------------------------------------------------------------------
    Une idée d'où ça peut venir?

  2. #2
    Membre Expert
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Par défaut
    Salut, la solution est simple. Tu as un 'Canvas->EndScene();' et tu n'as jamais de 'Canvas->BeginScene();'

    Je te suggère de le mettre avant de débuter tes manipulations de Canvas:
    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
            Canvas->BeginScene();
    	Canvas->Stroke->Color = claBlack;
    	Canvas->DrawRect(TRectF(Ax, Ay, Bx, By), 0, 0, AllCorners, 100);
     
    	Canvas->Fill->Color = claBlack;
    	Canvas->FillText(TRectF(marge, marge, marge + LYtxt, marge + HYtxt1),
    		stYmax, false, 1, TFillTextFlags() << TFillTextFlag::RightToLeft,
    		TTextAlign::Center, TTextAlign::Center);
    	Canvas->FillText(TRectF(marge, Oy - HYtxt0 / 2, marge + LYtxt,
    		Oy - HYtxt0 / 2 + HYtxt0), stYmin, false, 1,
    		TFillTextFlags() << TFillTextFlag::RightToLeft, TTextAlign::Center,
    		TTextAlign::Center);
    	Canvas->FillText(TRectF(Ox - LXtxt0 / 2, Oy + marge, Ox + LXtxt0 / 2,
    		Oy + marge + HXtxt), stXmin, false, 1,
    		TFillTextFlags() << TFillTextFlag::RightToLeft, TTextAlign::Center,
    		TTextAlign::Center);
    	Canvas->FillText(TRectF(Bx - LXtxt1 / 2, Oy + marge, Bx + LXtxt1 / 2,
    		Oy + marge + HXtxt), stXmax, false, 1,
    		TFillTextFlags() << TFillTextFlag::RightToLeft, TTextAlign::Center,
    		TTextAlign::Center);
    	Canvas->EndScene();
    Pour ceux que sa intéresse le message d'exception EMonitorLockException en anglais est le suivant: Object lock not owned.

  3. #3
    Membre émérite
    Avatar de Gouyon
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    1 137
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 137
    Billets dans le blog
    5
    Par défaut
    Arghh je l'avais pas vu en fait il a du être effacé lors d'une édition du code et comme j'avais introduit d'autres éléments je pensais que ça venais de là

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

Discussions similaires

  1. [Lazarus] Création de composant - Problème à la création dans l'IDE
    Par Jon Shannow dans le forum Lazarus
    Réponses: 4
    Dernier message: 03/12/2012, 10h34
  2. [Lazarus] Problème de création de composant
    Par Gouyon dans le forum Lazarus
    Réponses: 24
    Dernier message: 05/11/2011, 23h25
  3. Problème : création de composants
    Par programaniac dans le forum VB.NET
    Réponses: 18
    Dernier message: 18/02/2008, 08h20
  4. Création de composants: Problème lors du Destroy
    Par fred64 dans le forum Langage
    Réponses: 17
    Dernier message: 13/12/2007, 22h42
  5. Réponses: 1
    Dernier message: 29/05/2007, 00h00

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