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
|
//---------------------------------------------------------------------------
#ifndef Unit7H
#define Unit7H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
struct minfo
{
AnsiString nom;
int age;
AnsiString metier;
};
class TForm7 : public TForm
{
__published: // Composants gérés par l'EDI
TListView *ListView1;
TEdit *Edit1;
TEdit *Edit2;
TEdit *Edit3;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TButton *Button3;
TButton *Button4;
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private: // Déclarations utilisateur
public: // Déclarations utilisateur
__fastcall TForm7(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm7 *Form7;
//---------------------------------------------------------------------------
#endif
// le cpp
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit7.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm7 *Form7;
// ---------------------------------------------------------------------------
__fastcall TForm7::TForm7(TComponent* Owner) : TForm(Owner) {
ListView1->ViewStyle = vsReport;
ListView1->Items->BeginUpdate();
for (int col(0); col < 4; col++)
ListView1->Columns->Add();
ListView1->Items->EndUpdate();
}
// ---------------------------------------------------------------------------
void __fastcall TForm7::Button3Click(TObject *Sender) {
minfo* n1 = new minfo(); // new record
// n1->nom = new char(Edit1->Text.Length()); // reservation Memoire Buffer
n1->nom = Edit1->Text;
n1->age = StrToInt(Edit2->Text);
n1->metier = Edit3->Text;
TListItem *LI;
LI = ListView1->Items->Add();
LI->Caption = ListView1->Items->Count;
LI->Data = n1;
}
// ---------------------------------------------------------------------------
void __fastcall TForm7::Button4Click(TObject *Sender) {
TListItem *LI;
minfo *n2;
ListView1->Items->BeginUpdate();
for (int i(0); i < ListView1->Items->Count; i++) {
LI = ListView1->Items->Item[i];
if (LI->SubItems->Count)
LI->SubItems->Clear(); // on efface la liste précédente si existante
n2 = (minfo*)LI->Data;
LI->SubItems->Add(n2->nom);
LI->SubItems->Add(n2->age);
LI->SubItems->Add(n2->metier);
}
ListView1->Items->EndUpdate();
}
// ---------------------------------------------------------------------------
void __fastcall TForm7::FormDestroy(TObject *Sender) {
TListItem *LI;
minfo *n2;
ListView1->Items->BeginUpdate();
for (int i(0); i < ListView1->Items->Count; i++) {
LI = ListView1->Items->Item[i];
n2 = (minfo*)LI->Data;
delete n2; // on libère les buffer
}
ListView1->Items->EndUpdate();
}
// --------------------------------------------------------------------------- |