I am using the uHTMLEdit.pas provided in RadPHP 3 as HTML editor (based on TWebbrowser).
When I load some HTML files the program crashes. As an example, save this StackOverflow page and load it in TWebbrowser. It will crash:
Crash details:
Access violation at address 005FAF9B in module 'TestHtmlEditRad.exe'. Read of address 00000000.
Crash on line Doc.Body.SetAttribute('contentEditable', 'true', 0)
:
procedure THTMLEdit.EditText(const text: string);
VAR
Doc: IHTMLDocument2;
sl: TStringList;
f: string;
begin
sl := TStringList.Create;
TRY
sl.Text := text;
f := gettempfile('.html');
sl.SaveToFile(f);
wbBrowser.Navigate(f);
Doc := GetDocument;
if Doc <> NIL
then Doc.Body.SetAttribute('contentEditable', 'true', 0); **Crash HERE**
DeleteFile(f);
FINALLY
FreeAndNil(sl);
END;
end;
It works with small (not so complex) HTML files.
My question is: Is normal for TWebBrowser to crash?
To reproduce you only need this code and the uHTMLEdit.pas (already provided with Embarcadero RadPHP).
unit FormMain;
interface
USES
Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, uHTMLEdit;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
IMPLEMENTATION {$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
VAR debug: string;
begin
debug:= stringfromfile('test.htm'); // this temporary line of code is mine, for testing. All other code is Embarcadero's
with THTMLEditDlg.Create(application) do begin
try
edittext(debug);
if ShowModal= 0
then debug:= getText;
finally
free;
end;
end;
end;
end.