Valeur de retour d'une fonction : access violation

keguira Messages postés 4 Date d'inscription lundi 2 juin 2003 Statut Membre Dernière intervention 18 mai 2004 - 18 mai 2004 à 13:08
keguira Messages postés 4 Date d'inscription lundi 2 juin 2003 Statut Membre Dernière intervention 18 mai 2004 - 18 mai 2004 à 13:14
Bon alors voila :
j'ai une application qui recupere une trame, la lit et renvoi une erreur si la trame n'est pas valide. pour cela, j'affecte la valeur que je reçoit dans une string, l'analise avec une fonction, si elle est valide, la foonction retourne true sinon false.
Hors ça plante, normal quoi ..
Avec le mode pas à pas, j'ai pu constaté que ça buggait quand je sortais de ma fonction ValidTrame : cad que la valeur de result est bien mise à true ou a false mais quand on est au end de fin de la fonction, sa mouline dans le vide et pouf "access violation"

voila le source :

function TFrmModem.ValidTrame: Boolean;
var
Command : string;
EndofCalc : integer;
begin
result := True;
if not (ReceivedData[1] = START) and (ReceivedData[length(ReceivedData)] = STOP) then
begin
Result := False;
SendError(ERROR_COMMAND);
end;
Endofcalc := length(ReceivedData);
while (ReceivedData[endofcalc] <> SEPARATOR) do
dec(endofcalc);
Command := StringofChar(' ', EndOfCalc);
move(ReceivedData, Command, EndofCalc);
if not (ReadChecksum = DoChecksum(Command)) then
begin
Result := False;
SendError(ERROR_CHECKSUM);
end;
end; <------ c à ce niveau que le programme s'arrete

procedure TFrmModem.Timer1Timer(Sender: TObject);
begin
if (not Connected) and (ReceivedData <> '') then
begin
Timer1.Enabled := False;
if ValidTrame then <---j'appel ma fonction validtrame
begin
identification;
dbfClient.GoTop;
dbfClient.SetOrder(CLIENT_IDX_ID);
dbfClient.Seek(lblNoClient.Caption);
if (dbfClient.GetInteger('clt_auth') and UPDATES) = UPDATES then
begin
if (dbfClient.GetDate('clt_last') < date) then
sendBlackList; //envoyer liste rouge
end;
end
else
begin <----- on n'arrive pas ici
ReceivedData := '';
Timer1.Enabled := True;
end;
end;
end;

donc ça mouline dans le vide et au bout de 3 seconde à peut pres j'ai :

Echec du projet "....." avec le message : 'access violation at 0x00000000 : read of adress 0x00000000', processus stopé, utilisez le mode pas à pas.

Il est à signalé que la valeur result a l'air d'avoir été bien assignée à la valeur demandé quand on sort de la fonction .. enfin je crois.

Voila donc si quelu'un peut m'aider ...

1 réponse

keguira Messages postés 4 Date d'inscription lundi 2 juin 2003 Statut Membre Dernière intervention 18 mai 2004
18 mai 2004 à 13:14
apres verification, result n'est pas mis à false qd on fait une erreur ... cad quand validtrame:

function TFrmModem.ValidTrame: Boolean;
var
Command : string;
EndofCalc : integer;
begin
result := True;
if not (ReceivedData[1] = START) and (ReceivedData[length(ReceivedData)] = STOP) then
begin
Result := False;
SendError(ERROR_COMMAND);
end;
Endofcalc := length(ReceivedData);
while (ReceivedData[endofcalc] <> SEPARATOR) do
dec(endofcalc);
Command := StringofChar(' ', EndOfCalc);
move(ReceivedData, Command, EndofCalc);
if not (ReadChecksum = DoChecksum(Command)) then
begin
SendError(ERROR_CHECKSUM);
Result := False;
end;
end; <--- à ce niveau si je teste avec le debugger la valeur de result : il me dit valeur inaccessible
0
Rejoignez-nous