Я использую Delphi Embedding Chromium (CEF1) в своем приложении, и у меня возникли проблемы с чтением данных cookie для URL-адреса.
Я нашел этот код (приведен ниже), но на XE3 я получаю исключение, когда я использую его об этой строке:
if WaitForSingleObject(vis.pEvent.Handle, INFINITE) = WAIT_OBJECT_0 then begin
Исключение составляет
Проект guiclient.exe вызвал класс исключения EAccessViolation с сообщением «Нарушение прав доступа по адресу 00000000». Чтение адреса 00000000
подразумевая, что один из объектов не создан или не инициализирован должным образом.
Код, который я использую (скопирован из указанной выше ссылки на форуме):
TCustomVisitor = class (TCefCookieVisitorOwn)
private
fcookie: PCefCookie;
function visit(const name, value, domain, path: ustring; secure, httponly,
hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;
count, total: Integer; out deleteCookie: Boolean): Boolean; override;
public
pEvent: TEvent;
function getCookies: PCefCookie;
constructor Create; override;
end;
constructor TCustomVisitor.Create;
begin
inherited;
pEvent := TEvent.Create(nil, False, False, 'ev.chromium');
new(fcookie);
end;
function TCustomVisitor.getCookies;
begin
Result := fcookie;
end;
function TCustomVisitor.visit(const name, value, domain, path: ustring; secure, httponly,
hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;
count, total: Integer; out deleteCookie: Boolean): Boolean;
begin
fcookie.name := CefString(name);
fcookie.value := CefString(value);
fcookie.domain := CefString(domain);
fcookie.path := CefString(path);
fcookie.secure := secure;
fcookie.httponly := httponly;
fcookie.has_expires := hasExpires;
//fcookie.creation := DateTimeToCefTime(creation);
//fcookie.last_access := DateTimeToCefTime(lastAccess);
//fcookie.expires := DateTimeToCefTime(expires);
SetEvent(pEvent.Handle);
end;
procedure TfrmAuth.bt_okClick(Sender: TObject);
var
vis: TCustomVisitor;
cname, cvalue: uString;
ccookie: PCefCookie;
begin
if crm.Browser<>nil then begin
vis := TCustomVisitor.Create;
try
CefVisitUrlCookies(ed_url.Text, true, vis);
// !!! This line causes the access violation
if WaitForSingleObject(vis.pEvent.Handle, INFINITE) = WAIT_OBJECT_0 then begin
ccookie := vis.getCookies;
cname := CefString(@ccookie.name);
cvalue := CefString(@ccookie.value);
end;
finally
vis.Free;
end;
end;
end;