Morning ! I got a little probleme here, every time i try to access on apdcomport1 or on timer_com i get a Violation access, on my .exe and at very low adress... i first think of bad declaration of the component or bad settings on the interface menu, i also try to change my com port.
I would like for my interface a RS232 Communication and i think AdpPortCom i good at this.
error message is : Access Violation at address 00630477 in module 'blabla.exe'. Read address 000003D0.
Here is the declaration of my variable, lib and fonction. (not the main)
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, OoMisc, AdPort, DefVar, AdExcept,u_msg;
type
TForm11 = class(TForm)
ApdComPort1: TApdComPort;
Timer1: TTimer;
Timer_com: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ApdComPort1TriggerData(CP: TObject; TriggerHandle: Word);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form11: TForm11;
Data:string ;
IndiceSortie : integer;
IndiceAux : byte;
Tx_com : array[1..5000]of ansichar ;
Rx_com : array[1..5000]of ansichar ;
handle1 : word;
procedure open_port_com; forward;
Procedure StoreConsigne(Var Data: string); forward;
implementation
{$R *.dfm}
uses U_main;
Here is one procedure who give's me trouble. (not in the main)
procedure open_port_com;
var
c: Ansichar;
{ handle1 est une variable application }
begin
with Form11 do
begin
try
ApdComPort1.ComNumber:= 1;//sysdata.PortCom;
ApdComPort1.open := false;
ApdComPort1.RS485Mode := false;
ApdComPort1.open := true;
ApdComPort1.RemoveAllTriggers;
c := chr(13);
{ caractère de déclenchement de l'évènement Ondatatrigger }
handle1 := Form11.ApdComPort1.addDatatrigger(c, false);
Timer_Com.Enabled := true;
except
on Ealreadyopen do { port série déja ouvert }
begin
Timer_Com.Enabled := false;
messagedlg(Str_Err_Com[1] + inttostr(ApdComPort1.comnumber) + Str_Err_Com[2] + Str_Err_Com[3], mTerror, [mbok], 1);
if messagedlg(Str_Err_Com[6], mtConfirmation, [mbYes, mbNo], 0) = mryes then
end;
on Ebadid do { port série innexistant }
begin
Timer_com.Enabled := false;
messagedlg(Str_Err_Com[4] + inttostr(ApdComPort1.comnumber) + Str_Err_Com[5], mTerror, [mbok], 1);
if messagedlg(Str_Err_Com[6], mtConfirmation, [mbYes, mbNo], 0) = mryes then
end;
end;
end;
end;
Lib of my main (Com is the unit upper)
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.ExtCtrls,
Vcl.Imaging.pngimage, Vcl.Grids,
U_Msg,DefVar,U_ModeMDP,U_Alerte,u_ValidationNet,U_ConsigneLancement,U_ArrUrgence,U_FinDeCycle,
U_ConfirmFerme, com ,Vcl.WinXPickers, Vcl.Menus, Vcl.Imaging.jpeg;
I Would like to know how if it is possible to track and resolve easily this type of error.
open_port_com
? MainForm.OnCreate? If yes, then check the creation order of your forms in the project options. It's very likely that your Form11 just isn't created yet!DataModule
. Like in your example it must also be created before use. See stackoverflow.com/questions/12625721/…