Last active
October 9, 2020 12:00
-
-
Save unreal79/cd0996c1782e9d453a63dea1e13ac88a to your computer and use it in GitHub Desktop.
Include file README.md into About window (Delphi) -- README.md will be compiled inside .exe file and displayed on About window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses | |
ActiveX, MSHTML, SHDocVw, MarkdownCommonMark, MarkdownProcessor; // uses https://github.com/grahamegrieve/delphi-markdown | |
procedure TForm1.Button1Click(Sender: TObject); | |
var | |
ResStream: TResourceStream; | |
StringStream: TStringStream; | |
FormAbout: TForm; | |
WebBrowser1: TWebBrowser; | |
commonmark : TMarkdownProcessor; | |
Doc: IHTMLDocument2; | |
psa: PSafeArray; | |
v: variant; | |
s: String; | |
begin | |
ResStream := TResourceStream.Create( hInstance, 'READMEText', RT_RCDATA ); | |
StringStream := TStringStream.Create(); | |
try | |
StringStream.LoadFromStream( ResStream ); | |
READMEstring := Utf8ToAnsi( StringStream.DataString ); // Utf8ToAnsi could be unnecessary | |
finally | |
FreeAndNil( ResStream ); | |
FreeAndNil( StringStream ); | |
end; | |
FormAbout := TForm.Create(nil); | |
try | |
FormAbout.BorderStyle := bsDialog; | |
FormAbout.Caption := 'About window'; | |
FormAbout.Position := poScreenCenter; | |
FormAbout.ClientWidth := 800; | |
FormAbout.ClientHeight := 600; | |
WebBrowser1 := TWebBrowser.Create( FormAbout ); | |
TWinControl( WebBrowser1 ).Name := 'WebBrowser1'; | |
TWinControl( WebBrowser1 ).Parent := FormAbout; | |
WebBrowser1.Align := alclient; | |
commonmark := TMarkdownProcessor.CreateDialect(mdCommonMark); | |
s := commonmark.process( READMEstring ); | |
memo2.Text := s; | |
WebBrowser1.Navigate( 'about:blank' ); | |
v := VarArrayCreate( [0, 0], varVariant ); | |
v[ 0 ] := s; | |
psa := PSafeArray( TVarData( v ).VArray ); | |
Doc := WebBrowser1.Document as IHTMLDocument2; | |
Doc.write( psa ); | |
FormAbout.ShowModal(); | |
finally | |
commonmark.Free(); | |
FormAbout.Free(); | |
end; | |
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
READMEText RCDATA README.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment