voici un extrait de mon code :
procedure TForm1.lectureClick(Sender: TObject);
var
F:TextFile;
ligne:string;
numLigne : integer;
LongueurAExtraire : integer;
PartieAExtraire : TFileName;
LigneTrouvee : boolean;
LongueurLigne : integer;
SL : TStringList;
LigneSansCaracSpeciaux : string;
LongChaine : string;
SensRotation : string;
NumeroBloc : integer;
i : integer;
begin
for i:=0 to StringGridDecodageTrame.RowCount-1 do
StringGridDecodageTrame.Rows[i].Clear;
numLigne:=1;
NumeroBloc := 0;
LigneTrouvee := false;
If FileExists(chemin.Text)
then MessageDlg ('Le fichier existe', mtConfirmation, [mbok], 0);
// rempli les differentes entêtes des string grids
StringGridDecodageTrame.Cells[0,0]:='N°';
StringGridDecodageTrame.Cells[1,0]:='Type';
StringGridDecodageTrame.Cells[2,0]:='Taille';
StringGridDecodageTrame.Cells[3,0]:='X Début';
StringGridDecodageTrame.Cells[4,0]:='Y Début';
StringGridDecodageTrame.Cells[5,0]:='X Fin';
StringGridDecodageTrame.Cells[6,0]:='Y Fin';
StringGridDecodageTrame.Cells[7,0]:='X Centre';
StringGridDecodageTrame.Cells[8,0]:='Y Centre';
StringGridDecodageTrame.Cells[9,0]:='Rayon';
StringGridDecodageTrame.Cells[10,0]:='Nb caracs';
StringGridDecodageTrame.Cells[11,0]:='Texte';
// Assignation du Fichier
assignfile(F,chemin.Text);
MessageDlg ('Le fichier est assigné', mtConfirmation, [mbok], 0);
// ouverture du fichier F en lecture seul
reset(F);
MessageDlg ('Le fichier est initialisé', mtConfirmation, [mbok], 0);
// Récuperation du N° de la Tole grâce au nom du fichier
// et on supprime l'extension du fichier
PartieAExtraire:=ExtractFileName(chemin.Text);
nom.Caption:=trim(leftstr(PartieAExtraire,length(partieAExtraire)-4));
// Tant que l'on n'est pas a la fin du fichier, on effectue le traitement.
// cad que l'on lit ligne par ligne le fichier.mpg et on recueuille les infos
// que l'on aura besoin .
while not EOF(F) do
begin
// lecture dans notre chaine de caractere nommé ligne d'une ligne de
// notre fichier F qui a été déclaré comme étant un fichier texte
readln(F,ligne);
sendMessage(Memo1.Handle,WM_VSCROLL,SB_BOTTOM,0);
// on ajoute au memo chaque ligne contenu dans le fichier texte
Memo1.Lines.Add(ligne);
//Si on se trouve a la 5° ligne, on recherche la gamme de tole (nom)
{if (NumLigne = 5)then
begin
trim() permet de suprimer les espaces et les caractères spéciaux des début et fin de String
midstr() permet de Récupérer une chaîne (inconnue)
nom.caption:=Trim(midstr(ligne,10,5));
end;
}
if (NumLigne = 6) then
begin
Longueur.Caption:=trim(midstr(ligne,10,5));
Largeur.Caption:=trim(midstr(ligne, 24,4));
Epaisseur.Caption:=trim(rightstr(ligne,2));
end;
if (Ligne='53' )then
begin
//MessageDlg ('Ligne Trouvee est à True', mtConfirmation, [mbok], 0);
LigneTrouvee := true;
NumeroBloc := NumeroBloc+1;
end;
NumLigne:=NumLigne+1;
while (ligneTrouvee=true)do
begin
LigneSansCaracSpeciaux :=trim(ligne);
LongueurLigne := length(LigneSansCaracSpeciaux);
StringGridDecodageTrame.Cells[0,StringGridDecodageTrame.RowCount-1]
:= intToStr(NumeroBloc);
if (Ligne='54' ) then
begin
//MessageDlg ('Ligne Trouvee est à False', mtConfirmation, [mbok], 0);
ligneTrouvee := false;
end;
// SI LA LIGNE COMMENCE PAR LE SIGNE + OU LE SIGNE - il y a Mvt
if ((trim(leftstr(ligne,1))) = '+') or((trim(leftstr(ligne,1))) = '-') then
begin
// Si la ligne se termine par le signe - (Mouvement CIRCULAIRE)
if ((LongueurLigne > 10) and ((trim(rightstr(ligne,1))) = '-')) then
begin
//MessageDlg('la ligne se termine par -',mtConfirmation, [mbok], 0);
SL := TStringList.Create;
SL.Delimiter := '-';
SL.DelimitedText := ligne;
readln(F,ligne);
// Scrollbar pour memo1
sendMessage(Memo1.Handle,WM_VSCROLL,SB_BOTTOM,0);
// on ajoute au memo chaque ligne contenu dans le fichier texte
Memo1.Lines.Add(ligne);
NumLigne:=NumLigne+1;
end;
// Si la ligne se termine par le signe + (Mouvement CIRCULAIRE)
if ((LongueurLigne > 10) and (trim(rightstr(ligne,1)) = '+')) then
begin
SensRotation := '+';
StringGridDecodageTrame.Cells[9,StringGridDecodageTrame.RowCount-1]:=SensRotation;
SL := TStringList.Create;
SL.Delimiter := '+';
SL.DelimitedText := ligne;
if (SL[1] <> '') then
StringGridDecodageTrame.Cells[5,StringGridDecodageTrame.RowCount-1]:= SL[1];
if (SL[2] <> '')then
StringGridDecodageTrame.Cells[6,StringGridDecodageTrame.RowCount-1]:= SL[2];
if (SL[3] <> '')then
StringGridDecodageTrame.Cells[7,StringGridDecodageTrame.RowCount-1]:= SL[3];
if (SL[4] <> '')then
StringGridDecodageTrame.Cells[8,StringGridDecodageTrame.RowCount-1]:= SL[4];
readln(F,ligne);
// Scrollbar pour memo1
sendMessage(Memo1.Handle,WM_VSCROLL,SB_BOTTOM,0);
// on ajoute au memo chaque ligne contenu dans le fichier texte
Memo1.Lines.Add(ligne);
NumLigne:=NumLigne+1;
end;
// Si la ligne ne se termine ni par un - ni par un +
if ( ((trim(rightstr(ligne,1))<>'-') and
(trim(rightstr(ligne,1))<>'+'))
or (LongueurLigne <= 10)) then
begin
SL := TStringList.Create;
SL.Delimiter := '+';
SL.DelimitedText := ligne;
//MessageDlg(SL.Text,mtConfirmation, [mbok], 0);
StringGridDecodageTrame.Cells[5,StringGridDecodageTrame.RowCount-1]:= SL[1];
StringGridDecodageTrame.Cells[6,StringGridDecodageTrame.RowCount-1]:= SL[2];
readln(F,ligne);
// Scrollbar pour memo1
sendMessage(Memo1.Handle,WM_VSCROLL,SB_BOTTOM,0);
// on ajoute au memo chaque ligne contenu dans le fichier texte
Memo1.Lines.Add(ligne);
NumLigne:=NumLigne+1;
StringGridDecodageTrame.RowCount := StringGridDecodageTrame.RowCount+1;
end;
end
// SI LA LIGNE NE COMMENCE NI PAR + NI PAR -
else
begin
readln(F,ligne);
// Scrollbar pour memo1
sendMessage(Memo1.Handle,WM_VSCROLL,SB_BOTTOM,0);
// on ajoute au memo chaque ligne contenu dans le fichier texte
Memo1.Lines.Add(ligne);
NumLigne:=NumLigne+1;
end;
end;
end;
closefile(f);
end;