bouddha69
Messages postés7Date d'inscriptionlundi 3 mai 2010StatutMembreDernière intervention11 janvier 2012
-
11 janv. 2012 à 11:18
fbalien
Messages postés251Date d'inscriptiondimanche 7 décembre 2003StatutMembreDernière intervention11 novembre 2016
-
11 janv. 2012 à 15:29
Bonjour,
J'avance petit à petit dans ma programmation et je suis presque au bout.
Il me reste un petit problème (qui en fait est vraiment embêtant).
J'ai une boucle For qui s'arrête au bout de 99 tours alors que j'ai 107 lignes et qu'il les lit toutes.
Voilà mes codes :
Je copie tout d'abord mon fichier
//Début routine de .obs(Comp3D) vers .xml(GnuGama)
procedure TFMain_tcglb.comp3d2gnugamaClick(Sender: TObject);
var
z, o : integer;
ligne, lignecor : string;
ligne_obs, ligne_cor : Type_Tab_Ligne;
N_Champs, N_Champs_cor : integer;
format, formatcor : boolean;
Tabobs : tab_observation;
Tabcor : tab_cor;
nomfic_obs1, nomfic_cor : string;
nomfic_gnu, nomfic_obs2 : string;
control, controlcor : Tcontrol;
commentaire, commentairecor : string;
sigma_add, sigma_mult, sigma : double;
fcor : textfile;
list_cor : TStringList;
NTabcor : integer;
OpenDialog1.FileName := '';
OpenDialog1.Title := 'Choix du nom du fichier coordonnées';
OpenDialog1.Filter:='Fichier Coordonnées (*.cor)|*.cor';
if OpenDialog1.Execute then
begin
nomfic_cor := OpenDialog1.FileName;
format:=FALSE;
// Chargement du fichier dans une TStringList
assignfile(fcor,nomfic_cor);
reset(fcor);
list_cor := TStringList.Create;
while (not(eof(fcor))) do begin
readln(fcor,ligne);
list_cor.Add(trim(ligne));
end;
closefile(fcor);
//showmessage(inttostr(list_cor.Count));
// decodage de la TStringList vers un TabObs
setlength (Tabcor, list_cor.Count);
NTabcor := 0;
for o := 0 to (list_cor.Count-1) do
begin
Tabcor[o].CH := list_cor.Strings[o] ;
if Tabcor[o].CH<>'' then
begin
lignecor := Copy(Tabcor[o].CH,1,1);
if (lignecor='0') or (lignecor='1') or (lignecor='2')
or (lignecor='3') then
begin
Tabcor[o].cod := Copy(Tabcor[o].CH,1,1);
Formatcor :=True;
Decoupe_Ligne(Tabcor[o].CH,ligne_cor,N_Champs_cor,commentairecor);
Tabcor[o].nompt := ligne_cor[1];
Tabcor[o].est := ligne_cor[2];
Tabcor[o].nord := ligne_cor[3];
Tabcor[o].alti:=ligne_cor[4];
Tabcor[o].sigm1:=ligne_cor[5];
Tabcor[o].sigm2:=ligne_cor[6];
NTabcor := NTabcor + 1;
end
else
begin
Tabcor[o].cod := '9';
end;
end;
end;
list_cor.Clear;
end;
Puis dans un second temps, je traite mes lignes pour les couper comme je le souhaite.
Var
ficgnu : TextFile;
i,j,l,c,m,index,p,r,g : integer;
observation : TLigne_obs;
cor : TLigne_cor;
last_code : string[1];
lecture : real;
k, n, Comm : string;
ouvert, houvert : Boolean;
q : char;
label etiquette1;
for i := 0 to (NTabcor-1) do begin
cor := Tabcor[i];
{******************** Ecriture des commentaires **********************}
if cor.cod='9' then begin
write(ficgnu,'<!--');
cor.ch := trim(cor.ch);
if (last_code <> cor.cod) then write(ficgnu,'');
delete(cor.ch,1,1);
if (cor.ch <> '') then
begin
p := Length(cor.ch);
For r := 1 to p do
begin
q := cor.ch[r];
if q = 'é' then q := 'e';
if q = 'è' then q := 'e';
if q = 'ê' then q := 'e';
if q = 'ë' then q := 'e';
if q = 'à' then q := 'a';
if q = 'â' then q := 'a';
if q = 'ä' then q := 'a';
if q = 'ù' then q := 'u';
if q = 'û' then q := 'u';
if q = 'ü' then q := 'u';
if q = 'î' then q := 'i';
if q = 'ï' then q := 'i';
if q = 'ô' then q := 'o';
if q = 'ö' then q := 'o';
if q = 'ÿ' then q := 'y';
if q = '°' then q := ' ';
cor.ch[r] := q;
end;
Comm := cor.ch;
end;
write(ficgnu,Comm);
last_code := cor.cod;
writeln(ficgnu,'-->');
end;
{******************** Coordonnées libres **********************}
if cor.cod='0' then begin
if (last_code <> cor.cod) then writeln(ficgnu,'');
cor.ch := '';
cor.ch:= cor.ch + format(' ',[cor.nompt,cor.est,cor.nord,cor.alti]);
writeln(ficgnu,cor.ch);
last_code := cor.cod;
end;
{******************** Coordonnées 3D fixées **********************}
if cor.cod='1' then begin
if (last_code <> cor.cod) then writeln(ficgnu,'');
cor.ch := '';
cor.ch:= cor.ch + format(' ',[cor.nompt,cor.est,cor.nord,cor.alti]);
writeln(ficgnu,cor.ch);
last_code := cor.cod;
end;
{******************** Coordonnées plani fixées **********************}
if cor.cod='2' then begin
if (last_code <> cor.cod) then writeln(ficgnu,'');
cor.ch := '';
cor.ch:= cor.ch + format(' ',[cor.nompt,cor.est,cor.nord,cor.alti]);
writeln(ficgnu,cor.ch);
last_code := cor.cod;
end;
{******************** Coordonnées alti fixées **********************}
if cor.cod='3' then begin
if (last_code <> cor.cod) then writeln(ficgnu,'');
cor.ch := '';
cor.ch:= cor.ch + format(' ',[cor.nompt,cor.est,cor.nord,cor.alti]);
writeln(ficgnu,cor.ch);
last_code := cor.cod;
end;
end;
bouddha69
Messages postés7Date d'inscriptionlundi 3 mai 2010StatutMembreDernière intervention11 janvier 2012 11 janv. 2012 à 14:39
En effet il manquait la déclaration de ma deuxième procédure où je dis que NTabcor est un integer.
Mais je ne le réinitialise pas car je veux qu'il garde la valeur prise dans la procédure 1 et elles sont liées.
En revanche, j'ai trouvé mon erreur.
Le fait de couper à 99 était une coïncidence. Je souhaitais incrémenter NTabcor à chaque boucle mais je l'avais placé trop tôt dans ma boucle. Il fallait qu'il s'incrémente aussi quand Tabcor[o].cod := '9'.
Je l'ai donc déplacé et mon problème est résolu.
Merci de votre aide. Je n'aurais sûrement jamais vu ce souci si je n'avais pas chercher de réponses à vos questions
fbalien
Messages postés251Date d'inscriptiondimanche 7 décembre 2003StatutMembreDernière intervention11 novembre 2016 11 janv. 2012 à 15:29
pour info si vous déclarez NTabcor dans chaque procédure ce n'est pas bon car dans ce cas la NTabcor cera une variable locale a chaque procédure
il faut donc déclarer NTabcor au niveau global