以下代码来自我的程序:
procedure TFrmMain.WebBrowserBeforeNavigate2(Sender: TObject;
const pDisp: IDispatch;
var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant;
var Cancel: WordBool);
var
ResLeft: string;
sCaptionIn, sCaption, sCaptionLeft: WideString;
sDll, sDllLeft: string;
sFrame: string;
begin
//[caption]商品信息维护[dll]pPosDLL.dll[frame]FrmItem
if UpperCase(Copy(URL, 1, 6)) = 'URL://' then
begin
URL := Copy(URL, 7, Length(URL) - 1);
ShellExecute(handle, 'open', 'iexplore.exe',
PChar(ExtractFilePath(Application.ExeName) +
'ReportWeb/' + string(URL)), nil, SW_MAXIMIZE);
Cancel := True;
end;
if UpperCase(Copy(URL, 1, 7)) = 'HTTP://' then
begin
// URL := Copy(URL, 7, Length(URL) - 1);
ShellExecute(handle, 'open', 'iexplore.exe',
PChar(string(URL)), nil, SW_MAXIMIZE);
Cancel := True;
end;
if UpperCase(Copy(URL, 1, 6)) = 'RES://' then
begin
ResLeft := Copy(URL, 7, Length(URL) - 1);
// Caption
sCaptionIn := Copy(ResLeft, 1, Pos('[dll]', ResLeft) - 1);
sCaption := Trim(Copy(sCaptionIn, Length('[caption]') + 1,
Length(sCaptionIn) - 1));
if Copy(sCaption, 1, 2) = 'n]' then
begin
sCaption := Copy(sCaption, 3, Length(sCaption) - 1);
end;
sCaptionLeft := Copy(ResLeft, Pos('[dll]', ResLeft) + Length('[dll]'),
Length(ResLeft) - 1);
// Dll
sDll := Trim(Copy(sCaptionLeft, 1, Pos('[frame]', sCaptionLeft) - 1));
sDllLeft := Copy(ResLeft, Pos('[frame]', ResLeft) + Length('[frame]'),
Length(ResLeft) - 1);
// Frame
sFrame := Trim(StringReplace(sDllLeft, '/', '', []));
// 判断权限
// if not Right.GetRight(gUserInfo.UserID, sDll, sFrame) then
// begin
// Cancel := True;
// raise Exception.Create('权限不足,请与管理员联系!');
// end;
try
DllImport.ImportDllFrame(sDll, sFrame, sCaption,
NoteBook, TabControl1);
PnlTabContrl.Visible := True;
except
on E: Exceptiondo
begin
Cancel := True;
raise Exception.Create(E.Message);
end;
end;
DllImport.ParentResize(Self.Width - 5,
Self.Height - StatusBar.Height - PnlLogo.Height - 30);
Cancel := True;
end;
end;