我有一个包含HTML代码的字符串var'HTMLCode'.我想将此代码加载到浏览器中.
这是Embarcadero的代码:
procedure THTMLEdit.EditText(CONST HTMLCode: string);
{VAR
Doc: IHTMLDocument2;
TempFile: string; }
begin
TempFile := GetTempFile('.html');
StringToFile(TempFile, HTMLCode);
wbBrowser.Navigate(TempFile);
Doc := GetDocument;
if Doc <> NIL
then Doc.Body.SetAttribute('contentEditable', 'true', 0); //crash here when I load complex html files
DeleteFile(TempFile);
end;
Run Code Online (Sandbox Code Playgroud)
它有一些问题所以我用这个替换它:
procedure THTMLEdit.EditText(CONST HTMLCode: string);
VAR
TSL: TStringList;
MemStream: TMemoryStream;
begin
wbBrowser.Navigate('about:blank');
WHILE wbBrowser.ReadyState < READYSTATE_INTERACTIVE
DO Application.ProcessMessages;
GetDocument.DesignMode := 'On';
if Assigned(wbBrowser.Document) then
begin
TSL := TStringList.Create;
TRY
MemStream := TMemoryStream.Create;
TRY
TSL.Text := HTMLCode;
TSL.SaveToStream(MemStream);
MemStream.Seek(0, …Run Code Online (Sandbox Code Playgroud) 我希望在我的应用程序中快速显示大文本文件的内容,而无需将整个文件加载到内存中.
其他人如何做到这一点?
Total Commander是一个很棒的工具,拥有一个令人惊叹的内部查看器.它打开任何文件,无论多大,瞬间(或那么快,我无法计时).我在12GB文件上试了一下.显示文件时没有明显的内存使用量(仅约100KB).他们是怎么做到的?
SynEdit - 程序冻结(分钟),因为它将首先解析整个文件,然后它将显示文本.
LargeTextFile
近似滚动条的大小.滚动条连续调整(收缩),直到程序最终读取整个文件(可能需要几分钟).与Total Commander相比,它真的很糟糕.
UltraEdit 32 - 程序冻结(我不得不杀死它,因为我没有耐心(或ram)让完成)
这个问题与:在 TWebBrowser 中加载字符串(HTML 代码)的最佳方法是什么?
我正在尝试使用 doc.body.style.fontFamily 更改 TWebBrowser 中的字体,但没有任何反应。字体仍然是 TimesNewRoman。
procedure THTMLEdit.SetHtmlCode(CONST HTMLCode: string);
VAR
Doc: Variant;
begin
if NOT Assigned(wbBrowser.Document)
then wbBrowser.Navigate('about:blank');
WHILE wbBrowser.ReadyState < READYSTATE_INTERACTIVE
DO Application.ProcessMessages;
Doc := wbBrowser.Document;
Doc.Clear;
Doc.Write(HTMLCode);
doc.body.style.fontFamily:='Arial'; <------ won't work
Doc.DesignMode := 'On';
Doc.Close;
end;
Run Code Online (Sandbox Code Playgroud) 我在 DesignMode (Doc.DesignMode := 'On') 中使用 TWebBrowser 来编写 HTML 文档。TWebBrowser 中没有加载文档(磁盘上的 HTML 文件)。我直接在 TWebBrowser 中从零创建文档。html 代码将从 TWebBrowser 中提取并保存为 c:/MyProjects/SomeHtmlName.html。
问题是它不会显示我插入的图像,如果它们有相对路径。
更确切地说,如果我将此代码粘贴到 WebBrowser 中,它将立即显示图像:
<IMG src="file:///c:/MyProjects/resources/R.PNG">
Run Code Online (Sandbox Code Playgroud)
但是,如果我输入:
<IMG border=0 src="resources\R.PNG">
<IMG border=0 src="resources/R.PNG"> <---- preferred so it will work on Linux
Run Code Online (Sandbox Code Playgroud)
它将显示图像占位符而不是实际图像。
我需要相对路径,因此如果我更改根路径或将其上传到 FTP,网站仍然可以工作。
procedure TForm1.Button1Click(Sender: TObject);
begin
LoadDummyPage;
SetHtmlCode('<img src="resources/test_img.PNG">');
Memo1.Text:= GetHtmlCode;
end;
function TForm1.LoadDummyPage: Boolean;
const FileName: string= 'c:\MyProject\_ONLINE WEB SITE\dummy.html';
begin
if not Assigned(wbBrowser.Document)
then wbBrowser.Navigate('about:blank');
Result := FileExists(FileName);
if Result
then wbBrowser.Navigate('file://' + FileName)
else Caption:= 'file …Run Code Online (Sandbox Code Playgroud) 我需要支持TRichEdit中的"友好名称超链接",我找到的所有解决方案都基于autoURL(EM_AUTOURLDETECT),它通过检测用户输入的以www(或http)开头的字符串来工作.
但我想在不以www开头的字符串上放置链接.示例:" 下载 ".
是否必须在构造函数的第一行上具有Inherited?
我可以在"继承"之前使用其他代码吗?
例:
constructor TMyIniFile.Create(SectionName: string);
VAR Path: string;
begin
Path:= UserProfileFolder; //initialize path here
inherited Create(Path);
//more code ..
end;
Run Code Online (Sandbox Code Playgroud) 手册说Synchronize是TThread的成员.但是,它表明您可以直接调用Synchronize.其他消息来源也是如此.
//Synchronize() performs actions contained in a routine as if they were executed from the main VCL thread
void __fastcall TCriticalThread::Execute()
{
...
Synchronize(UpdateCaption);
...
}
Run Code Online (Sandbox Code Playgroud)
但如果我这样做,我的编译器告诉我"E2268调用未定义的函数'同步'".当然我包括了图书馆:
#include <System.Classes.hpp>
Run Code Online (Sandbox Code Playgroud)
另一方面,编译器找到TThread :: Synchronize,但它不接受MainThreadID作为参数:
TThread::Synchronize(MainThreadID, MainForm->UpdateCaption );
Run Code Online (Sandbox Code Playgroud)
PS:我是C++ Builder的新手.
我有一个需要几秒钟才能加载的应用程序(大量初始化)。GUI 在启动期间冻结。所以我想创建一个在应用程序加载时淡入淡出的启动画面。我使用TBackgroundWorker组件在后台线程中执行动画。
但是,当我使用这个组件时会发生一些奇怪的事情:当它发出“工作完成”的信号时(请参阅 BackgroundWorkerWorkComplete),同时我打开的消息对话框会自动关闭。
procedure TMainForm.ButtonStartSplashClick(Sender: TObject);
VAR
frmSplash: TfrmSplash;
begin
frmSplash:= TfrmSplash.Create(NIL);
frmSplash.StartAnimation;
//MessageBox(Handle, 'Hi', nil, MB_OK); // This remains on screen
Application.MessageBox(PChar('Hi'), PChar('Box'), MB_ICONINFORMATION); // This is automatically closed when the background thread is done
end;
Run Code Online (Sandbox Code Playgroud)
这是启动画面:
procedure TfrmSplash.StartAnimation;
begin
Show;
BackgroundWorker.Execute;
end;
procedure TfrmSplash.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:= caFree;
end;
procedure TfrmSplash.BackgroundWorkerWork(Worker: TBackgroundWorker);
VAR i: Integer;
begin
for i:= 1 to 255 DO
begin
AlphaBlendValue:= i; // do not access GUI directly from …Run Code Online (Sandbox Code Playgroud) 我尝试围绕这个jpeg 解码器库(由 Arnaud Bouchez 原创)实现一个包装器。该库非常快,但它不支持所有 jpeg!
对于非常大的 jpg 文件,它会因 EOutOfResources 异常而失败(如预期)。
所以我尝试默默地跳过这些文件。它有效,但是当我关闭应用程序时,FastMM 指示内存泄漏。
function FastJpgDecode(FileName: string; OUT ErrorType: string): TBitmap;
var Img: PJpegDecode;
res: TJpegDecodeError;
Stream: TMemoryStream;
begin
Result:= NIL;
Stream:= TMemoryStream.Create;
TRY
if Length(FileName) > MAX_PATH then { TMemoryStream does not support long paths }
begin
ErrorType:= 'File name too long!';
Exit;
end;
Stream.LoadFromFile(FileName);
Stream.Position:= 0;
res:= JpegDecode(Stream.Memory, Stream.Size, Img);
case res of
JPEG_SUCCESS:
begin
try
Result:= Img.ToBitmap; // This will raise an EOutOfResources for large files! …Run Code Online (Sandbox Code Playgroud) 我想将像素从 BMP1 复制到 BMP2 但复制的图像是乱码。为什么?
注:输入图像为pf8bit;
TYPE
TPixArray = array[0..4095] of Byte;
PPixArray = ^TPixArray;
procedure Tfrm1.CopyImage;
VAR
BMP1, BMP2: TBitmap;
y, x: Integer;
LineI, LineO: PPixArray;
begin
BMP1:= TBitmap.Create;
BMP2:= TBitmap.Create;
TRY
BMP1.LoadFromFile('test.bmp');
BMP2.SetSize(BMP1.Width, BMP1.Height);
BMP2.PixelFormat:= BMP1.PixelFormat;
for y:= 0 to BMP1.Height -1 DO
begin
LineI := BMP1.ScanLine[y];
LineO := BMP2.ScanLine[y];
for x := 0 to BMP1.Width -1 DO
LineO[x]:= LineI[x];
end;
//BMP2.SaveToFile('out.bmp');
imgOut.Picture.Assign(BMP2); //TImage
FINALLY
FreeAndNil(BMP2);
FreeAndNil(BMP1);
END;
end;
Run Code Online (Sandbox Code Playgroud)
对于保存的图像,图形编辑器会显示“像素深度/颜色:索引,256 色板”。
delphi ×10
delphi-xe7 ×3
twebbrowser ×3
html ×2
bitmap ×1
browser ×1
c++ ×1
c++builder ×1
delphi-xe ×1
font-face ×1
jpeg ×1
large-data ×1
tbitmap ×1
text ×1
tform ×1
trichedit ×1