Delphi上的组件单元违反访问

发布于 2025-02-10 05:45:42 字数 2995 浏览 1 评论 0原文

早晨 !我在这里遇到了一个小问题,每次尝试在apdcomport1上访问或在timer_com上访问我,我都会在.exe上访问违规行为,并且在非常低的地址上...我首先想到组件的不良声明或不良设置接口菜单,我也尝试更改我的COM端口。

我想要我的接口A rs232通信,我认为Adpportcom我擅长于此。

错误消息是:00630477在模块“ blabla.exe”中的访问违规。读取地址000003D0。

这是我的变量,lib和fonction的声明。 (不是主要的)

“具有组件的单位”

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;

这是一个给我麻烦的过程。 (不是在主)

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;

我的主(com是单位鞋面)的lib,

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;

我想知道是否可以轻松跟踪和解决此类型的错误。

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)

Unit with component

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文