embeded için pack kodları

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Lord_Ares
Üye
Mesajlar: 1070
Kayıt: 15 Eki 2006 04:33
Konum: Çorlu

embeded için pack kodları

Mesaj gönderen Lord_Ares »

merhaba arkadaşlar, embedded webbrowser komponentinde proxy kullanmak için ( normalde hatalar veriyor)komponentin pack edilmesi gerekiyormuş. http://www.bsalsa.com da yani kompenentin orjinal sitesinde ilgili örneği vermişler. Fakat siteye giremiyorum. google önbellek metodunu kullanarak aşağıdaki bilgiyi aldım. Bu komponenti pack edemedim yardımcı olabilirseniz sevinirim.

How to fix Proxy

EwbTools.pas

Kod: Tümünü seç

type
  PInternetPerConnOption = ^INTERNET_PER_CONN_OPTION;
  INTERNET_PER_CONN_OPTION = record
    dwOption: DWORD;
    case Integer of
      0: (dwValue: DWORD);
      1: (pszValue:LPTSTR);
      2: (ftValue: FILETIME);
    end;

  PInternetPerConnOptionList = ^INTERNET_PER_CONN_OPTION_LIST;
  INTERNET_PER_CONN_OPTION_LIST = record
    dwSize        :DWORD;
    pszConnection :LPTSTR;
    dwOptionCount :DWORD;
    dwOptionError :DWORD;
    pOptions      :PInternetPerConnOption;
  end;

.......

function SetProxy(UserAgent, Address, Bypass: string): Boolean; // mladen //@@@NP@@@ - Add bypass to function
var
  list: INTERNET_PER_CONN_OPTION_LIST;
  dwBufSize: DWORD;
  hInternet: Pointer;
  Options: array[1..3] of INTERNET_PER_CONN_OPTION;
begin
  Result := False;
  dwBufSize := SizeOf(list);
  list.dwSize := SizeOf(list);
  list.pszConnection := nil;
  list.dwOptionCount := High(Options); // the highest index of the array (in this case 3)

  //@@@NP@@@ - Note: Options[*].Value.dwValue has now changed to Options[*].dwValue defined in Type "PInternetPerConnOption" above

  Options[1].dwOption := INTERNET_PER_CONN_FLAGS;
//  Options[1].Value.dwValue := PROXY_TYPE_DIRECT or PROXY_TYPE_PROXY; //@@@NP@@@ - Original code
  Options[1].dwValue := PROXY_TYPE_PROXY; //@@@NP@@@ - Modified to force proxy usage and ignore direct connections

  Options[2].dwOption := INTERNET_PER_CONN_PROXY_SERVER;
  Options[2].pszValue := PChar(Address); //@@@NP@@@ - Changed from "PAnsiChar(AnsiString(Address));"

  Options[3].dwOption := INTERNET_PER_CONN_PROXY_BYPASS;
  Options[3].pszValue := PChar(Bypass); //@@@NP@@@ - Changed from "'<local>'"

  list.pOptions := @Options;
  hInternet := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
  if hInternet <> nil then
  try
    Result := InternetSetOption(hInternet, INTERNET_OPTION_PER_CONNECTION_OPTION, @list, dwBufSize);
    Result := Result and InternetSetOption(hInternet, INTERNET_OPTION_REFRESH, nil, 0);
  finally
    InternetCloseHandle(hInternet)
  end;
end;


EmbeddedWB.pas

Kod: Tümünü seç

TProxySettings = class(TPersistent)
  private
    ...
    FBypass: string; //@@@NP@@@ - Add Bypass to ProxySettings
  public
{$IFDEF USE_EwbTools}
    function SetProxy(UserAgent, Address, Bypass: string): Boolean; overload; //@@@NP@@@ - Define Bypass in SetProxy function
{$ENDIF}
  published
    ...
    property Bypass: string read FBypass write FBypass; //@@@NP@@@ - Define Bypass for design-time component    
  end;
  
  
.......


  TEmbeddedWB = class(TCustomEmbeddedWB,
      ...
  private
    FBypass: string; //@@@NP@@@ - Required for Object inspector  
  
  
.......


function TProxySettings.SetProxy(UserAgent, Address, Bypass: string): Boolean; //@@@NP@@@ - Define Bypass in SetProxy function
begin
  Result := EwbTools.SetProxy(UserAgent, Address, Bypass); //@@@NP@@@ - Forward Bypass to EwbTools.pas
  bProxy := Result;
end;


........


procedure TEmbeddedWB.RefreshProxy;
begin
  if FProxySettings.FUserName = '' then
    FProxySettings.SetProxy(FProxySettings.FUserAgent, FProxySettings.FAddress +
      ':' + IntToStr(FProxySettings.FPort), FProxySettings.FBypass) //@@@NP@@@ - Foward Bypass onto SetProxy
  ...
end;


You may have to re-compile the component package to get Bypass to appear in the Object Inspector.

Setting the proxy can be done 3 ways;
1) Object Inspector->ProxySettings->Address/Port/Bypass Etc

2) Coding:

Kod: Tümünü seç

with EmbeddedWb1 do begin
    ProxySettings.Address:='myplace';
    ProxySettings.Port:=222;
    ProxySettings.Bypass:='<local>';
end;
EmbeddedWb1.RefreshProxy;
3) Coding:

Kod: Tümünü seç

EmbeddedWb1.ProxySettings.UserAgent:='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'; // Stolen from "Enigmatic" (Topic: "Setting proxy (I need the fog cleared out.. )") ;D
EmbeddedWb1.ProxySettings.SetProxy(EmbeddedWb1.UserAgent, '127.0.0.1:666', '<local>*.somedomain.co.uk;www.google.co.uk');

That should be everything to get you up and running, I haven't added the code to the username/password SetProxy but just as easy - copy and paste

Bypass can be "<local>", "" (none) or "*.domainname.com". Multiple domains can be added, just split with a semi-colon; "<local>*.somedomain.co.uk;www.google.co.uk".

The reason the proxy didn't work was because the wrong type was defined. I found this at "http://akirabbq.spaces.live.com/blog/cn ... !264.entry".

I have tried to explain in as much detail but any questions just email me.

Just one other thing while I remember, under the SetProxy function there is a variable called "hInternet". See below:

Kod: Tümünü seç

   Result := InternetSetOption(hInternet, INTERNET_OPTION_PER_CONNECTION_OPTION, @list, dwBufSize);
    Result := Result and InternetSetOption(hInternet, INTERNET_OPTION_REFRESH, nil, 0);

This will set the proxy *only* for the EmbeddedWB component, change this to "nil" if you ever need to change the IE proxy.

Feel free to include this in the EmbeddedWB component set and modify/rewrite it.
Cevapla