Ciao Alka,
grazie al tuo topic sono ritornato al vecchio meccanismo, meno problematico da gestire. Avrei un problema che non capisco da dove salta fuori:
Spiego il problema: alla prima chiamata della funzione non ho nessun tipo di errore o problema, invio i dati tramite seriale e ricevo la risposta correttamente; se richiamo la funzione per due volte consecutive, la seconda chiamata alla funzione mi genera errore di Invalid Pointer Operation sull'istruzione ApdComPort1.Freecodice:Function Polling(DID: PChar): PChar; export; StdCall; var ResponseBox : String; VerifyXor : byte; I : Integer; begin try if ApdComPort1 = nil then ApdComPort1 := TApdComPort.Create(nil); //Configuro la porta seriale e la apro per iniziare le comunicazioni ApdComPort1.ComNumber := 1; ApdComPort1.Baud := 9600; ApdComPort1.Parity := pNone; ApdComPort1.DataBits := 8; ApdComPort1.StopBits := 1; ApdComPort1.InSize := 128; ApdComPort1.Open := true; if Result <> nil then FreeMem(Result); if ApdComPort1.Open then begin //for N := 1 to Loop do //begin repeat repeat ResponseBox := DownloadPolling(StrToInt(DID)); until ResponseBox <> ''; VerifyXor := $00; if ResponseBox <> '' then begin for I := 1 to 103 do begin VerifyXor := VerifyXor xor Byte(ResponseBox[I]); end; //Verifico l'esito del VCR, se 0 è corretto altrimenti c'è stato qualche errore if VerifyXor = 0 then begin //I dati sono corretti e invio la stringa di ritorno che il box si aspetta inviando un ACK = Hex(06) ApdComPort1.PutString(Chr($01) + Chr($41) + Chr($31) + Chr($06)); //Chiudo la trasmissione con EOT ApdComPort1.PutString(Chr($04)); end else begin //I dati sono errati e invio la stringa di ritorno che il box si aspetta inviando un NACK = Hex(15) ApdComPort1.PutString(Chr($01) + Chr($41) + Chr($31) + Chr($15)); //Chiudo la trasmissione con EOT ApdComPort1.PutString(Chr($04)); end; end else begin ResponseBox := 'ERROR'; end; until VerifyXor = 0; //end; //Chiudo la porta di comunicazione //ApdComPort1.Open := false; end else begin ResponseBox := 'COM Port Close'; end; //Alloco memoria per contenere il valore di ritorno della funzione da passare al software GetMem(Result,104); //Copio il valore di ritorno nella variabile che la funzione ritorna Result := StrPCopy(Result, ResponseBox); finally ApdComPort1.Free; <---- ERRORE Invalid Pointer Operation end; end;
Perchè? Dove sbaglio?

Rispondi quotando