Bonjour,

Je suis sur un autre problème que j'ai du mal à résoudre, sans
doute à cause de mon niveau "débutant" en Delphi.

J'ai construit une fonction renvoyant un tableau multidimensionnel
(array of record). Mais dès que je veux alimenter la variable de
sortie "result", Delphi me retourne une "classe d'exception EAccessViolation
avec Violation d'accès à l'adresse 0056D8F0"... Le problème apparaît
après With result[0] Do...

Voici mon code :

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
 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, Spin, ExtCtrls, Menus, QComCtrls,ComCtrls,StrUtils,UnitWinMainGenerique, Unit2, ucanip,
  ModuleSecuriteBDD, ToolWin, Math, CommCtrl, ImgList;
 
type
 
Tab1 = record
   Id:Integer;
   Index1:Integer;
   Txt1:string;
   DIBitmask:string;
   SsIndex:Integer;
   SsTxt:string;
   Valeur:Integer;
   DIReadOnly:string;
   DINotify:string;
  end;
 
  Tab2 = Array of Tab1;
 
var
  Form1: TForm1;
  MessBox: Tform;
  PTab1 : Array of Tab1;
 
implementation
 
uses Unit3, Unit4;
 
{$R *.dfm}
 
function LocateParam(PStruct: Array of Tab1; Id:longint; valCan:longint; mode:string):Tab2;
var
  i:word;
  k,l,j:integer;
begin
  k:=-1;
  if(length(PStruct))=0 then exit;
  if(mode = 'ptext') then
  Begin
    while(PTab1[k].Id<>Id) Do
    Begin
      inc(k,1);
    End;
 
    j := k;
 
   //Chargement du paramètre demandé : du rang j au rang k
 
   For l:=j to k Do
   Begin
     With Result[l] Do
       Begin
        Id:=PStruct[k+l].Id;
        Index1:=PStruct[k+l].Index1;
        SsIndex:=PStruct[k+l].SsIndex;
        SsTxt:=PStruct[k+l].SsTxt;
        Valeur:=PStruct[k+l].Valeur;
        DIReadOnly:=PStruct[k+l].DIReadOnly;
        DINotify:=PStruct[k+l].DINotify;
       End;
     End;
   End
   Else
   Begin
    if(Id=0)then
    Begin
      With result[0] Do
      Begin 
        Id:=0;
        Index1:=0;
        SsIndex:=0;
        SsTxt:='';
        Valeur:=0;
        DIReadOnly:='';
        DINotify:='';
      End;
    End
    Else
    Begin
      for i:=0 to length(PStruct)-1 do
      Begin
        if PStruct[i].Id=Id then
        Begin
          k:=i;
 
          repeat
            if(PStruct[k].Valeur = (valCan)) then
            Begin
	 With result[0] Do
	 Begin
	   Id:=0;
	   Index1:=0;
	   SsIndex:=0;
	   SsTxt:='';
	   Valeur:=0;
  	   DIReadOnly:='';
                DINotify:='';
	 End;
            End;
 
            inc(k,1);
          until PStruct[k].Id<>Id;
          exit;
        End;
     End;
    End;
  end;
end;
J'appelle la fonction avec

SrchParam:=LocateParam(TabStruct,idStrcut,donnee,'unit');


Merci beaucoup pour votre aide, je suis bloqué.