Page 2 of 2 FirstFirst 1 2
Results 16 to 18 of 18

Thread: Event na openen bestand

  1. #16
    Ik had heel dit stukje in een TThread staan omdat hier een bestand geopend kan worden en mijn programma gewoon door kan werken.

    Als dat niet hoeft dan kun je dit natuurlijk ook gewoon buiten een TThread doen.
    Dan hoef je dit alleen in een procedure te zetten.

    Zoiets:
    Delphi Code:
    1. procedure OpenAndExecute(FTempFile: String);
    2. var
    3.   // Ext: string;
    4.   exInfo: TShellExecuteInfo;
    5. begin
    6.  
    7.   // ================================================
    8.   // ShellExecute
    9.   // ================================================
    10.   FillChar(exInfo, SizeOf(exInfo), 0);
    11.   with exInfo do
    12.   begin
    13.     cbSize := SizeOf(exInfo);
    14.     lpVerb := nil; // Defaults to 'open'.
    15.     fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
    16.     Wnd := Application.Handle;
    17.     LpFile := pChar(FTempFile);
    18.     lpDirectory := nil; // Defaults to current directory.
    19.     LpParameters := nil;
    20.     // nShow := SW_SHOWNORMAL;
    21.     nShow := SW_SHOW;
    22.   end;
    23.  
    24.   // ================================================
    25.   // cCppException       = $0EEFFACE; { used by BCB }
    26.   // ================================================
    27.   if ShellExecuteEx(@exInfo) then
    28.   begin
    29.     Waitforsingleobject(exInfo.HProcess, infinite);
    30.     CloseHandle(exInfo.HProcess);
    31.   end
    32.   else
    33.   begin
    34.     ShowMessage(SysErrorMessage(GetLastError));
    35.   end;
    36.  
    37.   // ================================================
    38.  
    39.   // toch even wachten tot file niet meer in gebruik is
    40.   while FileIsInUse(FTempFile) do
    41.   begin
    42.     Application.ProcessMessages;
    43.     Sleep(1000);
    44.   end;
    45.  
    46.   // SaveAndClose;
    47.  
    48. end;

    Op het moment van Waitforsingleobject() zal je programma natuurlijk wel blijven wachten.

    Als je wilt hebben dat je programma gewoon door blijft lopen dan gebruik je dit dus in een TThread.

  2. #17
    John Kuiper
    Join Date
    Apr 2007
    Location
    Almere
    Posts
    8,747
    Wij ondertekenen ook bepaalde PDF d.m.v. een USB token. Daarvoor gebruik ik deze code;
    Delphi Code:
    1. procedure TMailreport.ExecuteAndWait(const aCommando: string);
    2. var
    3.   tmpStartupInfo: TStartupInfo;
    4.   tmpProcessInformation: TProcessInformation;
    5.   tmpProgram: String;
    6. begin
    7.   tmpProgram := trim(aCommando);
    8.   FillChar(tmpStartupInfo, SizeOf(tmpStartupInfo), 0);
    9.   with tmpStartupInfo do
    10.   begin
    11.     cb := SizeOf(TStartupInfo);
    12.     dwFlags := STARTF_USESHOWWINDOW; // <---- toegevoegd
    13.     wShowWindow := SW_SHOW;          // <---- gewijzigd
    14.   end;
    15.   if CreateProcess(nil, pchar(tmpProgram), nil, nil, true, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
    16.     nil, nil, tmpStartupInfo, tmpProcessInformation) then
    17.   begin
    18.     // loop every 10 ms
    19.     while WaitForSingleObject(tmpProcessInformation.hProcess, 10) > 0 do
    20.       sleep(1000);
    21.     CloseHandle(tmpProcessInformation.hProcess);
    22.     CloseHandle(tmpProcessInformation.hThread);
    23.   end
    24.   else
    25.   begin
    26.     RaiseLastOSError;
    27.   end;
    28. end;
    Deze start een batchbestand op, start het programma voor de hantekening en sla deze op met een andere naam. Die naam neem ik weer terug in mijn programma en stuur de pdf met de mail.
    Delphi is great. Lazarus is more powerfull

  3. #18
    Quote Originally Posted by jkuiper View Post
    Wij ondertekenen ook bepaalde PDF d.m.v. een USB token. Daarvoor gebruik ik deze code;
    Maar bij die code moet je volgens mij wel eerst het juiste programma ophalen die bij een .PDF hoort.
    (ShellExecuteEx doet dat zelf)

    Maar het principe is inderdaad hetzelfde.
    (Overigens is dit ook in een TThread zie ik )

Page 2 of 2 FirstFirst 1 2

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •