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 8147941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:31:35+00:00 2026-06-06T14:31:35+00:00

i have developed application for read information from card reader. Here i have used

  • 0

i have developed application for read information from card reader. Here i have used timer for get the information each five second, so every five second the user interface getting slow
because it’s get the information from reader. how to run the timer in background with out affecting user interface

unit frmVistorreg;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;

type
 thread1=class(TThread)
 private
 FEvent: THandle;
 protected
 procedure Execute; override;
 public
 procedure MyTerminate;
end;


TForm3 = class(TForm)     
txt_name: TEdit;   
txt_cardno.Text  TEdit;        

private

public

end;

var
Form3: TForm3;

implementation

{$R *.dfm}


procedure thread1.Execute;
var
idcard_info :array[0..1024*5] of byte;
flag :Integer;
portflag :Integer;
st :TStrings;
str :string;  
begin

FEvent:= CreateEvent(nil, False, false, nil);
try
while not Terminated do begin
if  MainForm.PortFlag=0 then
begin

 Form3.Label11.Caption:='port has been successfully opened';
 Form3.Label11.Font.Color :=32768;
 flag := GetIdCardInfo(@idcard_info[0],1024*5,5);
 str := byteArray2Str(@idcard_info[0],1024*5);

        if(flag=0) then
        begin
           st := TStringList.Create;
           try
              SplitStr('^_^',str,st);
              Form3.txt_name.Text := st.Strings[0]; 
              Form3.txt_cardno.Text := st.Strings[5]; 
          finally
        st.Free;
          end;
        end;

end
else
begin 

Form3.Label11.Caption:='Please open the port';
Form3.Label11.Font.Color:=clRed;
end;

if WaitForSingleObject(FEvent, 500) <> WAIT_TIMEOUT // 5 seconds timeout
then Terminate;
end;

finally
CloseHandle(FEvent);
end;
end;


procedure thread1.MyTerminate;
begin
 SetEvent(FEvent);
end;


procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
var
Objthread1:thread1;
begin   
Objthread1.MyTerminate;
Action := caFree;
end;


procedure TForm3.FormCreate(Sender: TObject);
var
Objthread1:thread1;
begin
Objthread1:=thread1.Create(false);  
end;

end.

when i close the form have error like

Project MDIAPP.exe raised exception class EAccessViolation with message 'Access violation at address 0051B9F1 in module 'MDIAPP.exe'. Read of address 00000198'.

how can i solve this.

  • 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-06T14:31:37+00:00Added an answer on June 6, 2026 at 2:31 pm

    You need not a timer component for that, you need a background thread. A simplest solution is to use Sleep function in the thread:

    unit Unit2;
    
    interface
    
    uses
      Classes;
    
    type
      TMyThread = class(TThread)
      protected
        procedure Execute; override;
      end;
    
    implementation
    
    procedure TMyThread.Execute;
    begin
      while not Terminated do begin
    // do your processing here
        Sleep(5000);   // wait 5 seconds
      end;
    end;
    
    end.
    

    A better approach is to use WaitForSingleObject and an event instead of Sleep to be able to terminate your background thread immediately without 5 seconds delay:

    unit Unit2;
    
    interface
    
    uses
      Windows, Classes;
    
    type
      TMyThread = class(TThread)
      private
        FEvent: THandle;
      protected
        procedure Execute; override;
      public
        procedure MyTerminate;
      end;
    
    implementation
    
    procedure TMyThread.Execute;
    begin
      FEvent:= CreateEvent(nil, False, False, nil);
      try
        while not Terminated do begin
    // do your processing here
    // ..
          if WaitForSingleObject(FEvent, 5000) <> WAIT_TIMEOUT // 5 seconds timeout
            then Terminate;
        end;
      finally
        CloseHandle(FEvent);
      end;
    end;
    
    procedure TMyThread.MyTerminate;
    begin
      SetEvent(FEvent);
    end;
    
    end.
    

    To terminate TMyThread instance on closing a form call MyTerminate method from OnClose event handler of a form.

    And yes, it is interesting to know what error message you receive, not just ‘showing error’.

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

Sidebar

Related Questions

I have simple C# console application developed in Visual Studio 2008, which writes information
i have developed application while running my application another application ContactManager is also get
I have developed the application in which i want to set the background color
I have developed a application for a client who uses windows 7 home premium
I have developed my application in .Net and my installer is working fine. Now
I am new to iPhone world. I have developed an application, which I would
I have developed a window application in VS2005 using C#. I need to integrate
i have developed an web application[ERP FOR A SCHOOL].i have given the build for
I have developed a Win32 application using C/C++, which runs on Vista and XP.
I have developed my iPhone application and now I am testing it with instruments

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.