Jump to content

Is it not Possible UniSession.BrowserWindow in UniGUIServerModuleHTTPCommand ?


david600320@hotmail.com

Recommended Posts

Is it not Possible UniSession.BrowserWindow in UniGUIServerModuleHTTPCommand  ? 

 - Version 1.90.0.1514 , XE2 

In the ServerModule , I made a pdf file from FastReport (  makePdf())  and saved on the /files folder successed . 

What i want to show  the pdf file  on the new browser . but failed .

What am i wrong ?  

procedure TUniServerModule.UniGUIServerModuleHTTPCommand(
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
  var Handled: Boolean);
var
      r : string ;
      params : TStrings ;
      cHost : String ;
      cHostUrlPortPdfRepoPathFilename : String ;
begin

      ARequestInfo.ContentType := 'application/json;charset=utf-8;' ;  //success
      AResponseInfo.CustomHeaders.AddValue('Access-Control-Allow-Origin', '*');    //CORS
      AResponseInfo.CustomHeaders.AddValue('Access-Control-Allow-Credentials', 'true');    //CORS
      params :=   ARequestInfo.Params  ;

      //  109-2. FastReport -> pdfFile -> show pdfFile on the New BrowserWindow 
      if  UpperCase(ARequestInfo.URI) = UpperCase( '/report' ) then  begin

           Handled := true;
           r := '';
           r := MakePDF() ;  // (success getting pdf filename as files/Repo_200217184615048.pdf )

           cHostUrlPortPdfRepoPathFilename := ARequestInfo.Host + '/' + r ;
           cHostUrlPortPdfRepoPathFilename := StringReplace(  cHostUrlPortPdfRepoPathFilename , '\' , '/' , [rfReplaceAll, rfIgnoreCase] ) ;


           // failed below all . Read of address 00000017 )
           // (Errors both ) ( Access violation at address 007212DA in module 'fastReport_test.exe' )
           UniSession.UrlRedirect( cHostUrlPortPdfRepoPathFilename );
           UniSession.BrowserWindow( cHostUrlPortPdfRepoPathFilename , 0, 0, '_blank');

           //AResponseInfo.ContentText :=  cHostUrlPortPdfRepoPathFilename  ;

      end;



end;

 

thanks ,

Edited by david600320@hotmail.com
show error
Link to comment
Share on other sites

          in UniGUIServerModuleHTTPCommand. 

          [Solved] 
           pdfUrl := 'http://127.0.0.1:8077/files/Repo_200218085047701.pdf'
           ShellExecute(0, 'OPEN', PChar(pdfUrl), '', '', SW_SHOWNORMAL);

           

      Q. Is this only way to solve ?  

Link to comment
Share on other sites

8 hours ago, david600320@hotmail.com said:

@Oliver ,  Thank you for your help .

By the way , I am not clear that solved was a good way or not. 

( The Server is for only as Reporting-server independent of any Front-end ) 

Could you give me a better Idea ?  

 

 

ShellExecute not work on application as Service (HyperServer)

Use instead something like this (RunApp) :


function WTSQueryUserToken(SessionId: ULONG; var phToken: THandle): BOOL; stdcall; external 'Wtsapi32.dll';


procedure TBackUp.RunApp(Ma_cmdLine, Dossier: String);
var
  hToken: THandle;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  res: boolean;

begin

//============
//  RunApp  fonctionne uniquement en Service (HyperServer)   pas en debugMode
//  RunApp remplace le ShellExecute (pour Desktop version)
//============

   GetStartupInfo(StartupInfo);

   if WTSQueryUserToken(WtsGetActiveConsoleSessionID, hToken) then
   begin
     res := CreateProcessAsUser(hToken,
               Nil,
               PChar('cmd.exe /C ' + Ma_cmdLine),
               nil,
               nil,
               True,
               CREATE_NO_WINDOW,
               nil,
               PChar(Dossier),
               StartupInfo,
               ProcessInfo);

     if res then WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
   end;

end;


 

Link to comment
Share on other sites

@AbakSoft , Thanks for your kind explanation !!

// calling ....
       pdfUrl := 'http://127.0.0.1:8077/files/Repo_200218085047701.pdf'
       RunApp( ' chrome ' , pdfURL);

// function RunApp( Ma_cmdLine, Dossier : String )        
        ChromeBrowserPath  := 'cmd.exe /C ' + Ma_cmdLine + ' ' + Dossier ;

        res := CreateProcessAsUser(hToken,
               nil,
               PChar(ChromeBrowserPath),
               nil,
               nil,
               False,
               CREATE_NEW_CONSOLE,
               nil,
               nil,  // PChar(WorkDir),
               StartupInfo,
               ProcessInfo);

As I mentioned above,

I wanted to show a pdf file on the new google browser  but still Failed.  ( In Command line , ' chrome  http://127.0.0.1:8077/files/Repo_....pdf  is OK  - successed !! )

As Result   -  just 200 ok -  , Not showing !! 

What am i wrong ?  

 

Link to comment
Share on other sites

Sorry,

Not sure we are talking about the same thing. i wante to advise only if you will use after hyperserver (what is highly recommanded) then forget SHELLEXECUTE. Use instead RunApp (showed above).

 

Now about showing a pdf file, it's quit simple : seesee FastReport Demo (mega unigui Demo).

Regards.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...