Recent

Author Topic: TSynExporterHTML  (Read 13637 times)

Hippy

  • New Member
  • *
  • Posts: 32
    • http://www.matthewhipkin.co.uk
TSynExporterHTML
« on: June 12, 2006, 12:48:02 am »
Hi there

I'm trying to use the pas2html demo which comes with the original SynEdit package for Delphi, but I am getting this error:

[FORMS.PP] ExceptionOccurred
  Sender=EAccessViolation
  Exception=Access violation
  Stack trace:
  $0042E19B  CLIPBOARDREGISTERFORMAT,  line 93 of ./include/lclintf.inc
  $0042B300  PREDEFINEDCLIPBOARDFORMAT,  line 149 of LCLIntf.pas
TApplication.HandleException Access violation
  Stack trace:
  $0042E19B  CLIPBOARDREGISTERFORMAT,  line 93 of ./include/lclintf.inc
  $0042B300  PREDEFINEDCLIPBOARDFORMAT,  line 149 of LCLIntf.pas
[FORMS.PP] ExceptionOccurred

The only code modication I made was removing {$APPTYPE CONSOLE} and replacing with {$mode objfpc}{$H+}. The code looks like this:

Code: [Select]
program pas2html;

{$mode objfpc}{$H+}

uses
  Windows, Classes, Clipbrd, SynHighlighterPas, SynExportHTML;

var
  ALines: TStringList;
  Syn: TSynPasSyn;
  Exp: TSynExporterHTML;
begin
  if Clipboard.HasFormat(CF_TEXT) then begin
    ALines := TStringList.Create;
    try
      Syn := TSynPasSyn.Create(nil);
      try
        // get syntax highlighter settings
        Syn.EnumUserSettings(ALines);
        if ALines.Count > 0 then
          Syn.UseUserSettings(ALines.Count - 1);
        // load text from clipboard
        ALines.Text := Clipboard.AsText;
        // export ALines to HTML, as HTML fragment in text format
        Exp := TSynExporterHTML.Create(nil);
        try
          Exp.Highlighter := Syn;
          Exp.ExportAsText := TRUE;
          Exp.CreateHTMLFragment := TRUE;
          Exp.ExportAll(ALines);
          Exp.CopyToClipboard;
        finally
          Exp.Free;
        end;
      finally
        Syn.Free;
      end;
    finally
      ALines.Free;
    end;
  end;
  Readln;
end.


Can anyone shed any light why this isn't working?

Thanks.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: TSynExporterHTML
« Reply #1 on: June 12, 2006, 12:21:51 pm »
You are using the LCL without having the interfaces unit in the uses clause of your main program. See part of the LCL backend is not initialized.

Hint: You don't need the windows unit, but it doesn't harm in this case.

Change the uses clause to:
Code: [Select]

uses
  Interfaces, Classes, Clipbrd, SynHighlighterPas, SynExportHTML;


Vincent

Hippy

  • New Member
  • *
  • Posts: 32
    • http://www.matthewhipkin.co.uk
TSynExporterHTML
« Reply #2 on: June 12, 2006, 02:59:56 pm »
Thanks I'll give that a go :D

Hippy

  • New Member
  • *
  • Posts: 32
    • http://www.matthewhipkin.co.uk
TSynExporterHTML
« Reply #3 on: June 13, 2006, 02:19:00 pm »
It's working fine in Windows, but I try to run it in Linux I get

Gtk-WARNING **: cannot open display:

I would like to be able to run this app from an SSH connection and that's not going to happen if I need GTK+ installed. Any ideas on how I can fix this?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
TSynExporterHTML
« Reply #4 on: June 13, 2006, 03:04:35 pm »
You cannot have a clipboard without GTK.

Hippy

  • New Member
  • *
  • Posts: 32
    • http://www.matthewhipkin.co.uk
TSynExporterHTML
« Reply #5 on: June 13, 2006, 03:52:22 pm »
I have just removed it and removed the clipboard bits completely, making it load from a file and echo the output to screen and it is still giving that error. I'm guessing as the TSynExporterHTML component has clipboard functions I am not going to be able to escape this problem without modifying the component itself. :(

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2582
TSynExporterHTML
« Reply #6 on: June 14, 2006, 11:01:48 am »
Also remove interfaces.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Hippy

  • New Member
  • *
  • Posts: 32
    • http://www.matthewhipkin.co.uk
TSynExporterHTML
« Reply #7 on: June 14, 2006, 03:25:41 pm »
I've removed Interfaces and that just caused the original error.

I was using the pas2html demo as a guide for using this component in a command line app. I have now written that app which again is working in Windows (with the Interfaces unit) but not in Linux with or without Interfaces.

The new app looks like this:

Code: [Select]
program highlight;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils, SynExportHTML, SynHighlighterHTML, SynHighlighterPas,
  SynHighlighterAny, SynHighlighterPHP, SynHighlighterSQL, SynHighlighterXML,
  SynHighlighterCSS, miscfunc;

var
  exporter: TSynExporterHTML;
  CSS: TSynCSSSyn;
  HTML: TSynHTMLSyn;
  Pas: TSynPasSyn;
  PHP: TSynPHPSyn;
  Misc: TSynAnySyn;
  SQL: TSynSQLSyn;
  XML: TSynXMLSyn;
  fc: TStrings;
  output: TStrings;
  Data: TMemoryStream;

begin
  if ParamCount = 0 then
  begin
    Writeln('ERROR: No filename specified');
    Exit;
  end;
  if FileExists(ParamStr(1)) then
  begin
    fc := TStringList.Create;
    output := TStringList.Create;
    Data := TMemoryStream.Create;
    exporter := TSynExporterHTML.Create(Nil);
    CSS := TSynCSSSyn.Create(Nil);
    HTML := TSynHTMLSyn.Create(Nil);
    Pas := TSynPasSyn.Create(Nil);
    PHP := TSynPHPSyn.Create(Nil);
    Misc := TSynAnySyn.Create(Nil);
    SQL := TSynSQLSyn.Create(Nil);
    XML := TSynXMLSyn.Create(Nil);
    exporter.Highlighter := Misc;
    if GetFileExt(ParamStr(1)) = 'css' then exporter.Highlighter := CSS;
    if GetFileExt(ParamStr(1)) = 'html' then exporter.Highlighter := HTML;
    if GetFileExt(ParamStr(1)) = 'htm' then exporter.Highlighter := HTML;
    if GetFileExt(ParamStr(1)) = 'pas' then exporter.Highlighter := Pas;
    if GetFileExt(ParamStr(1)) = 'pp' then exporter.Highlighter := Pas;
    if GetFileExt(ParamStr(1)) = 'php' then exporter.Highlighter := PHP;
    if GetFileExt(ParamStr(1)) = 'sql' then exporter.Highlighter := SQL;
    if GetFileExt(ParamStr(1)) = 'xml' then exporter.Highlighter := XML;
    exporter.ExportAsText := true;
    exporter.CreateHTMLFragment := true;
    fc.LoadFromFile(ParamStr(1));
    exporter.ExportAll(fc);
    exporter.SaveToStream(Data);
    Data.Position := 0;
    output.LoadFromStream(Data);
    Writeln(output.Text);
    exporter.Free;
    CSS.Free;
    HTML.Free;
    Pas.Free;
    PHP.Free;
    Misc.Free;
    SQL.Free;
    XML.Free;
    Data.Free;
    fc.Free;
    output.Free;
  end
  else writeln('ERROR: File does not exist');
end.


When I run this (with Interfaces) in a Shell window inside a graphical environment it does do as expected except for 2 warning lines before any output:

Gtk-WARNING **: Unable to locate loadable module in module_path: "liblighthouseblue.so",

Gtk-WARNING **: Unable to locate loadable module in module_path: "liblighthouseblue.so",

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2582
TSynExporterHTML
« Reply #8 on: June 16, 2006, 10:55:00 am »
I don't know the syn* code by heart, but I fear it uses some win32 api calls. We have implemented them in the interfaces, so if this is the case, you indeed need some widgetset.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Hippy

  • New Member
  • *
  • Posts: 32
    • http://www.matthewhipkin.co.uk
TSynExporterHTML
« Reply #9 on: June 16, 2006, 11:30:33 am »
I've just tested the same app in Kylix, and I get the same error, that's a shame cos it really would have come in handy. I think if I get some spare time I'll have a go at breaking, err modifying it some way so it will work in a pure text environment.

 

TinyPortal © 2005-2018