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 :

Suppression d'un répertoire


Sujet :

Langage Delphi

  1. #1
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 51
    Points : 50
    Points
    50
    Par défaut Suppression d'un répertoire
    Bonjour à tous,
    Je reposte ce message ici car je me suis trompé la première fois et je ne sais pas ou est passé le mlessage. Désolé.

    Je voudrais supprimer un répertoire vide (ou non).
    le problème c'est que quoique j'utilise pour supprimer le répertoire, il faut que je ferme mon application pour que la suppression prenne effêt. Toutes les solutions fonctionnent :

    - removedir
    - removedirectory
    - Tshfileopstruct...

    j'ai essayé aussi de changer le répertoire courant (setcurrentdir) avant de supprimer mais a chaque fois le répertoire reste visible dans l'explorateur et lorsque je veux l'ouvrir ''acces refusé".
    Si j'essaye de recréer le répertoire sans quitter mon application par du code, le message est le même "acces refusé".
    Mon appli est dans C:\mon dossier\application.exe
    le dossier '1234' que je veux effacer est dans C:\mon dossier\machines\1234

    J'ai essayé tout ce que j'ai pu trouver sur le site comme méthode et je me pose la question si c'est pas mon ordi qui m'embète.
    je suis Adrminstrateur du PC. (delphi XE sur seven)

    Merci!

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 577
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 577
    Points : 25 225
    Points
    25 225
    Par défaut
    Veille à ne pas conserver de fichier ouvert par TON programme dans ce dossier
    La suppression refusée est problablement parce que tu libères mal un handle sur un fichier

  3. #3
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 51
    Points : 50
    Points
    50
    Par défaut
    Je vérifie cela ce soir dès que je peux.
    Je ne peux pas le faire maintenant.

    Merci pour l'info.

  4. #4
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 51
    Points : 50
    Points
    50
    Par défaut
    Bon là, je ne comprend toujours pas ou est l'erreur :

    c'est une appli qui me permet d'enregistrer des interventions sur des machines (date heure commentaire - pièce jointe s'il y en a).
    la liste des interventions est dans une listbox1 (résultat d'une recherche) et chaque intervention est stockée dans un répertoire portant le nom de la machine (edit1).
    j'utilise le jvrichedit1 parce que je veux pouvoir copier/coller une image dans le texte (rtf) .

    Merci de m'aider car je ne vois vraiment pas !

    je mets le code ci-après
    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
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
     
    unit Unit1;
     
    interface
     
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.IOutils, System.Variants, System.Classes,
      Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls,
      Vcl.ExtCtrls, Vcl.Menus, unit2, unit4, JvExStdCtrls, JvEdit, JvRichEdit,
      JvExComCtrls, JvDateTimePicker, Vcl.Buttons, shellapi, strutils;
     
    type
      TForm1 = class(TForm)
        StatusBar1: TStatusBar;
        Panel1: TPanel;
        JvRichEdit1: TJvRichEdit;
        MainMenu1: TMainMenu;
        Interventions1: TMenuItem;
        Nouvelle1: TMenuItem;
        Modifier1: TMenuItem;
        N1: TMenuItem;
        Supprimer1: TMenuItem;
        N2: TMenuItem;
        Rechecher1: TMenuItem;
        PopupMenu1: TPopupMenu;
        Panel2: TPanel;
        Button1: TButton;
        Button2: TButton;
        Shape3: TShape;
        ListBox2: TListBox;
        Label9: TLabel;
        DateTimePicker2: TDateTimePicker;
        DateTimePicker1: TDateTimePicker;
        ComboBox2: TComboBox;
        ComboBox1: TComboBox;
        Label2: TLabel;
        Label1: TLabel;
        Shape1: TShape;
        Shape2: TShape;
        Edit2: TEdit;
        Edit1: TEdit;
        Label3: TLabel;
        Label4: TLabel;
        Label5: TLabel;
        Shape4: TShape;
        JvEdit1: TJvEdit;
        Panel3: TPanel;
        Label7: TLabel;
        ComboBox3: TComboBox;
        Label6: TLabel;
        Edit3: TEdit;
        JvDateTimePicker1: TJvDateTimePicker;
        Button3: TButton;
        ListBox1: TListBox;
        SpeedButton1: TSpeedButton;
        Supprimerlapicejointeslectionne1: TMenuItem;
        Machies1: TMenuItem;
        NouvelleMachine1: TMenuItem;
        procedure FormResize(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure ComboBox3Change(Sender: TObject);
        procedure JvDateTimePicker1Change(Sender: TObject);
        procedure SpeedButton1Click(Sender: TObject);
        procedure Supprimerlapicejointeslectionne1Click(Sender: TObject);
        procedure PopupMenu1Popup(Sender: TObject);
        procedure ListBox2MouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure ListBox2Click(Sender: TObject);
        procedure ComboBox1Select(Sender: TObject);
        procedure ComboBox2Select(Sender: TObject);
        procedure Supprimer1Click(Sender: TObject);
        procedure Nouvelle1Click(Sender: TObject);
        procedure Modifier1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure ListBox1Click(Sender: TObject);
        procedure DateTimePicker1CloseUp(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure NouvelleMachine1Click(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
      modeintervention = (new,modify,del,lookup);
            // modeintervention = new, modify ou del quand selection menu
            // intervention vaut lookfor quand clic sur bouton Lancer recherche
      typerecherche = (machine,ordre,texte,date,tout);
     
    var
      Form1: TForm1;
      mode : modeintervention; // definition du mode en cours
      typer : typerecherche; // type de recherche
      valide : boolean;
      fichiermodifier : string;
      nummachine : string; // memorise le numero machine lors de l'ouverture d'une intervention
    const
      chemin = 'c:\franck\delphi projet\interventions XE2\machines\';
     
    implementation
     
     
    {$R *.dfm}
     
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    initialisation;
    //preparation des variables
    mode:= lookup; // mode recherche
    typer := machine;
    valide := true;  //determine qu'il n'y plus d'edition d'intervention en cours
    fichiermodifier := '';
    //preaparation des objets d'une nouvelle intervention
    edit1.Enabled := false;
    edit2.Enabled := false;
    combobox1.ItemIndex := 36; //Debut  9:00
    combobox2.ItemIndex := 37; //Fin    9:15
    datetimepicker1.Date := now; //actualiser a la date du jour du pc
    datetimepicker2.Date := now; //actualiser a la date du jour du pc
    button1.Enabled := false;
    button1.Caption := 'Non Valide';
    button2.Enabled := false;
    jvedit1.Enabled := false;
    combobox1.Enabled := false;
    combobox2.Enabled := false;
    datetimepicker1.Enabled := false;
    datetimepicker2.Enabled := false;
    statusbar1.Panels[0].Text := 'Mode Rechecher';
    statusbar1.Panels[1].Text := '';
    combobox3.ItemIndex := 0;
    label6.Caption := 'Entrez un numéro de machine :';
    form1.activecontrol := edit3; // le focus est sur l'edit de recherche
    speedbutton1.Enabled := false;
     
    end;
    //------------redimensionnement de la fenetre
    procedure TForm1.FormResize(Sender: TObject);
    begin
    //panel1
    panel1.Width := form1.Width - 190;
    //Zone de liste de recherche
    listbox1.Height := panel3.Height - 135;
    end;
    //-----------date sélectionnée pour la Recherche
    procedure TForm1.JvDateTimePicker1Change(Sender: TObject);
    begin
    edit3.Text := datetostr(jvdatetimepicker1.Date);
    end;
    //------------Ouverture de l'intervention sélectionnée
    procedure TForm1.ListBox1Click(Sender: TObject);
    var i : integer;
        itemlistbox : string;
    begin
      jvrichedit1.Visible := false;
      itemlistbox := leftstr(listbox1.Items[listbox1.ItemIndex],4);
      jvrichedit1.Lines.LoadFromFile(chemin+leftstr(listbox1.Items[listbox1.ItemIndex],4)+'\'+listbox1.Items[listbox1.ItemIndex]);
      statusbar1.Panels[2].Text := 'Nom du fichier : ' + listbox1.Items[listbox1.ItemIndex];
      edit1.Text := jvrichedit1.Lines[0];
      edit2.Text := jvrichedit1.Lines[1];
      jvedit1.Text := jvrichedit1.Lines[2];
      combobox1.Text := jvrichedit1.Lines[3];
      combobox2.Text := jvrichedit1.Lines[4];
      datetimepicker1.Date := strtodate(jvrichedit1.Lines[5]);
      datetimepicker2.Date := strtodate(jvrichedit1.Lines[6]);
      listbox2.Clear ;
      if strtoint(jvrichedit1.Lines[7]) > 0 then
        begin
        for i := 1 to strtoint(jvrichedit1.Lines[7]) do
          begin
          listBox2.Items.Add(jvrichedit1.Lines[i+7]);
        end;
      end;
      jvrichedit1.Lines.Delete(0); //numero machine 0
      jvrichedit1.Lines.Delete(0); //numéro ordre 1
      jvrichedit1.Lines.Delete(0); //titre 2
      jvrichedit1.Lines.Delete(0); //heure de debut 3
      jvrichedit1.Lines.Delete(0); //heure de fin 4
      jvrichedit1.Lines.Delete(0); //date debut 5
      jvrichedit1.Lines.Delete(0); //date de fin 6
      if strtoint(jvrichedit1.Lines[0]) >= 0  then //le nombre de pieces jointes 7
        begin
        for i := 1 to strtoint(jvrichedit1.Lines[0])+1 do
            jvrichedit1.Lines.Delete(0); // le chemin des pieces jointes
      end;
      jvrichedit1.Visible := true;
    end;
    //-----------Ouverture de la pièce jointe
    procedure TForm1.ListBox2Click(Sender: TObject);
    begin
    ShellExecute(Handle,'open',PChar(listbox2.Items[listbox2.ItemIndex]),
                              nil,nil,SW_SHOWNORMAL) ;
    end;
    //-----------Affichage de la ligne sélectionnée de la liste des pieces jointes
    procedure TForm1.ListBox2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    var APoint:TPoint;
    begin
      APoint.X :=X;
      APoint.Y :=Y;
      application.HintPause:=0; // temps pour que l'étiquette apparaisse
                                //(ici instantané)
      application.HintHidePause:=5000; //duree d'affichage de l'étiquette
      if listbox2.ItemAtPos(Apoint,true)>-1 then
        begin
        //listbox2.Hint := inttostr(listbox2.ItemAtPos(Apoint,false));
        listbox2.Hint := listbox2.Items[listbox2.ItemAtPos(Apoint,false)];
        application.ActivateHint(mouse.CursorPos);
      end;
    end;
    //------------MENU Modifier l'intervention
    procedure TForm1.Modifier1Click(Sender: TObject);
    begin
    if listbox1.ItemIndex>-1 then
      begin
      mode:= modify;
      nummachine := edit1.Text ;
      statusbar1.Panels[0].Text := 'Mode Modifier';
      valide := false;
      statusbar1.Panels[1].Text := 'Intervention en cours de modification';
      button1.Enabled := true;
      Button1.Caption := 'Modifier';
      button2.Enabled := true;
      jvedit1.Enabled  := true;
      edit1.Enabled := true;
      edit2.Enabled := true;
      jvedit1.ReadOnly  := false;
      combobox1.Enabled := true;
      combobox2.Enabled := true;
      speedbutton1.Enabled := true;
      datetimepicker1.Enabled := true;
      datetimepicker2.Enabled := true;
      jvrichedit1.ReadOnly := false;
      form1.activecontrol := edit1; // donne le focus sur le edit1
      fichiermodifier := listbox1.Items[listbox1.ItemIndex];
      statusbar1.Panels[2].Text := 'Nom du fichier : ' + fichiermodifier;
    end;
    end;
    //------------MENU Nouvelle intervention
    procedure TForm1.Nouvelle1Click(Sender: TObject);
    begin
    mode:= new;
    valide := false;
    edit1.Enabled := true;
    edit1.Text := '';
    edit2.Enabled := true;
    edit2.Text := '';
    jvedit1.Enabled  := true;
    jvedit1.Text := '';
    combobox1.Enabled := true;
    combobox1.ItemIndex := 36;
    combobox2.Enabled := true;
    combobox2.ItemIndex := 37;
    datetimepicker1.Enabled := true;
    datetimepicker1.Date := now;
    datetimepicker2.Enabled := true;
    datetimepicker2.Date := now;
    speedbutton1.Enabled := true;
    jvrichedit1.ReadOnly := false;
    jvrichedit1.Clear;
    listbox2.Clear;
    button1.Enabled := true;
    button1.Caption := 'Enregistrer';
    button2.Enabled := true;
    statusbar1.Panels[0].Text := 'Mode Nouveau';
    statusbar1.Panels[1].Text := 'Intervention en cours de modification';
    form1.activecontrol := edit1; // donne le focus sur le edit1
    end;
     
    procedure TForm1.NouvelleMachine1Click(Sender: TObject);
    begin
    form4.Show;
    end;
     
    //---------Affichage/Masquage du popup pièce jointe
    procedure TForm1.PopupMenu1Popup(Sender: TObject);
    begin
    if ((listbox2.Items.Count = 0) or
        (listbox2.ItemIndex = -1)) then popupmenu1.Items[0].Enabled := false;
    if ((listbox2.Items.Count > 0) and
        (listbox2.ItemIndex <> -1)) then popupmenu1.Items[0].Enabled := true;
    end;
    //-----------Bouton Piece jointe
    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var opendialog : Topendialog;
    begin
    opendialog := Topendialog.Create(self);
    opendialog.InitialDir := 'c:\';
    if opendialog.Execute then
      begin
      listBox2.Items.Add(opendialog.FileName);
      //copy du fichier piece jointe dans le répertoire pjointes
      CopyFile(PChar(opendialog.FileName),
              PChar(chemin+'pjointes\' + extractfilename(opendialog.FileName)), False);
    end;
    opendialog.Free;
    end;
    //-----------Menu Supprimer l'intervention
    procedure TForm1.Supprimer1Click(Sender: TObject);
    var buttonselected : integer;
        dossier : Tdirectory;
    begin
    mode:= del;
    statusbar1.Panels[0].Text := 'Mode Supprimer';
    buttonSelected := MessageDlg('L''intervention va être supprimée définitivement !'
                              + #10#13 + 'Voulez-vous vraiment la supprimer ?',mtconfirmation,
                                [mbYes,mbCancel], 0);
    // reponse oui
    if buttonSelected = mrYes then
      begin
      deletefile(chemin+leftstr(listbox1.Items[listbox1.ItemIndex],4)+'\' +
                                listbox1.Items[listbox1.ItemIndex]);
      removedir(chemin+leftstr(listbox1.Items[listbox1.ItemIndex],4));
      end;
      button3.Click; // mise a jour liste
      mode := lookup;
    end;
    //----------Menu POPUP Supprimer la pièce jointe
    procedure TForm1.Supprimerlapicejointeslectionne1Click(Sender: TObject);
    begin
    if (mode=modify) or (mode=new) then
      begin
      listBox2.Items.Delete(listbox2.ItemIndex);
    end;
    end;
    //----------Bouton Enregistrer/Modifier
    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
        buttonSelected : Integer;
        newfichiermodifier : string;
    begin
    if (edit1.Text = '') or (Jvedit1.Text = '') then
      begin
      showmessage('Le Minimum pour enregistrer une intervention est:' + #10#13 + #10 +
                  '                    un Numéro de machine' + #10#13 +
                  '                    un Titre d''intervention');
      form1.ActiveControl := edit1;
    end
    else
      begin
      if valide = false then
        begin
        // inscription dans Jvrichedit des éléments que l'on doit enregistrer
        jvrichedit1.Visible := false;
        jvrichedit1.Lines.Insert(0,edit1.Text);//numero machine
        jvrichedit1.Lines.Insert(1,edit2.Text);//numero ordre
        jvrichedit1.Lines.Insert(2,jvedit1.Text);//objet
        jvrichedit1.Lines.Insert(3,combobox1.Text);//heure debut
        jvrichedit1.Lines.Insert(4,combobox2.Text);//heure fin
        jvrichedit1.Lines.Insert(5,datetostr(datetimepicker1.Date));//date debut
        jvrichedit1.Lines.Insert(6,datetostr(datetimepicker2.Date));//date fin
        jvrichedit1.Lines.Insert(7,inttostr(listbox2.Count));//nombre pieces jointes
        if listbox2.Count > 0 then
          begin
          for i := 1 to listbox2.Count do
            begin
            jvrichedit1.Lines.Insert(i+7,listbox2.Items[i-1]);//chaque piece jointe
          end;
        end;
     
        // nouvelle intervention
        if mode = new then
          begin
          // enregistrement du nouveau fichier
          if directoryexists(chemin+edit1.Text) then
            begin
            jvrichedit1.Lines.SaveToFile(chemin + edit1.Text + '\' + edit1.Text +
                                                formatdatetime(' ddmmyyhhnnss',now)+'.int');
          end
          else
            begin
            setcurrentdir(chemin);
            if not createdir(edit1.Text) then
              raise exception.Create('Impossible de créer le répertoire')
            else
              begin
              jvrichedit1.Lines.SaveToFile(chemin + edit1.Text + '\' + edit1.Text +
                                                formatdatetime(' ddmmyyhhnnss',now)+'.int');
            end;
          end;
        end;
     
        // intervention modifiée
        if mode = modify then
          begin
          // vérification si le numéro machine a changer
          if edit1.Text <> nummachine then
            begin
            // afficher l'alerte
            buttonSelected := MessageDlg('Le numéro machine a changé !' + #10#13 +
                                    'Faut-il vraiment le modifer ?',mtconfirmation,
                                        [mbYes,mbCancel], 0);
            // reponse oui
            if buttonSelected = mrYes    then
              begin
              newfichiermodifier := edit1.Text + ' ' + copy(fichiermodifier,6,12); //je veux garder le reste du nom
                                                                                   //du nom de fichier
              showmessage('Le nouveau nom de l''intervention sera:'+#10#13 +
                            newfichiermodifier);
              // enregistrement du fichier modifier
              if directoryexists(chemin+edit1.Text) then
                begin
                jvrichedit1.Lines.SaveToFile(chemin + edit1.Text+'\'+newfichiermodifier+'.int');
                deletefile(chemin+leftstr(fichiermodifier,4)+'\' + fichiermodifier);  //j'efface l'ancien fichier qui
                                                                                      //changé de nom
                valide := true;
                button3.Click;
                fichiermodifier := '';
              end
              else
                begin  //creation du répertoire = numéro machine
                setcurrentdir(chemin);
                if not createdir(edit1.Text) then
                  raise exception.Create('Impossible de créer le répertoire')
                else
                  begin
                  jvrichedit1.Lines.SaveToFile(chemin + edit1.Text+'\'+newfichiermodifier+'.int');
                  deletefile(chemin+leftstr(fichiermodifier,4)+'\' + fichiermodifier);
                  valide := true;
                  button3.Click;
                  fichiermodifier := '';
                end;
              end;
              //if buttonSelected = mrCancel then ShowMessage('Cancel pressed');
            end; // fin si MrYes
          end //fin si numero machine a changé
          else //si edit1.Text = nummachine
            begin
            jvrichedit1.Lines.SaveToFile(chemin+leftstr(fichiermodifier,4)+'\'+ fichiermodifier);
          end; //   fin si edit1.Text <> nummachine
        end; // fin si mode = modify
      end; // fin si valide = false
     
      //remise en etat de Jvrichedit après sauvegarde ou annulation
      jvrichedit1.Lines.Delete(0); //numéro machine
      jvrichedit1.Lines.Delete(0); //numéro d'ordre
      jvrichedit1.Lines.Delete(0); //titre
      jvrichedit1.Lines.Delete(0); //heure debut
      jvrichedit1.Lines.Delete(0); //heure fin
      jvrichedit1.Lines.Delete(0); //date debut
      jvrichedit1.Lines.Delete(0); //date fin
      jvrichedit1.Lines.Delete(0); // nombre pieces jointes
      jvrichedit1.Visible := true;
      if listbox2.Count > 0 then
        begin
        for i := 1 to listbox2.Count do
          begin
          jvrichedit1.Lines.Delete(0); // le chemin des pieces jointes
        end;
      end;
      // passage en mode RECHERCHER
      valide := true;
      mode := lookup;
      statusbar1.Panels[0].Text := 'Mode Rechercher';
      button1.Enabled := false;
      button1.Caption := 'Non valide';
      button2.Enabled := false;
      edit1.Enabled := false;
      edit2.Enabled := false;
      jvedit1.Enabled  := false;
      combobox1.Enabled := false;
      combobox2.Enabled := false;
      datetimepicker1.Enabled := false;
      datetimepicker2.Enabled := false;
      jvrichedit1.ReadOnly := true;
      speedbutton1.Enabled := false;
    end;
    end;
     
    //----------Bouton ANNULER
    procedure TForm1.Button2Click(Sender: TObject);
    begin
    edit1.Text := '';
    edit1.Enabled := false;
    edit2.Text := '';
    edit2.Enabled := false;
    jvedit1.Text := '';
    jvedit1.Enabled := false;
    combobox1.ItemIndex := 36;
    combobox1.Enabled := false;
    combobox2.ItemIndex := 37;
    combobox2.Enabled := false;
    datetimepicker1.Date := now;
    datetimepicker1.Enabled := false;
    datetimepicker2.Date := now;
    datetimepicker2.Enabled := false;
    jvrichedit1.Clear;
    jvrichedit1.Enabled := false;
    listbox1.Clear;
    listbox2.Clear;
    listbox2.Enabled := false;
    speedbutton1.Enabled := false;
    edit3.Enabled := true;
    form1.activecontrol := edit3; // donne le focus sur le edit3
     
    valide := true;
    end;
    //----------Bouton RECHERCHER
    procedure TForm1.Button3Click(Sender: TObject);
    var Info,info2   : TSearchRec;
    numero : string; // nom répertoire a rechercher
    flag : boolean;
    begin
    if valide=false then
      begin
      showmessage('Une intervention est en cours d''édition !!!' + #10#13 +
                  'Il faut cliquer sur le bouton ENREGISTRER ou MODIFIER' +#10#13 +
                  'pour la valider ou alors sur le bouton ANNULER pour'+#10#13 +
                  'quitter l''édition');
      form1.activecontrol := edit1; // donne le focus sur le edit1
    end
    else
      begin
      listbox1.Clear;
      jvrichedit1.Visible := false;
      jvrichedit1.Clear;
        //---------------------
      if typer = tout then
        // TOUTes les interventions
        begin
        // je regarde si il y a un répertoire dans 'Machines'
        // si oui la réponse est  =0
        if findfirst(chemin+'*.*',fadirectory,info)=0 then    //si un répertoire, s prend les infos du répertoire
          begin
          repeat
            if (info.Name<>'.') and (info.Name<>'..') then  // ne pas prendre en compte
            //les . et .. placés en début de répertoire (sinon bouclage infini)
              begin
              if findfirst(chemin+info.Name+'\*.*',faanyfile,info2)=0 then
                begin
                repeat
                  if (info2.Name<>'.') and (info2.Name<>'..') and (info2.Attr<>16) then  // ne pas prendre en compte
                  //les . et .. placés en début de répertoire (sinon bouclage infini) et les sous-répertoires
                    begin
                    listbox1.items.Add(info2.Name) ;
                  end;
                until findnext(info2)<>0; // recherche du répertoire suivant
              end; //fin findfirst info2
            end; // fin if info.name<>
          until findnext(info)<>0; // recherche du répertoire suivant
        end; // fin findfist repertoire
        findclose(info); // libération des resources
        findclose(info2); // libération des resources
      end; //if typer = tout then
     
      // Numéro machine
      if typer = machine then
        begin
        // je regarde si il y a un répertoire dans 'Machines'
        // si oui la réponse est  =0 sinon un code d'érreur
        if findfirst(chemin+'*.*',fadirectory,info)=0 then    //si un répertoire, info prend les infos du répertoire
          begin
          numero := edit3.Text;
          flag := false;
          listbox1.Clear;
          repeat
            if (info.Name<>'.') and (info.Name<>'..') then  // ne pas prendre en compte
            //les . et .. placés en début de répertoire (sinon bouclage infini)
              begin
              if info.Name = numero then
                begin
                showmessage('le répertoire '+ info.Name + 'est présent!');
                flag := true;
              end;
            end;
          until findnext(info)<>0; // recherche du répertoire suivant
          //findclose(info); // libération des resources
          if flag then
            begin
            if findfirst(chemin+numero+'\*.*',faanyfile,info)=0 then    //si un fichier, s prend les infos du répertoire
              begin
              repeat
                if (info.Name<>'.') and (info.Name<>'..') and (info.Attr<>16) then  // ne pas prendre en compte
                //les . et .. placés en début de répertoire (sinon bouclage infini) et les sous-répertoires
                  begin
                  listbox1.items.Add(info.Name) ;
                end;
              until findnext(info)<>0; // recherche du répertoire suivant
            end; // fin findfirst fichier
          end; // fin flag
          //findclose(info); // libération des resources
        end; // fin findfist repertoire
        findclose(info); // libération des resources
      end; // fin if typer = machine then
    end; // fin else si valide
    if listbox1.Count=0 then
      begin
      showmessage('Pas d''intervention en rapport avec la recherche !');
    end;
    jvrichedit1.Visible := true;
    edit1.Text := '';
    edit2.Text := '';
    jvedit1.Text := '';
    combobox1.Text := '';
    combobox2.Text := '';
    datetimepicker1.Date := now;
    datetimepicker2.Date := now;
    jvrichedit1.Clear;
    end;
     
    //-----------Mode de recherche
    procedure TForm1.ComboBox3Change(Sender: TObject);
    begin
    if combobox3.ItemIndex = 0 then
      begin
      label6.Visible := true;
      edit3.Visible := true;
      label6.Caption := 'Entrez un numéro de machine';
      typer := machine;
      jvdatetimepicker1.Visible := false;
      edit3.Text := '';
      edit3.Width := 145;
      form1.activecontrol := edit3; // donne le focus sur l'edit de recherche
    end;
    if combobox3.ItemIndex = 1 then
      begin
      label6.Visible := true;
      edit3.Visible := true;
      label6.Caption := 'Entrez un numéro d''ordre';
      typer := ordre;
      jvdatetimepicker1.Visible := false;
      edit3.Text := '';
      edit3.Width := 145;
      form1.activecontrol := edit3; // donne le focus sur l'edit de recherche
    end;
    if combobox3.ItemIndex = 2 then
      begin
      label6.Visible := true;
      edit3.Visible := true;
      label6.Caption := 'Entrez une date';
      typer := date;
      jvdatetimepicker1.Visible := true;
      edit3.Text := '';
      edit3.Width := 125;
      form1.activecontrol := edit3; // donne le focus sur l'edit de recherche
    end;
    if combobox3.ItemIndex = 3 then
      begin
      label6.Visible := false;
      typer := tout;
      jvdatetimepicker1.Visible := false;
      edit3.Visible := false;
      edit3.Width := 145;
      form1.activecontrol := button3; // donne le focus sur le bouton de recherche
    end;
    end;
    //-----------Heure de debut
    procedure TForm1.ComboBox1Select(Sender: TObject);
    begin
    combobox2.ItemIndex := combobox1.ItemIndex + 1; // decalage de 1/4 d'heure
                                                    // par defaut
    form1.activecontrol := jvrichedit1; // donne le focus sur le jvrichedit
    end;
    //-----------Heure de fin
    procedure TForm1.ComboBox2Select(Sender: TObject);
    begin
    form1.activecontrol := jvrichedit1; // donne le focus sur le jvrichedit
    end;
    //-------------Mise a jour Date de fin
    procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
    begin
    datetimepicker2.Date := datetimepicker1.Date;
    end;
     
    end.

  5. #5
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 577
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 577
    Points : 25 225
    Points
    25 225
    Par défaut
    Pour ne pas avoir laisser le findclose ligne 568, tu ne libère pas les ressources du premier findfirst en 552 écrasé par celui en 571

    Je pense que SaveToFile du TJvRichEdit est fiable et ne laisse pas trainer un verrou

    J'ai survolé le code, il est trop long pour cerner tous les problèmes !
    refait ton indentation !
    Le nommage Label6, Edit3 n'est pas pérenne à long terme et n'aide pas du tout à comprendre !

    Pour extraire une extension, tu as ChangeFileExt et ExtractFileExt
    ExtractFileDir, ExtractFileName ...
    plus fiable que tes Copy et LeftStr

  6. #6
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 51
    Points : 50
    Points
    50
    Par défaut
    j'ai remis la ligne 568 en fonction mais c'est toujours pareil !
    j'ai viré tout ce qui n'a pas d'utilité dans le problème
    c'est moins long

    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
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
     
    unit Unit1;
     
    interface
     
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.IOutils, System.Variants, System.Classes,
      Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls,
      Vcl.ExtCtrls, Vcl.Menus, unit2, unit4, JvExStdCtrls, JvEdit, JvRichEdit,
      JvExComCtrls, JvDateTimePicker, Vcl.Buttons, shellapi, strutils;
     
     
      modeintervention = (new,modify,del,lookup);
            // modeintervention = new, modify ou del quand selection menu
            // intervention vaut lookfor quand clic sur bouton Lancer recherche
      typerecherche = (machine,ordre,texte,date,tout);
     
    var
      Form1: TForm1;
      mode : modeintervention; // definition du mode en cours
      typer : typerecherche; // type de recherche
      valide : boolean;
      fichiermodifier : string;
      nummachine : string; // memorise le numero machine lors de l'ouverture d'une intervention
    const
      chemin = 'c:\franck\delphi projet\interventions XE2\machines\';
     
    implementation
     
     
    {$R *.dfm}
     
     
     
    //------------Ouverture de l'intervention sélectionnée
    procedure TForm1.ListBox1Click(Sender: TObject);
    var i : integer;
        itemlistbox : string;
    begin
      jvrichedit1.Visible := false;
      itemlistbox := leftstr(listbox1.Items[listbox1.ItemIndex],4);
      jvrichedit1.Lines.LoadFromFile(chemin+leftstr(listbox1.Items[listbox1.ItemIndex],4)+'\'+listbox1.Items[listbox1.ItemIndex]);
     
    // je travaille les lignes du jvrichedit1 
     
     
    end;
    //-----------Ouverture de la pièce jointe
    procedure TForm1.ListBox2Click(Sender: TObject);
    begin
    ShellExecute(Handle,'open',PChar(listbox2.Items[listbox2.ItemIndex]),
                              nil,nil,SW_SHOWNORMAL) ;
    end;
     
    //-----------Menu Supprimer l'intervention
    procedure TForm1.Supprimer1Click(Sender: TObject);
    var buttonselected : integer;
        dossier : Tdirectory;
    begin
    mode:= del;
    buttonSelected := MessageDlg('L''intervention va être supprimée définitivement !'
                              + #10#13 + 'Voulez-vous vraiment la supprimer ?',mtconfirmation,
                                [mbYes,mbCancel], 0);
    // reponse oui
    if buttonSelected = mrYes then
      begin
      deletefile(chemin+leftstr(listbox1.Items[listbox1.ItemIndex],4)+'\' +
                                listbox1.Items[listbox1.ItemIndex]);
      removedir(chemin+leftstr(listbox1.Items[listbox1.ItemIndex],4));
      end;
      button3.Click; // mise a jour liste
      mode := lookup;
    end;
    //----------Bouton Enregistrer/Modifier
    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
        buttonSelected : Integer;
        newfichiermodifier : string;
    begin
    if (edit1.Text = '') or (Jvedit1.Text = '') then
      begin
      showmessage('Le Minimum pour enregistrer une intervention est:' + #10#13 + #10 +
                  '                    un Numéro de machine' + #10#13 +
                  '                    un Titre d''intervention');
      form1.ActiveControl := edit1;
    end
    else
      begin
      if valide = false then
        begin
        // inscription dans Jvrichedit des éléments que l'on doit enregistrer
        // nouvelle intervention
        if mode = new then
          begin
     
          // enregistrement du nouveau fichier
          if directoryexists(chemin+edit1.Text) then
            begin
            jvrichedit1.Lines.SaveToFile(chemin + edit1.Text + '\' + edit1.Text +
                                                formatdatetime(' ddmmyyhhnnss',now)+'.int');
          end
          else
            begin
            setcurrentdir(chemin);
            if not createdir(edit1.Text) then
              raise exception.Create('Impossible de créer le répertoire')
            else
              begin
              jvrichedit1.Lines.SaveToFile(chemin + edit1.Text + '\' + edit1.Text +
                                                formatdatetime(' ddmmyyhhnnss',now)+'.int');
            end;
          end;
        end;
     
        // intervention modifiée
        if mode = modify then
          begin
          // vérification si le numéro machine a changer
          if edit1.Text <> nummachine then
            begin
            // afficher l'alerte
            buttonSelected := MessageDlg('Le numéro machine a changé !' + #10#13 +
                                    'Faut-il vraiment le modifer ?',mtconfirmation,
                                        [mbYes,mbCancel], 0);
            // reponse oui
            if buttonSelected = mrYes    then
              begin
              newfichiermodifier := edit1.Text + ' ' + copy(fichiermodifier,6,12); //je veux garder le reste du nom
                                                                                   //du nom de fichier
              showmessage('Le nouveau nom de l''intervention sera:'+#10#13 +
                            newfichiermodifier);
              // enregistrement du fichier modifier
              if directoryexists(chemin+edit1.Text) then
                begin
                jvrichedit1.Lines.SaveToFile(chemin + edit1.Text+'\'+newfichiermodifier+'.int');
                deletefile(chemin+leftstr(fichiermodifier,4)+'\' + fichiermodifier);  //j'efface l'ancien fichier qui
                                                                                      //changé de nom
                valide := true;
                button3.Click;
              end
              else
                begin  //creation du répertoire = numéro machine
                setcurrentdir(chemin);
                if not createdir(edit1.Text) then
                  raise exception.Create('Impossible de créer le répertoire')
                else
                  begin
                  jvrichedit1.Lines.SaveToFile(chemin + edit1.Text+'\'+newfichiermodifier+'.int');
                  deletefile(chemin+leftstr(fichiermodifier,4)+'\' + fichiermodifier);
                  valide := true;
                  button3.Click;
                end;
              end;
            end; // fin si MrYes
          end //fin si numero machine a changé
          else //si edit1.Text = nummachine
            begin
            jvrichedit1.Lines.SaveToFile(chemin+leftstr(fichiermodifier,4)+'\'+ fichiermodifier);
          end; //   fin si edit1.Text <> nummachine
        end; // fin si mode = modify
      end; // fin si valide = false
     
      //remise en etat de Jvrichedit après sauvegarde ou annulation
     
      // passage en mode RECHERCHER
      valide := true;
      mode := lookup;
     
    end;
    end;
     
    //----------Bouton RECHERCHER
    procedure TForm1.Button3Click(Sender: TObject);
    var Info,info2   : TSearchRec;
    numero : string; // nom répertoire a rechercher
    flag : boolean;
    begin
    if valide=false then
      begin
      showmessage('Une intervention est en cours d''édition !!!' + #10#13 +
                  'Il faut cliquer sur le bouton ENREGISTRER ou MODIFIER' +#10#13 +
                  'pour la valider ou alors sur le bouton ANNULER pour'+#10#13 +
                  'quitter l''édition');
      form1.activecontrol := edit1; // donne le focus sur le edit1
    end
    else
      begin
      listbox1.Clear;
      jvrichedit1.Visible := false;
      jvrichedit1.Clear;
        //---------------------
      if typer = tout then
        // TOUTes les interventions
        begin
        // je regarde si il y a un répertoire dans 'Machines'
        // si oui la réponse est  =0
        if findfirst(chemin+'*.*',fadirectory,info)=0 then    //si un répertoire, s prend les infos du répertoire
          begin
          repeat
            if (info.Name<>'.') and (info.Name<>'..') then  // ne pas prendre en compte
            //les . et .. placés en début de répertoire (sinon bouclage infini)
              begin
              if findfirst(chemin+info.Name+'\*.*',faanyfile,info2)=0 then
                begin
                repeat
                  if (info2.Name<>'.') and (info2.Name<>'..') and (info2.Attr<>16) then  // ne pas prendre en compte
                  //les . et .. placés en début de répertoire (sinon bouclage infini) et les sous-répertoires
                    begin
                    listbox1.items.Add(info2.Name) ;
                  end;
                until findnext(info2)<>0; // recherche du répertoire suivant
              end; //fin findfirst info2
            end; // fin if info.name<>
          until findnext(info)<>0; // recherche du répertoire suivant
        end; // fin findfist repertoire
        findclose(info); // libération des resources
        findclose(info2); // libération des resources
      end; //if typer = tout then
     
      // Numéro machine
      if typer = machine then
        begin
        // je regarde si il y a un répertoire dans 'Machines'
        // si oui la réponse est  =0 sinon un code d'érreur
        if findfirst(chemin+'*.*',fadirectory,info)=0 then    //si un répertoire, info prend les infos du répertoire
          begin
          numero := edit3.Text;
          flag := false;
          listbox1.Clear;
          repeat
            if (info.Name<>'.') and (info.Name<>'..') then  // ne pas prendre en compte
            //les . et .. placés en début de répertoire (sinon bouclage infini)
              begin
              if info.Name = numero then
                begin
                showmessage('le répertoire '+ info.Name + 'est présent!');
                flag := true;
              end;
            end;
          until findnext(info)<>0; // recherche du répertoire suivant
          findclose(info); // libération des resources
          if flag then
            begin
            if findfirst(chemin+numero+'\*.*',faanyfile,info)=0 then    //si un fichier, s prend les infos du répertoire
              begin
              repeat
                if (info.Name<>'.') and (info.Name<>'..') and (info.Attr<>16) then  // ne pas prendre en compte
                //les . et .. placés en début de répertoire (sinon bouclage infini) et les sous-répertoires
                  begin
                  listbox1.items.Add(info.Name) ;
                end;
              until findnext(info)<>0; // recherche du répertoire suivant
            end; // fin findfirst fichier
          end; // fin flag
          findclose(info); // libération des resources
        end; // fin findfist repertoire
        findclose(info); // libération des resources
      end; // fin if typer = machine then
    end; // fin else si valide
    if listbox1.Count=0 then
      begin
      showmessage('Pas d''intervention en rapport avec la recherche !');
    end;
    jvrichedit1.Visible := true;
     
    end;
     
     
    end.

  7. #7
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 577
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 577
    Points : 25 225
    Points
    25 225
    Par défaut
    removedir, ne peut supprimer qu'un dossier vide !
    N'oublie pas cela !

    Est-ce que RemoveDir fonctionne sur un dossier bidon, juste pour tester ?

    Découpe plus ton code, Fait des fonctions !
    Sépare le mode new\modify pour avoir des fonctions plus courtes et donc plus facile à lire
    Encapsule les findfirst dans deux fonctions GetListFile et GetListDir qui stocke leur contenu dans un TStringList ou TStrings

    Réduire le nombre d'imbrication peu aussi être bénéfique, certaines des tes boucles comme celle du flag, tourne plus que réellement nécessaire

    Mettre tout le code derrière les OnClick n'est pas une bonne pratique,
    cela rend souvent le code confus et souvent beaucoup de code dupliqué !

    Utilise ChangeFileExt, ExtractFileExt, ExtractFileDir, ExtractFileName ...
    Tu nous compliques la vie avec tes LeftStr
    Idem IncludeTrailingPathDelimiter gère l'ajout de \


    Retire la JVCL :
    Si Bug, on aura écarté une piste
    Si plus Bug, tu seras où chercher !

    il est fort possible que le bug soit implicitement corrigé suite à ce refactoring !
    Il est important d'avoir un code clair et structuré !

    Tu as pensé au LoadFromFile aussi du TJvRichEdit ?
    Ou même le ShellExecute
    Tout ça ouvre du fichier, donc peu verrouiller le fichier et\ou le dossier !

    Nettoie le code, procède étape par étape,
    tu verras à partir de quel moment cela bloque

  8. #8
    Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 51
    Points : 50
    Points
    50
    Par défaut
    j'ai trouvé pourquoi cela ne marche pas .
    tu avais raison, lors de la recherche avec FindFirst

    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
    if findfirst(chemin+'*.*',fadirectory,info)=0 then    //si un répertoire, s prend les infos du répertoire
          begin
          repeat
            if (info.Name<>'.') and (info.Name<>'..') then  // ne pas prendre en compte
            //les . et .. placés en début de répertoire (sinon bouclage infini)
              begin
              if findfirst(chemin+info.Name+'\*.*',faanyfile,info2)=0 then
                begin
                repeat
                  if (info2.Name<>'.') and (info2.Name<>'..') and (info2.Attr<>16) then  // ne pas prendre en compte
                  //les . et .. placés en début de répertoire (sinon bouclage infini) et les sous-répertoires
                    begin
                    listbox1.items.Add(info2.Name) ;
                  end;
                until findnext(info2)<>0; // recherche du répertoire suivant
              end; //fin findfirst info2
            end; // fin if info.name<>
          until findnext(info)<>0; // recherche du répertoire suivant
        end; // fin findfist repertoire
        findclose(info); // libération des resources
        findclose(info2); // libération des resources
      end; //if typer = tout then
    je fermais findclose(info); avant findclose(info2);
    en inversant l'ordre de fermeture tout devient

    Je vais évidemment prendre toutes tes remarques avec le plus grand serieux pour m'améliorer
    Merci encore

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

Discussions similaires

  1. Réponses: 6
    Dernier message: 30/11/2007, 12h52
  2. Suppression d'un répertoire
    Par Zenerox dans le forum Langage
    Réponses: 2
    Dernier message: 07/09/2007, 18h25
  3. Suppression d'un répertoire
    Par tomtom187 dans le forum Entrée/Sortie
    Réponses: 4
    Dernier message: 07/09/2006, 17h19
  4. Probleme de suppression d'un répertoire
    Par selmak7 dans le forum C++Builder
    Réponses: 16
    Dernier message: 10/07/2006, 18h05
  5. [VB6] Suppression d'un répertoire et sous répertoire
    Par Tsien dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 24/01/2006, 13h37

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