关于Ie的内存漏失(500分)(300分)

  • 主题发起人 主题发起人 DNChen
  • 开始时间 开始时间
D

DNChen

Unregistered / Unconfirmed
GUEST, unregistred user!
把IE内嵌入程序中,会产生如cJ所说的内存漏失,在Delphi5中编译后发现,
漏失比较少,却无法使用enter键。

高分征求解决方案,500分,不够会另外开帖子给


 
>>却无法使用enter键。
什么意思?
 
是不是没有正确释放资源?
 
你实验过d5的twebbrowser吗?当用他显示一个form时,form里面的textarea是无法
用回车的。

其实D5还是有资源泄露,所以最好的方法是找办法解决这个问题,其他事情都好办
了。

有人说C++ Builder 3和D4的DPL是完全兼容的,所以如果用BCB3弄一个
twebbrowser出来,用d4导入使用,可以解决内存泄露问题,但是我没有条件实验
我不会BCB,哪位大虾愿意一试?

另,我这边缺个Delphi程序员,要winsocks熟悉的,谁有兴趣也可以回复在帖子后面
 
>>当用他显示一个form时,form里面的textarea是无法用回车的。
晚上回家试一试.
 
果然不能用Enter键。
我倒是有C++Builder4,但是他跟Delphi5的DPL不兼容。
 
C++ Builder的也可以啊,email我:tocdn@pchome.net或者tqz(tqz@stame.com)
 
你说的“如果用BCB3弄一个twebbrowser出来,用d4导入使用,
可以解决内存泄露问题”是什么意思,我不是很明白。如果你
能比较详细的说一下,我可以马上帮你办,呵呵。
 
我已经在C++Builder4中导入了TWebBrowser,可以用
Enter键。只是在D5中不能导入,出错:
Cannot load package 'vcl40.' It contains unit 'ToolsAPI,';
which is also contained in package 'Vcl50'
我没有D4,也没法试验了。你想要什么?就那个bpl?
 
好象是要在d4里导入的吧,你给我发一个那个dpl吧,
tocdn@pchome.net
 
我已经给你发了,不过,你前面说C3才跟D4兼容,我是用C4的,怀疑无效。
 
没有收到,你发我的cdn@stame.com吧,或者tqz的tqz@stame.com
 
我就是给tqz@stame.com发的。
这次我给你三个信箱都发了,呵呵,不会骂我吧。
干活干的这么迟,I服了U。
 
各位,我和tqz已经找出方法解决了,但是限于商业因素,暂时不能说,其实也是一些比较黑的方法,呵呵。


分数大伙儿分了吧
 
unit SHDocVw_TLB;

{ This file contains pascal declarations imported from a type library.
This file will be written during each import or refresh of the type
library editor. Changes to this file will be discarded during the
refresh process. }

{ Microsoft Internet Controls }
{ Version 1.0 }

{ Conversion log:
Warning: 'Type' is a reserved word. IWebBrowser.Type changed to Type_
}

interface

uses Windows, ActiveX, Classes, Graphics, OleCtrls, StdVCL;

const
LIBID_SHDocVw: TGUID = '{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}';

const

{ Constants for WebBrowser navigation flags }

{ BrowserNavConstants }

navOpenInNewWindow = 1;
navNoHistory = 2;
navNoReadFromCache = 4;
navNoWriteToCache = 8;

{ Constants for Refresh }

{ RefreshConstants }

REFRESH_NORMAL = 0;
REFRESH_IFEXPIRED = 1;
REFRESH_COMPLETELY = 3;

{ Constants for WebBrowser CommandStateChange }

{ CommandStateChangeConstants }

CSC_UPDATECOMMANDS = -1;
CSC_NAVIGATEFORWARD = 1;
CSC_NAVIGATEBACK = 2;

const

{ Component class GUIDs }
Class_WebBrowser: TGUID = '{EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B}';
Class_InternetExplorer: TGUID = '{0002DF01-0000-0000-C000-000000000046}';

type

{ Forward declarations: Interfaces }
IWebBrowser = interface;
IWebBrowserDisp = dispinterface;
DWebBrowserEvents = dispinterface;
IWebBrowserApp = interface;
IWebBrowserAppDisp = dispinterface;

{ Forward declarations: CoClasses }
WebBrowser = IWebBrowser;
InternetExplorer = IWebBrowserApp;

{ Forward declarations: Enums }
BrowserNavConstants = TOleEnum;
RefreshConstants = TOleEnum;
CommandStateChangeConstants = TOleEnum;

{ Web Browser interface }

IWebBrowser = interface(IDispatch)
['{EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B}']
procedure GoBack
safecall;
procedure GoForward
safecall;
procedure GoHome
safecall;
procedure GoSearch
safecall;
procedure Navigate(const URL: WideString
var Flags, TargetFrameName, PostData, Headers: OleVariant)
safecall;
procedure Refresh
safecall;
procedure Refresh2(var Level: OleVariant)
safecall;
procedure Stop
safecall;
function Get_Application: IDispatch
safecall;
function Get_Parent: IDispatch
safecall;
function Get_Container: IDispatch
safecall;
function Get_Document: IDispatch
safecall;
function Get_TopLevelContainer: WordBool
safecall;
function Get_Type_: WideString
safecall;
function Get_Left: Integer
safecall;
procedure Set_Left(Value: Integer)
safecall;
function Get_Top: Integer
safecall;
procedure Set_Top(Value: Integer)
safecall;
function Get_Width: Integer
safecall;
procedure Set_Width(Value: Integer)
safecall;
function Get_Height: Integer
safecall;
procedure Set_Height(Value: Integer)
safecall;
function Get_LocationName: WideString
safecall;
function Get_LocationURL: WideString
safecall;
function Get_Busy: WordBool
safecall;
property Application: IDispatch read Get_Application;
property Parent: IDispatch read Get_Parent;
property Container: IDispatch read Get_Container;
property Document: IDispatch read Get_Document;
property TopLevelContainer: WordBool read Get_TopLevelContainer;
property Type_: WideString read Get_Type_;
property Left: Integer read Get_Left write Set_Left;
property Top: Integer read Get_Top write Set_Top;
property Width: Integer read Get_Width write Set_Width;
property Height: Integer read Get_Height write Set_Height;
property LocationName: WideString read Get_LocationName;
property LocationURL: WideString read Get_LocationURL;
property Busy: WordBool read Get_Busy;
end;

{ DispInterface declaration for Dual Interface IWebBrowser }

IWebBrowserDisp = dispinterface
['{EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B}']
procedure GoBack
dispid 100;
procedure GoForward
dispid 101;
procedure GoHome
dispid 102;
procedure GoSearch
dispid 103;
procedure Navigate(const URL: WideString
var Flags, TargetFrameName, PostData, Headers: OleVariant)
dispid 104;
procedure Refresh
dispid -550;
procedure Refresh2(var Level: OleVariant)
dispid 105;
procedure Stop
dispid 106;
property Application: IDispatch readonly dispid 200;
property Parent: IDispatch readonly dispid 201;
property Container: IDispatch readonly dispid 202;
property Document: IDispatch readonly dispid 203;
property TopLevelContainer: WordBool readonly dispid 204;
property Type_: WideString readonly dispid 205;
property Left: Integer dispid 206;
property Top: Integer dispid 207;
property Width: Integer dispid 208;
property Height: Integer dispid 209;
property LocationName: WideString readonly dispid 210;
property LocationURL: WideString readonly dispid 211;
property Busy: WordBool readonly dispid 212;
end;

{ Event interface for Web Browser Control }

DWebBrowserEvents = dispinterface
['{EAB22AC2-30C1-11CF-A7EB-0000C05BAE0B}']
procedure BeforeNavigate(const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Cancel: WordBool)
dispid 100;
procedure NavigateComplete(const URL: WideString)
dispid 101;
procedure StatusTextChange(const Text: WideString)
dispid 102;
procedure ProgressChange(Progress, ProgressMax: Integer)
dispid 108;
procedure DownloadComplete
dispid 104;
procedure CommandStateChange(Command: Integer
Enable: WordBool)
dispid 105;
procedure DownloadBegin
dispid 106;
procedure NewWindow(const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Processed: WordBool)
dispid 107;
procedure TitleChange(const Text: WideString)
dispid 113;
procedure FrameBeforeNavigate(const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Cancel: WordBool)
dispid 200;
procedure FrameNavigateComplete(const URL: WideString)
dispid 201;
procedure FrameNewWindow(const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Processed: WordBool)
dispid 204;
procedure Quit(var Cancel: WordBool)
dispid 103;
procedure WindowMove
dispid 109;
procedure WindowResize
dispid 110;
procedure WindowActivate
dispid 111;
procedure PropertyChange(const szProperty: WideString)
dispid 112;
end;

{ Web Browser Application Interface. }

IWebBrowserApp = interface(IWebBrowser)
['{0002DF05-0000-0000-C000-000000000046}']
procedure Quit
safecall;
procedure ClientToWindow(var pcx, pcy: SYSINT)
safecall;
procedure PutProperty(const szProperty: WideString
vtValue: OleVariant)
safecall;
function GetProperty(const szProperty: WideString): OleVariant
safecall;
function Get_Name: WideString
safecall;
function Get_HWND: Integer
safecall;
function Get_FullName: WideString
safecall;
function Get_Path: WideString
safecall;
function Get_Visible: WordBool
safecall;
procedure Set_Visible(Value: WordBool)
safecall;
function Get_StatusBar: WordBool
safecall;
procedure Set_StatusBar(Value: WordBool)
safecall;
function Get_StatusText: WideString
safecall;
procedure Set_StatusText(const Value: WideString)
safecall;
function Get_ToolBar: SYSINT
safecall;
procedure Set_ToolBar(Value: SYSINT)
safecall;
function Get_MenuBar: WordBool
safecall;
procedure Set_MenuBar(Value: WordBool)
safecall;
function Get_FullScreen: WordBool
safecall;
procedure Set_FullScreen(Value: WordBool)
safecall;
property Name: WideString read Get_Name;
property HWND: Integer read Get_HWND;
property FullName: WideString read Get_FullName;
property Path: WideString read Get_Path;
property Visible: WordBool read Get_Visible write Set_Visible;
property StatusBar: WordBool read Get_StatusBar write Set_StatusBar;
property StatusText: WideString read Get_StatusText write Set_StatusText;
property ToolBar: SYSINT read Get_ToolBar write Set_ToolBar;
property MenuBar: WordBool read Get_MenuBar write Set_MenuBar;
property FullScreen: WordBool read Get_FullScreen write Set_FullScreen;
end;

{ DispInterface declaration for Dual Interface IWebBrowserApp }

IWebBrowserAppDisp = dispinterface
['{0002DF05-0000-0000-C000-000000000046}']
procedure GoBack
dispid 100;
procedure GoForward
dispid 101;
procedure GoHome
dispid 102;
procedure GoSearch
dispid 103;
procedure Navigate(const URL: WideString
var Flags, TargetFrameName, PostData, Headers: OleVariant)
dispid 104;
procedure Refresh
dispid -550;
procedure Refresh2(var Level: OleVariant)
dispid 105;
procedure Stop
dispid 106;
property Application: IDispatch readonly dispid 200;
property Parent: IDispatch readonly dispid 201;
property Container: IDispatch readonly dispid 202;
property Document: IDispatch readonly dispid 203;
property TopLevelContainer: WordBool readonly dispid 204;
property Type_: WideString readonly dispid 205;
property Left: Integer dispid 206;
property Top: Integer dispid 207;
property Width: Integer dispid 208;
property Height: Integer dispid 209;
property LocationName: WideString readonly dispid 210;
property LocationURL: WideString readonly dispid 211;
property Busy: WordBool readonly dispid 212;
procedure Quit
dispid 300;
procedure ClientToWindow(var pcx, pcy: SYSINT)
dispid 301;
procedure PutProperty(const szProperty: WideString
vtValue: OleVariant)
dispid 302;
function GetProperty(const szProperty: WideString): OleVariant
dispid 303;
property Name: WideString readonly dispid 0;
property HWND: Integer readonly dispid -515;
property FullName: WideString readonly dispid 400;
property Path: WideString readonly dispid 401;
property Visible: WordBool dispid 402;
property StatusBar: WordBool dispid 403;
property StatusText: WideString dispid 404;
property ToolBar: SYSINT dispid 405;
property MenuBar: WordBool dispid 406;
property FullScreen: WordBool dispid 407;
end;

{ WebBrowser Control }

TWebBrowserBeforeNavigate = procedure(Sender: TObject
const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Cancel: WordBool) of object;
TWebBrowserNavigateComplete = procedure(Sender: TObject
const URL: WideString) of object;
TWebBrowserStatusTextChange = procedure(Sender: TObject
const Text: WideString) of object;
TWebBrowserProgressChange = procedure(Sender: TObject
Progress, ProgressMax: Integer) of object;
TWebBrowserCommandStateChange = procedure(Sender: TObject
Command: Integer
Enable: WordBool) of object;
TWebBrowserNewWindow = procedure(Sender: TObject
const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Processed: WordBool) of object;
TWebBrowserTitleChange = procedure(Sender: TObject
const Text: WideString) of object;
TWebBrowserFrameBeforeNavigate = procedure(Sender: TObject
const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Cancel: WordBool) of object;
TWebBrowserFrameNavigateComplete = procedure(Sender: TObject
const URL: WideString) of object;
TWebBrowserFrameNewWindow = procedure(Sender: TObject
const URL: WideString
Flags: Integer
const TargetFrameName: WideString
var PostData: OleVariant
const Headers: WideString
var Processed: WordBool) of object;
TWebBrowserQuit = procedure(Sender: TObject
var Cancel: WordBool) of object;
TWebBrowserPropertyChange = procedure(Sender: TObject
const szProperty: WideString) of object;

TWebBrowser = class(TOleControl)
private
FOnBeforeNavigate: TWebBrowserBeforeNavigate;
FOnNavigateComplete: TWebBrowserNavigateComplete;
FOnStatusTextChange: TWebBrowserStatusTextChange;
FOnProgressChange: TWebBrowserProgressChange;
FOnDownloadComplete: TNotifyEvent;
FOnCommandStateChange: TWebBrowserCommandStateChange;
FOnDownloadBegin: TNotifyEvent;
FOnNewWindow: TWebBrowserNewWindow;
FOnTitleChange: TWebBrowserTitleChange;
FOnFrameBeforeNavigate: TWebBrowserFrameBeforeNavigate;
FOnFrameNavigateComplete: TWebBrowserFrameNavigateComplete;
FOnFrameNewWindow: TWebBrowserFrameNewWindow;
FOnQuit: TWebBrowserQuit;
FOnWindowMove: TNotifyEvent;
FOnWindowResize: TNotifyEvent;
FOnWindowActivate: TNotifyEvent;
FOnPropertyChange: TWebBrowserPropertyChange;
FIntf: IWebBrowser;
function GetControlInterface: IWebBrowser;
protected
procedure CreateControl;
procedure InitControlData
override;
function GetTOleEnumProp(Index: Integer): TOleEnum;
procedure SetTOleEnumProp(Index: Integer
Value: TOleEnum);
public
procedure GoBack;
procedure GoForward;
procedure GoHome;
procedure GoSearch;
procedure Navigate(const URL: WideString
var Flags, TargetFrameName, PostData, Headers: OleVariant);
procedure Refresh;
procedure Refresh2(var Level: OleVariant);
procedure Stop;
property ControlInterface: IWebBrowser read GetControlInterface;
property Application: IDispatch index 200 read GetIDispatchProp;
property Parent: IDispatch index 201 read GetIDispatchProp;
property Container: IDispatch index 202 read GetIDispatchProp;
property Document: IDispatch index 203 read GetIDispatchProp;
property TopLevelContainer: WordBool index 204 read GetWordBoolProp;
property Type_: WideString index 205 read GetWideStringProp;
property LocationName: WideString index 210 read GetWideStringProp;
property LocationURL: WideString index 211 read GetWideStringProp;
property Busy: WordBool index 212 read GetWordBoolProp;
published
property TabStop;
property Align;
property DragCursor;
property DragMode;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property Visible;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnStartDrag;
property OnBeforeNavigate: TWebBrowserBeforeNavigate read FOnBeforeNavigate write FOnBeforeNavigate;
property OnNavigateComplete: TWebBrowserNavigateComplete read FOnNavigateComplete write FOnNavigateComplete;
property OnStatusTextChange: TWebBrowserStatusTextChange read FOnStatusTextChange write FOnStatusTextChange;
property OnProgressChange: TWebBrowserProgressChange read FOnProgressChange write FOnProgressChange;
property OnDownloadComplete: TNotifyEvent read FOnDownloadComplete write FOnDownloadComplete;
property OnCommandStateChange: TWebBrowserCommandStateChange read FOnCommandStateChange write FOnCommandStateChange;
property OnDownloadBegin: TNotifyEvent read FOnDownloadBegin write FOnDownloadBegin;
property OnNewWindow: TWebBrowserNewWindow read FOnNewWindow write FOnNewWindow;
property OnTitleChange: TWebBrowserTitleChange read FOnTitleChange write FOnTitleChange;
property OnFrameBeforeNavigate: TWebBrowserFrameBeforeNavigate read FOnFrameBeforeNavigate write FOnFrameBeforeNavigate;
property OnFrameNavigateComplete: TWebBrowserFrameNavigateComplete read FOnFrameNavigateComplete write FOnFrameNavigateComplete;
property OnFrameNewWindow: TWebBrowserFrameNewWindow read FOnFrameNewWindow write FOnFrameNewWindow;
property OnQuit: TWebBrowserQuit read FOnQuit write FOnQuit;
property OnWindowMove: TNotifyEvent read FOnWindowMove write FOnWindowMove;
property OnWindowResize: TNotifyEvent read FOnWindowResize write FOnWindowResize;
property OnWindowActivate: TNotifyEvent read FOnWindowActivate write FOnWindowActivate;
property OnPropertyChange: TWebBrowserPropertyChange read FOnPropertyChange write FOnPropertyChange;
end;

procedure Register;

implementation

uses ComObj;

procedure TWebBrowser.InitControlData;
const
CEventDispIDs: array[0..16] of Integer = (
$00000064, $00000065, $00000066, $0000006C, $00000068, $00000069,
$0000006A, $0000006B, $00000071, $000000C8, $000000C9, $000000CC,
$00000067, $0000006D, $0000006E, $0000006F, $00000070);
CControlData: TControlData = (
ClassID: '{EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B}';
EventIID: '{EAB22AC2-30C1-11CF-A7EB-0000C05BAE0B}';
EventCount: 17;
EventDispIDs: @CEventDispIDs;
LicenseKey: nil;
Flags: $00000000;
Version: 300);
begin
ControlData := @CControlData;
end;

procedure TWebBrowser.CreateControl;

procedure DoCreate;
begin
FIntf := IUnknown(OleObject) as IWebBrowser;
end;

begin
if FIntf = nil then DoCreate;
end;

function TWebBrowser.GetControlInterface: IWebBrowser;
begin
CreateControl;
Result := FIntf;
end;

function TWebBrowser.GetTOleEnumProp(Index: Integer): TOleEnum;
begin
Result := GetIntegerProp(Index);
end;

procedure TWebBrowser.SetTOleEnumProp(Index: Integer
Value: TOleEnum);
begin
SetIntegerProp(Index, Value);
end;

procedure TWebBrowser.GoBack;
begin
CreateControl;
FIntf.GoBack;
end;

procedure TWebBrowser.GoForward;
begin
CreateControl;
FIntf.GoForward;
end;

procedure TWebBrowser.GoHome;
begin
CreateControl;
FIntf.GoHome;
end;

procedure TWebBrowser.GoSearch;
begin
CreateControl;
FIntf.GoSearch;
end;

procedure TWebBrowser.Navigate(const URL: WideString
var Flags, TargetFrameName, PostData, Headers: OleVariant);
begin
CreateControl;
FIntf.Navigate(URL, Flags, TargetFrameName, PostData, Headers);
end;

procedure TWebBrowser.Refresh;
begin
CreateControl;
FIntf.Refresh;
end;

procedure TWebBrowser.Refresh2(var Level: OleVariant);
begin
CreateControl;
FIntf.Refresh2(Level);
end;

procedure TWebBrowser.Stop;
begin
CreateControl;
FIntf.Stop;
end;


procedure Register;
begin
RegisterComponents('ActiveX', [TWebBrowser]);
end;

end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部