Results 1 to 10 of 43

Thread: Luna Game Pascal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by Thyandyr View Post
    I agree single file help chm or pdf is more appealing.
    Yes single file help does seem appealing. But the problem with .chm (Microsoft compiled HTML Help) is proprietary technology owned by Microsoft so there are probably some limitation of where you can use it. So if you are thinking about supporting any other platform besides Windows you would probably have to change it.

  2. #2
    @Thyandyr, ahh... glad you got that working. I know right, computers.

    @SilverWarior, again very good points you've brought out.

    For now, I think I will go with HTML files. I got the integration in and working. I can context search just like with a .CHM now. It automatically themes, blah blah... again all the advantages of direct control. Plus, it will provide some "future proofing" if/when I decide to move to other platforms.

    Interestingly, I dug up some tech I made some time ago (one of my many unfinished projects, haha) where I was able to take the raw html file help system, compress to a zip. I installed an protocol handler (for example lgp://index.html), this would fire an event and I could then fetch the files from inside the zip and display them as normal. This totally worked..... at that time. However, I played around a few hours last night trying to get it work, sadly I was not able to. I know its doable, just have to figure out why the protocol handler is not being initialized properly. Anyway, maybe I can get that working at some point.
    Last edited by drezgames; 20-06-2017 at 08:38 PM.

  3. #3
    Physics example,

    I changed

    body := Physics_CreatePolygonBody(MousePos.X, MousePos.Y, Random_Rangef(10, 45), Random_Rangei(4, 4), 1000);

    to make heavy squares.

    I see funny "non physical" effects, like pivot point in the center of the sqare keeping them floating. Very entertaining but perhaps not intended behaviour.

  4. #4
    Haha, cool! Still tweaking the physics engine. More work to be done on it for sure. Thanks for giving it a workout!

  5. #5
    Quote Originally Posted by piradyne View Post
    However, I played around a few hours last night trying to get it work, sadly I was not able to. I know its doable, just have to figure out why the protocol handler is not being initialized properly. Anyway, maybe I can get that working at some point.
    Are you trying to initialize the protocol system wide or in scope use user login session?
    You sad that you dug up this tech from long time ago. So I'm guessing it probably predates the UAC (User Account Control) that has been introduced with Windows Vista.

    Also does this new protocol only registers for Internet Explorer or is it made available for any installed Browser?

  6. #6
    @SilverWarior

    I found the protocol stuff here.
    I used it before to build the help system and it worked before for me. It will register the protocol and setup a callback within the current process and then remove it on shutdown. I think the issue maybe related to DLL vs EXE. I did some more test last night and placed into an EXE and it will register properly then. I got the files coming in from the HTML folder via the handler and I feed that to browser. It displays the help system interface, but when I click on a link, it then tries to load internet explorer. Not sure what is going on now. This was working perfectly before (maybe 2-3 years ago I think). I got the mime types correct. I see some javascript errors too. Maybe you can figure something out.

    Note, the examples work, they are simple static html files. I'm reading in a webhelp system generated by Help & Manual. It could be related to the template too. The more complex ones, im seeing a race condition when it loads, but the classic webhelp template loads just fine. I can navigate around, but any link tries to load IE. I see my protocol handler in the address bar of IE too. It should be continuing to fire to my handler. So something is wrong I have to figure out. Once I get this working, I can then redirect those files from a zip file. If I go WebBrowser1.Navigate('lgp://index.html'), the help system will load in and display. Any links clicked there after, will try to load IE.
    Last edited by drezgames; 21-06-2017 at 05:54 PM.

  7. #7
    Could you please show me the example of the code you use for loading of custom HTML files? When I'm looking at the example code I can't figure out how to do that properly as in example everything is hardcoded.
    Well I did manage to change the first HTML page, but I don't know how to open proper HTML based on the link you have clicked. I'm guessing I need to parse/extract needed infromation from aUrl variable but I just can't wrap my head around how

  8. #8
    Hi, yea sure. Here is the handler for the test project i'm working this evening. I just figured out how to prevent the new browser window popup Problem. You have to cancel it and then do a new navigation to the URL. The problem now is how to keep the link content within the frame. When you click on a link, the URL will be something like this: lgp://index.html/and.html, this will display and.html within the frame contents of index.html. Gosh, I can't rem now how I made this work. I don't have the old project code version where I got all these little PITA things sorted out. I rem now running up against each one and sorting them out one by one. Once I can get the frame thing sorted out, then I can start trying to read from zip.


    Code:
    procedure TForm2.MyProtocolHandler(aURL: string; var aMIMEType: string;
      const aPostMIMEType: string; const aPostData: array of byte;
      aMemoryStream: TCustomMemoryStream); // TProtocolCallback
    var
      fn: string;
    
    
      procedure WriteOutString(const aStr: string);
      var
        utf8Out: UTF8String;
      begin
        utf8Out := UTF8Encode(aStr);
        aMemoryStream.WriteBuffer(Pointer(utf8Out)^,
          Length(utf8Out) * SizeOf(AnsiChar));
      end;
    
    
      procedure WriteOutFile(const aFilename: string);
      var
        ms: TMemoryStream;
      begin
        ms := TMemoryStream.Create;
        try
          ms.LoadFromFile(aFilename);
          ms.SaveToStream(aMemoryStream);
        finally
          ms.Free;
        end;
      end;
    
    
      procedure WriteOutTextFile(const aFilename: string);
      var
        ms: TStringList;
      begin
        ms := TStringList.Create;
        try
          ms.LoadFromFile(aFilename);
          WriteOutString(ms.Text);
        finally
          ms.Free;
        end;
      end;
    
    
      function FindMimeType(const url: WideString): string;
      var
        mimetype: PWideChar;
      begin
        mimetype := nil;
        FindMimeFromData(nil, PWideChar(URL), nil, 0, nil, 0, mimetype, 0);
        Result := mimetype;
      end;
    
    
    begin
      // remove any slashes from the front
      while (aURL <> '') and (aURL[1] = '/') do
        Delete(aURL, 1, 1);
      // remove any slashes from the back
      while (aURL <> '') and (aURL[Length(aURL)] = '/') do
        Delete(aURL, Length(aURL), 1);
    
    
      if aURL.Contains('index.html?') then
        aURL := aURL.Replace('index.html?', '')
      else
        aURL := aURL.Replace('index.html/', '');
      if aURL.IsEmpty then
        aURL := 'index.html';
    
    
      // get mime type
      aMIMEType := FindMimeType(aURL);
    
    
      fn :=  TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), 'HTML\' + aURL);
      WriteOutFile(fn);
    end;
    
    
    procedure TForm2.WebBrowser1NewWindow3(ASender: TObject; var ppDisp: IDispatch;
      var Cancel: WordBool; dwFlags: Cardinal; const bstrUrlContext,
      bstrUrl: WideString);
    begin
      Cancel := True;
      WebBrowser1.Navigate(bstrUrl);
    end;
    Last edited by drezgames; 22-06-2017 at 12:50 AM.

  9. #9
    @SilverWarior,

    Ok, this is what I got. I can now click on the local links and they will open up properly inside the frame of the help system. SWEET! Now, the last nagging thing is getting the javascript to work.

    Code:
    procedure TForm2.FormCreate(Sender: TObject);begin
    
    
      FMimeTable := TIdMimeTable.Create;
      NewHttpProtocolHandler('lgp', MyProtocolHandler);
      WebBrowser1.Silent := True;
      WebBrowser1.Navigate('lgp://index.html');
    end;
    
    procedure TForm2.MyProtocolHandler(aURL: string; var aMIMEType: string;
      const aPostMIMEType: string; const aPostData: array of byte;
      aMemoryStream: TCustomMemoryStream); // TProtocolCallback
    
    
      procedure WriteOutString(const aStr: string);
      var
        utf8Out: UTF8String;
      begin
        utf8Out := UTF8Encode(aStr);
        aMemoryStream.WriteBuffer(Pointer(utf8Out)^,
          Length(utf8Out) * SizeOf(AnsiChar));
      end;
    
    
      procedure WriteOutFile(const aFilename: string);
      var
        ms: TMemoryStream;
      begin
        ms := TMemoryStream.Create;
        try
          ms.LoadFromFile(aFilename);
          ms.SaveToStream(aMemoryStream);
        finally
          ms.Free;
        end;
      end;
    
    
      procedure WriteOutTextFile(const aFilename: string);
      var
        ms: TStringList;
      begin
        ms := TStringList.Create;
        try
          ms.LoadFromFile(aFilename);
          WriteOutString(ms.Text);
        finally
          ms.Free;
        end;
      end;
    
    
      function FindMimeType(const url: WideString): string;
      var
        mimetype: PWideChar;
      begin
        mimetype := nil;
        FindMimeFromData(nil, PWideChar(URL), nil, 0, nil, 0, mimetype, 0);
        Result := mimetype;
      end;
    
    
      function GenFilename(url: string): string;
      begin
        Result :=  TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), 'HTML\' + url);
      end;
    
    
    begin
      // remove any slashes from the front
      while (aURL <> '') and (aURL[1] = '/') do
        Delete(aURL, 1, 1);
      // remove any slashes from the back
      while (aURL <> '') and (aURL[Length(aURL)] = '/') do
        Delete(aURL, Length(aURL), 1);
    
    
      // index.html/? indicate a frame operation
      if aURL.Contains('index.html/?') then
      begin
        // remove index.html/? from the url
        aURL := aURL.Replace('index.html/?', '');
    
    
        // load in the frame
        WriteOutFile(GenFilename('index.html'));
      end;
    
    
      // check for index.html/
      if aURL.Contains('index.html/') then
      begin
        // remove from url
        aURL := aURL.Replace('index.html/', '');
      end;
    
    
      // if empty endpoint is the frame index else endpoint is a specific file
      if aURL.IsEmpty then
        aURL := 'index.html';
    
    
      // get mime type of file
      aMIMEType := FindMimeType(aURL);
    
    
      // load the file
      WriteOutFile(GenFilename(aURL));
    end;
    
    
    procedure TForm2.WebBrowser1BeforeNavigate2(ASender: TObject; const pDisp: IDispatch;
      const URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
      var Cancel: WordBool);
    begin
      //
      Statusbar1.SimpleText := URL;
    end;
    
    
    procedure TForm2.WebBrowser1NewWindow3(ASender: TObject; var ppDisp: IDispatch;
      var Cancel: WordBool; dwFlags: Cardinal; const bstrUrlContext,
      bstrUrl: WideString);
    var
      s: string;
    begin
      // cancel new window operation
      Cancel := True;
    
    
      // get the url
      s := bstrURL;
    
    
      // modify url to indicate a frame load operation,
      s := s.Replace('index.html/', 'index.html?');
    
    
      // navigate to modified url that indicates a frame load operation
      WebBrowser1.Navigate(s);
    end;

Tags for this Thread

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
  •