ChrisLM
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
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
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
Do a search on Delphi's help, or even internet (google) for delphi threading and you'll find a lot of examples
Regards
Check out this example:
http://www.schulers.com/jpss/pascal/dthre.htm
http://www.schulers.com/jpss/pascal/dthre.htm
? should it not be
...
until Stop;
end;
meikl ;-)
...
until Stop;
end;
meikl ;-)
Thanks meikl.
Var
Stop : Boolean;
begin
Stop := False;
end
procedure MethodName;
begin
repeat
//your logic
Application.ProcessMessage ;
until Stop;
end;
Var
Stop : Boolean;
begin
Stop := False;
end
procedure MethodName;
begin
repeat
//your logic
Application.ProcessMessage
until Stop;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Stop : Boolean;
begin
Stop := False;
end
procedure MethodName;
begin
repeat
//your logic
Application.ProcessMessage
until Not Stop;
end;