Note that there are some explanatory texts on larger screens.

plurals
  1. POTDirectoryWatch not firing first time
    primarykey
    data
    text
    <p>I have a small application that is used to process some files made in another program. I use an older component by Angus Johnson called <code>TDirectoryWatch</code></p> <p>On my FormCreate I have the following code</p> <pre><code> DirectoryWatch := TDirectoryWatch.Create(self); DirectoryWatch.OnChange := FileAction; DirectoryWatch.Directory := Folders.Path(dirInput); DirectoryWatch.Active := True; </code></pre> <p>If the program is started and there is put a new file in the directory everything fires and runs OK. But if there is a file in the directory when the program is started nothing happens even if I make a call to FileAction(nil);</p> <p><code>FileAction</code> is the name of the procedure that handles the files</p> <p>I have a call to FileAction from a popupmenu and that handles the files in the directory</p> <p>So my question is: how to make sure that existing files are handled at program start?</p> <p>Or is there a better way to handle this problem.</p> <p>Added code for FileAction</p> <pre><code>procedure TfrmMain.FileAction(Sender: TObject); var MailFile: string; MailInfo: TMailInfo; ListAttachments: TstringList; i: integer; MailBody: string; begin for MailFile in TDirectory.GetFiles(Folders.Path(dirInput), CheckType) do begin if FileExists(MailFile) then begin MailInfo := TMailInfo.Create(MailFile); try if FileProcessing = False then begin Logfile.Event('Behandler fil: ' + MailFile); FileProcessing := True; MailBody := ''; Settings.Load; MailInfo.Load; Settings.Mail.Signature := ''; Settings.Mail.Subject := MailInfo.Subject; ListAttachments := TStringList.Create; ListAttachments.Clear; for i := 1 to MaxEntries do begin if (MailInfo.Attachment[i] &lt;&gt; '') and (FileExists(MailInfo.Attachment[i])) then ListAttachments.Add(MailInfo.Attachment[i]); end; for i := 1 to MaxEntries do begin MailBody := MailBody + MailInfo.MailBody[i]; end; try if MailBody &lt;&gt; '' then begin if MailInfo.SenderBcc then Mailing.Send(MailInfo.SenderMail, MailInfo.Recipient, MailInfo.SenderMail, MailInfo.Subject, MailBody, ListAttachments, True) else Mailing.Send(MailInfo.SenderMail, MailInfo.Recipient, MailInfo.Subject, MailBody, ListAttachments, True); end; finally ListAttachments.Free; end; FileProcessing := False; DeleteFile(MailFile); end; finally MailInfo.Free; end; end; end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload