Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9214837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:03:43+00:00 2026-06-18T02:03:43+00:00

I have problem with delphi code… I have code: MAIN FORM unit MainForm; interface

  • 0

I have problem with delphi code… I have code:

MAIN FORM

unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, CPort, Menus, ComObj, StdCtrls;

type
  TMainForm = class(TForm)
    MainMenu1: TMainMenu;
    Berkas1: TMenuItem;
    Alat1: TMenuItem;
    erminal1: TMenuItem;
    ComPort1: TComPort;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure erminal1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses
  ChildForm;

{$R *.dfm}

procedure TMainForm.erminal1Click(Sender: TObject);
var
  ChildForm: TChildForm;
begin
  ChildForm := TChildForm.Create(Application);
  ChildForm.Show;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
  ComPort1.ShowSetupDialog;
end;

procedure TMainForm.ComPort1RxChar(Sender: TObject; Count: Integer);
var
  ComPort: TComPort;
  data: string;
begin
  inherited;
  ComPort := TComPort.Create(Self);
  ComPort1.ReadStr(data, 5);
  ChildForm.Memo1.Text := ChildForm.Memo1.Text+''+data+'';
end;

end.

CHILD FORM:

unit ChildForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj;

type
  TChildForm = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ChildForm: TChildForm;

implementation

uses
  MainForm;

{$R *.dfm}

procedure TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TChildForm.Button1Click(Sender: TObject);
begin
  MainForm.ComPort1.Open;
end;

end.

I want to show data input from my device to memo in child form. I put the comport component in main form. But when I run the program, it says:

Project Data.exe raised exception class EAccessViolation with message ‘Access violation at address 00466051 in module ‘Data.exe’. Read of address 000002F8′. Process stopped. Use Step or Run to continue.

How can i solve the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:03:44+00:00Added an answer on June 18, 2026 at 2:03 am

    There are many problems with your code as mentioned in the comments.

    To make a better implementation of your parent/child form interaction with the comport component,
    do as follows:

    Create a TDataModule (ex: DataModule1), put the comport component there.

    Now you can access the comport component from the main form and the child form.

    Add a private method to your child form:

    procedure TChildForm.ComPort1RxChar(Sender: TObject; Count: Integer);
    var
      data: string;
    begin
      DataModule1.ComPort1.ReadStr(data, 5);
      Self.Memo1.Text := Self.Memo1.Text+''+data+'';
    end;
    

    When you open the comport in the child form, set the comport OnRxChar event to your TChildForm.ComPort1RxChar method.

    In the TChildForm.OnClose event, set the comport OnRxChar event to nil and close the comport.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I'm using Delphi 2010 on Windows 7 and have a problem with single quotes
I have a problem. I have following x86 delphi code which is written in
I have a Delphi 6 app that uses an ActiveX DLL to interface to
Possible Duplicate: What's wrong with Delphi's “with” I am have a problem debugging code
I have a problem with setting Browsing Path in Delphi 2009: When I install
I have started using of generics in Delphi 2010 but I have a problem
I'm generating dynamic HTML inside Delphi. I have no problem displaying UTF-8 strings inside
We have a little annoying problem with our delphi 2007 IDE, from time to
I have quite a problem concerning the use of relational database concepts in Delphi

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.