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

Contribuez Delphi Discussion :

Liste non typée


Sujet :

Contribuez Delphi

  1. #1
    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 Liste non typée
    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
    unit c;
     
    interface
     
    uses
      SysUtils,Classes;
     
    type
      TCustomList=class;
     
      TMFiler=class
      private
        FMParams :TCustomList;
        FIndex :integer;
      public
        constructor Create(AList:TCustomList);
        procedure Read(var AItem);
        procedure Write(const AItem);
        property Idx : integer read FIndex write FIndex;
      end;
     
      TCustomList=class
      private
        FList  :TList;
        FAlloc :integer;
        FOnChange :TNotifyEvent;
        FUpdate   :boolean;
        FChanged  :boolean;
        FMFiler   :TMFiler;
        function Get(idx:integer):TMFiler;
        procedure Change();
      public
        constructor Create(AllocBy :integer);
        destructor Destroy();override;
        procedure Add(const AItem);
        procedure Delete(idx:integer);
        procedure Clear();
        function Count:Integer;
        procedure BeginUpdate();
        procedure EndUpdate();
        property Items[index:integer]:TMFiler read Get; default;
        property List : TList read FList;
        property Alloc : integer read FAlloc;
        property OnChange :TNotifyEvent read FOnChange write FOnChange;
      end;
     
    implementation
        uses dialogs;
    {================================================================
                               TMFiler                              +
    ================================================================}
    constructor TMFiler.Create(AList:TCustomList);
    begin
        if Assigned(AList) then
        FMParams := AList;
    end;
     
    procedure TMFiler.Read(var AItem);
    begin
      with FMParams do
      System.Move(Pointer(List[FIndex])^, AItem, Alloc);
    end;
     
    procedure TMFiler.Write(const AItem);
    begin
      with FMParams do
      System.Move(AItem, Pointer(List[FIndex])^, Alloc);
    end;
     
    {================================================================
                               TCustomList                          +
    ================================================================}
    constructor TCustomList.Create(AllocBy :integer);
    begin
     
      if AllocBy in [1..255] then
        FAlloc  :=AllocBy
       else
        raise Exception.Create('');
      FMFiler  :=TMFiler.Create(Self);
      FList:=TList.Create;
    end;
     
    destructor TCustomList.Destroy();
    begin
      Clear();
      FList.Free;
      inherited;
    end;
     
    procedure TCustomList.Change();
    begin
     
        if not FUpdate then
        try
          if Assigned(FOnChange) then
             FOnChange(Self);
     
        finally
          FChanged  :=false;
        end
        else
           FChanged  :=true;
    end;
     
    procedure TCustomList.BeginUpdate();
    begin
       FUpdate:=true;
    end;
     
    procedure TCustomList.EndUpdate();
    begin
       FUpdate:=false;
       Change();
    end;
     
    procedure TCustomList.Delete(idx:integer);
    begin
         dispose(FList[idx]);
         FList.Delete(idx);
         Change();
    end;
     
    procedure TCustomList.Add(const AItem);
    var
      NewItem:Pointer;
    begin
       GetMem(NewItem,FAlloc);
       System.Move(AItem, Pointer(NewItem)^, FAlloc);
       FList.Add(NewItem);    
       Change();
    end;
     
    procedure TCustomList.Clear();
    var
     i:integer;
    begin
       for i:= 0to FList.Count-1 do
       try
         FreeMem(FList[i]);
       except
       end;
      if FList.Count <>0 then
      FList.Clear();
      Change();
    end;
     
    function TCustomList.Count:Integer;
    begin
       result:=FList.Count;
    end
    ;
    function TCustomList.Get(idx:integer):TMFiler;
    begin
       FMFiler.Idx:=idx;
       result:= FMFiler;
    end;
     
     
    end.
    pour les entier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TCustomList.Create(SizeOf(integer));
    pour les double
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TCustomList.Create(SizeOf(double));
    pour les type record
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TCustomList.Create(SizeOf(TMatype));
    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
     
     var
     GList: TCustomList;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
       GList:= TCustomList.Create(SizeOf(integer));
    end;
     
    procedure TForm1.Button1Click(Sender: TObject);
    var
     i:integer;
     k:integer;
    begin
        for i:=0 to 100 do
            GList.Add(i);
     
     
        for i:=0 to 100 do
        begin
            GList[i].Read(K);
     
          listbox1.Items.Add(inttostr(K));
        end;
     
    end;
    ++++++++++++++++++++

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    707
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 707
    Points : 777
    Points
    777
    Par défaut
    Ça a l'air intéressant, j'ai l'impression que je vais pouvoir l'utiliser. Merci.

Discussions similaires

  1. vide une liste de type select
    Par naourass dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 15/04/2009, 09h05
  2. [W3C] Code item de liste non valide dixit w3c validator !!
    Par Christophe Charron dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 19/02/2006, 15h10
  3. [MySQL] Affichage en liste de type et de leurs sous-types
    Par Mitaka dans le forum PHP & Base de données
    Réponses: 12
    Dernier message: 09/11/2005, 14h33
  4. [TP] Constantes typées et non typées, variables
    Par poppels dans le forum Turbo Pascal
    Réponses: 3
    Dernier message: 26/10/2005, 23h00
  5. Recherche dans une liste non trié
    Par Oberown dans le forum Algorithmes et structures de données
    Réponses: 7
    Dernier message: 13/09/2004, 13h56

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