Bonjour à tous,
A la compilation de mon programme j'obtiens une erreur au sein d'une procedure qui charge un fichier csv dans un TStringGrid.
Ce qui m'étonne c'est que l'erreur semble liée aux composants visuels qui compose mon interface graphique et qui n'interagissent même pas avec la dite procédure! En effet, quand je test ce morceau de code dans un programme de test, tout marche comme prévu. Quand je test au sein de mon projet de travail qui ne contient pas d'autre code mais juste les composants de l'interface graphique, l'erreur se déclare.
La procédure en question :
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 {CHARGER DIRECTEMENT.CSV DANS TABLEAU} procedure TWindow.LoadCSV(Filename: string; sg: TStringGrid); var i, j, Position, count, edt1: integer; temp, tempField : string; FieldDel: char; Data: TStringList; begin Data := TStringList.Create; FieldDel := ';'; Data.LoadFromFile(Filename); temp := Data[1]; count := 0; for i:= 1 to length(temp) do if copy(temp,i,1) = FieldDel then inc(count); edt1 := count+1; sg.ColCount := 5; // il y a 5 colonnes sg.RowCount := Data.Count +1; // il y a x lignes + 1 vide sg.FixedCols := 0; for i := 0 to Data.Count - 1 do begin temp := Data[i]; if copy(temp,length(temp),1) <> FieldDel then temp := temp + FieldDel; while Pos('"', temp) > 0 do begin Delete(temp,Pos('"', temp),1); end; for j := 1 to 5 do //for j := 1 to edt1 do begin Position := Pos(FieldDel,temp); tempField := copy(temp,0,Position-1); sg.Cells[j-1,i+1] := tempField; Delete(temp,1,length(tempField)+1); end; end; Data.Free; end;
Les lignes rapportant une erreur sont les suivantes (L27 et L34) :
Les messages d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Delete(temp,Pos('"', temp),1); Delete(temp,1,length(tempField)+1);
[dcc32 Erreur] Unit1.pas(119): E2066 Opérateur ou point-virgule manquant
[dcc32 Erreur] Unit1.pas(119): E2014 Instruction attendue, mais expression de type 'TButton' trouvée
[dcc32 Erreur] Unit1.pas(126): E2066 Opérateur ou point-virgule manquant
[dcc32 Erreur] Unit1.pas(126): E2014 Instruction attendue, mais expression de type 'TButton' trouvée
[dcc32 Erreur fatale] Project1.dpr(5): F2063 Impossible de compiler l'unité utilisée 'Unit1.pas'
A tout hasard, le code complet du projet qui provoque une erreur :
Et ici, le code du projet de test qui fonctionne :
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 unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Grids, Vcl.ComCtrls; type TWindow = class(TForm) PageCtrl: TPageControl; Tab1: TTabSheet; Tab2: TTabSheet; Tab3: TTabSheet; Memo1: TMemo; Label1: TLabel; LblDebug: TLabel; Panel1: TPanel; Panel2: TPanel; Panel3: TPanel; GridEdit: TEdit; Grid: TStringGrid; BtnSuppr: TButton; BtnAdd: TButton; Image: TImage; LblEName: TLabeledEdit; LblELoc: TLabeledEdit; Delete: TButton; Save: TButton; ScrBox: TScrollBox; Tile0: TPanel; Img0: TImage; Lbl0: TLabel; Timer: TTimer; OpenImage: TOpenDialog; procedure FormCreate(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } procedure LoadCSV(Filename: string; sg: TStringGrid); // charge le fichier dans le tableau end; var Window: TWindow; datapath: String; // chemins absolus vers les dossiers implementation {$R *.dfm} {CHARGER DIRECTEMENT.CSV DANS TABLEAU} procedure TWindow.LoadCSV(Filename: string; sg: TStringGrid); var i, j, Position, count, edt1: integer; temp, tempField : string; FieldDel: char; Data: TStringList; begin Data := TStringList.Create; FieldDel := ';'; Data.LoadFromFile(Filename); temp := Data[1]; count := 0; for i:= 1 to length(temp) do if copy(temp,i,1) = FieldDel then inc(count); edt1 := count+1; sg.ColCount := 5; // il y a 5 colonnes sg.RowCount := Data.Count +1; // il y a x lignes + 1 vide sg.FixedCols := 0; for i := 0 to Data.Count - 1 do begin temp := Data[i]; if copy(temp,length(temp),1) <> FieldDel then temp := temp + FieldDel; while Pos('"', temp) > 0 do begin Delete(temp,Pos('"', temp),1); end; for j := 1 to 5 do //for j := 1 to edt1 do begin Position := Pos(FieldDel,temp); tempField := copy(temp,0,Position-1); sg.Cells[j-1,i+1] := tempField; Delete(temp,1,length(tempField)+1); end; end; Data.Free; end; procedure TWindow.FormCreate(Sender: TObject); begin datapath := ExtractFilePath(Application.ExeName) +'../../datas/'; end; end.
Merci à vous !
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 unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids; type TWindow = class(TForm) Memo1: TMemo; Grid: TStringGrid; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } procedure LoadCSV(Filename: string; sg: TStringGrid); end; var Window: TWindow; datapath : String; implementation {$R *.dfm} {CHARGER DIRECTEMENT.CSV DANS TABLEAU} procedure TWindow.LoadCSV(Filename: string; sg: TStringGrid); var i, j, Position, count, edt1: integer; temp, tempField : string; FieldDel: char; Data: TStringList; begin Data := TStringList.Create; FieldDel := ';'; Data.LoadFromFile(Filename); temp := Data[1]; count := 0; for i:= 1 to length(temp) do if copy(temp,i,1) = FieldDel then inc(count); edt1 := count+1; sg.ColCount := 5; // il y a 5 colonnes sg.RowCount := Data.Count +1; // il y a x lignes + 1 vide sg.FixedCols := 0; for i := 0 to Data.Count - 1 do begin temp := Data[i]; if copy(temp,length(temp),1) <> FieldDel then temp := temp + FieldDel; while Pos('"', temp) > 0 do begin Delete(temp,Pos('"', temp),1); end; for j := 1 to 5 do //for j := 1 to edt1 do begin Position := Pos(FieldDel,temp); tempField := copy(temp,0,Position-1); sg.Cells[j-1,i+1] := tempField; // memo1.Lines.Add(tempfield); Delete(temp,1,length(tempField)+1); end; end; Data.Free; end; procedure TWindow.Button1Click(Sender: TObject); begin LoadCSV(Datapath + '1.csv', Grid) ; end; procedure TWindow.FormCreate(Sender: TObject); begin datapath := ExtractFilePath(Application.ExeName) +'../../datas/'; end; end.
Partager