Solved

Best way to repeat a method over and over

Posted on 2006-07-03
8
187 Views
Last Modified: 2010-04-05
Hi,
   I have a method that checks if there is a smartcard inserted into the card-reader, and reads the data on the card and stores it into a database if it is inserted, otherwise it just exits the method.

The method looks as follows:
--------------------------------------------------------------------------------------------------------------------------------------------------
SmartC := CreateFile(PChar('COM' + IntToStr(1)), GENERIC_READ + GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0);

//Setup connection

If Card Inserted
   //Read Data
   //Write to database
else
  //Exit method

CloseHandle(SmartC);
--------------------------------------------------------------------------------------------------------------------------------------------------

What would be the best way to repeat this method.
I have put this method into a timer, and I get the result i'm after, but I think this would waste a lot of the CPU's processing power, considering the method is around 75 lines.

I'm using Delphi 7, and Win-XP

Regards,
Chris
0
Comment
Question by:ChrisLM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17029849
Var
  Stop : Boolean;
begin
  Stop := False;
end
procedure MethodName;
begin
  repeat  
  //your logic
  Application.ProcessMessage;
  until Not Stop;
end;
0
 
LVL 11

Expert Comment

by:calinutz
ID: 17030175
Also you could use a separate thread for doing the checking.
Do a search on Delphi's help, or even internet (google) for delphi threading and you'll find a lot of examples

Regards
0
 
LVL 11

Expert Comment

by:calinutz
ID: 17030430
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 17030926
? should it not be

...
  until Stop;
end;

meikl ;-)
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17031192
Thanks meikl.

Var
  Stop : Boolean;
begin
  Stop := False;
end
procedure MethodName;
begin
  repeat  
  //your logic
  Application.ProcessMessage;
  until Stop;
end;
0
 
LVL 4

Accepted Solution

by:
Delphian earned 500 total points
ID: 17112384
I don't like the busy wait idea of atul_parmar... It'll eat much more cpu (if I got it right)...
Your timer approach seems very reasonable, just set the timer to about 1/2 of second or a little more.

Anyway, giving a look at your method skeleton, seems that real processing really begins after the Card_Inserted flag is true. If so, you can simplify it to just look if the card is inserted and only setup the connection, read data and write to database after the detection of card_inserted... It will detect the card and just do the dirty work after the flag.

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question