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 :

Comment créer un composant non graphique paramétré


Sujet :

Langage Delphi

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    803
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 803
    Points : 182
    Points
    182
    Par défaut Comment créer un composant non graphique paramétré
    Bonjour,

    Je souhaite créer un composant du type TBitsVector avec un paramétrage dans la fonction create du type :
    MonComposant:= TBitsVector.Create( NbTab, W,H ) où
    NBTab est le nombre de TBits que le composant utilisera qui seront de Size=W*H

    Un petit code source de la fonction constructor serait le bienvenu

    Merci Colorid

  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
    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
     
    type
      TBitsVector = class
      private
        fNbTab : integer;
        fW     : integer;
        fH     : integer;
        fSize  : integer;
        fTableau : array of byte; // ou autre
      public
        constructor Create(const aNbTab, aW, aH: integer);
        destructor Destroy; override;
      end;
     
     
    { TBitsVector }
     
    constructor TBitsVector.Create(const aNbTab, aW, aH: integer);
    begin
      fNbTab := aNbTab;
      fW     := aW;
      fH     := aH;
      fSize  := aW * aH;
      SetLength(fTableau, fSize);
    end;
     
    destructor TBitsVector.Destroy;
    begin
      SetLength(fTableau, 0);
      inherited;
    end;
    http://hdd34.developpez.com/cours/artpoo/

  3. #3
    Membre éprouvé
    Avatar de Montor
    Homme Profil pro
    Autre
    Inscrit en
    Avril 2008
    Messages
    879
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Avril 2008
    Messages : 879
    Points : 963
    Points
    963
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SetLength(fTableau,Ceil( (H*w) / 8));
    Dr.Who tu doits ajouter un property pour la lecture et ecrituredesbits

  4. #4
    Membre éprouvé
    Avatar de Montor
    Homme Profil pro
    Autre
    Inscrit en
    Avril 2008
    Messages
    879
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Avril 2008
    Messages : 879
    Points : 963
    Points
    963
    Par défaut
    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
      TabBits=class
      private
       FBits:TBits;
       FH   :integer;
       FW   :integer;
       FSize:integer;
       function Get_Bit(X,Y:integer):boolean;
       procedure Set_Bit(X,Y:integer;AValue:boolean);
       function Idx(X,Y:integer):integer;
       public
       constructor Create(AH,AW:integer);
       destructor Destroy();override;
       property BitXY[X,Y:integer]:boolean read Get_Bit write Set_Bit;
      end;
     
    implementation
    constructor TabBits.Create(AH,AW:integer);
    begin
      FBits:=TBits.Create();
      FH   :=AH;
      FW   :=AW;
      FSize:= AH * AW;
      FBits.Size:= FSize;
     
    end;
     
    destructor TabBits.Destroy();
    begin
      FBits.Free();
      inherited;
    end;
     
    function TabBits.Idx(X,Y:integer):integer;
    begin
     result:=(FW * Y)+X;
     if result >= FSize then
      raise Exception.Create('Error');
    end;
     
    function TabBits.Get_Bit(X,Y:integer):boolean ;
    begin
     result:= FBits[Idx(X,Y)];
    end;
     
    procedure TabBits.Set_Bit(X,Y:integer;AValue:boolean);
    begin
     FBits[Idx(X,Y)]:=AValue;
    end;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
    d:TabBits;
    begin
    d:=TabBits.Create(50,50);
    d.BitXY[49,49]:=false;
    end;

  5. #5
    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
    Citation Envoyé par Montor Voir le message
    Dr.Who tu doits ajouter un property pour la lecture et ecrituredesbits
    il l'as pas demandé ...

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

Discussions similaires

  1. Comment créer un composent logiciel graphique personnel
    Par sourire05 dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 16/04/2014, 17h18
  2. Réponses: 3
    Dernier message: 21/10/2010, 15h58
  3. Créer un événement non graphique
    Par Thorna dans le forum Général Java
    Réponses: 4
    Dernier message: 23/04/2007, 12h52
  4. [VS2005/C#] Comment créer un composant visuel .NET ?
    Par TeC_MaN dans le forum Visual Studio
    Réponses: 1
    Dernier message: 31/07/2006, 13h13
  5. Comment créer un composant graphique???
    Par Mickey.jet dans le forum Delphi .NET
    Réponses: 2
    Dernier message: 29/03/2006, 14h56

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