Link to home
Start Free TrialLog in
Avatar of ChrisLM
ChrisLMFlag for Australia

asked on

Best way to repeat a method over and over

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
Avatar of atul_parmar
atul_parmar
Flag of India image

Var
  Stop : Boolean;
begin
  Stop := False;
end
procedure MethodName;
begin
  repeat  
  //your logic
  Application.ProcessMessage;
  until Not Stop;
end;
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
? should it not be

...
  until Stop;
end;

meikl ;-)
Thanks meikl.

Var
  Stop : Boolean;
begin
  Stop := False;
end
procedure MethodName;
begin
  repeat  
  //your logic
  Application.ProcessMessage;
  until Stop;
end;
ASKER CERTIFIED SOLUTION
Avatar of Delphian
Delphian

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial