Jump to content
Sign in to follow this  
toufik

loop a table field

Recommended Posts

hello every on , i'm using this code to loop a sqllite database field called 'photos' and not doing the job for me 

im using a timer for that named tmr1 
where is the problem please thank you 

ps : this loop stop when one of  fields  value is empty 
tmr1.Enabled := False;
if not FDTableTask.IsEmpty and not FDTableTask.FieldByName('photos').IsNull and
FileExists(FDTableTask.FieldByName('photos').asString) then
  begin
 FDTableTask.next;
// ImageEnView2.PrepareTransition;
 // ImageEnView2.RunTransition( TIETransitionType( 1 + random( ord( High( TIETransitionType )) - 2 )), 550);
//  tmr1.Enabled := true;
 while  FDTableTask.EOF do begin
  FDTableTask.First;
end;
end;
tmr1.Enabled := true;

Edited by toufik

Share this post


Link to post
while  FDTableTask.EOF do begin
  FDTableTask.First;
end;

This is not correct first will move the cursor to the beginning of the query. You should call FDTableTask.Next, also if the loop contains only the call for the next record you can replace the loop with FDTableTask.Last to jumb to the last record.

Share this post


Link to post
Guest
6 hours ago, toufik said:

...

im using a timer for that named tmr1 

...

A Timer would be better for where a task needs to be monitored periodically, and preferably for short processing times.

 

Perhaps, it would be enough, you just use / create a "procedure" where the looping will be performed on your table.

 

This way, if an error occurs, an unforeseen event, you will have less chance of compromising and controlling your application.

 

You can even add one more parameter to "WHILE", to also observe if you pressed, for example, the "ESC" key to cancel the current or next processing, and thus finish the task as a whole .

 

Anyway, I think the "Timer" is unnecessary at this point. 

 

For example: in the google you can find more code for your help!


procedure prcCallMyTaskToAnimationMyPhotos;
var
  xLastKeyPressed: SmallInt;
begin
  // ... your code here
  while not(xLastKeyPressed = VK_ESCAPE) or not(xTable.EOF) do
  begin
    // your code necessary
    //
    // NOTES: or any other tech for control the "exit" by user!
    // 1) xLastKeyPressed := (GetKeyState(VK_ESCAPE) < 0); {or (GetKeyState(Ord(CharX)<0) } // or directly on "WHILE"
    //
    /// 2) Application.ProcessMessages; // in some point necessary to complete its "mission" and dont stuck your app!!!
    //
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  try { it's always good divide the task }
    prcCallMyTaskToAnimationMyPhotos;
  except
    // what do it?
  end;
end;

 

hug

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×