В общем, задачу абы-как решил. Только после закрытия программы вылазит ошибка "Exception EAccessViolation in module Project1.exe at 0012C5D5. Access violation at address 0052C5DB in module 'Project.exe'. Read of address 00000000."
Весь код(если это можно назвать кодом):
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cefvcl, StdCtrls ,ceflib, sButton, Grids, AdvObj, BaseGrid, AdvGrid,
sGroupBox, OleCtrls, SHDocVw;
type
CefTask = class(TCefTaskOwn)
procedure Execute; override;
end;
type
TForm1 = class(TForm)
Chromium1: TChromium;
sGroupBox3: TsGroupBox;
SGrid: TAdvStringGrid;
sButton1: TsButton;
Edit2: TEdit;
OpenDialog1: TOpenDialog;
Button1: TButton;
Label1: TLabel;
Memo1: TMemo;
Button2: TButton;
procedure sButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Auth;
procedure NextPage;
procedure GoDirect;
procedure Chromium1LoadEnd(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; httpStatusCode: Integer);
procedure StringVisitor(const str: ustring);
Procedure Delay(mSec:Cardinal);
function GetSourceHTML: string;
procedure Button2Click(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
proc, index:integer;
page:string;
PageLoaded:boolean;
implementation
Uses Unit2;
{$R *.dfm}
function Pars(T_, ForS, _T: string): string;
var
a, b: integer;
begin
Result := '';
if (T_ = '') or (ForS = '') or (_T = '') then Exit;
a := Pos(T_, ForS);
if a = 0 then Exit
else a := a + Length(T_);
ForS := Copy(ForS, a, Length(ForS) - a + 1);
b := Pos(_T, ForS);
if b > 0 then Result := Copy(ForS, 1, b - 1);
end;
procedure CefTask.Execute;
var
CookieManager: ICefCookieManager;
begin
CookieManager := TCefCookieManagerRef.Global;
CookieManager.DeleteCookies('', '');
end;
procedure ClearCookies;
var
Task: CefTask;
begin
Task := CefTask.Create;
CefPostTask(TID_IO, Task);
end;
procedure Tform1.Auth;
Var CodeStr : string;
begin
if Assigned(Form1.Chromium1.Browser) and Assigned(Form1.Chromium1.Browser.Mainframe) then
begin
CodeStr := 'document.forms[0].login.value="'+SGrid.Cells[3,Index]+'";';
Chromium1.Browser.MainFrame.ExecuteJavaScript(CodeStr, 'about:blank', 0);
CodeStr := 'document.forms[0].passwd.value="'+SGrid.Cells[4,Index]+'";';
Chromium1.Browser.MainFrame.ExecuteJavaScript(CodeStr, 'about:blank', 0);
CodeStr := 'document.forms[0].submit();';
Chromium1.Browser.MainFrame.ExecuteJavaScript(CodeStr, 'about:blank', 0);
end;
proc:=2;
end;
procedure TForm1.NextPage;
begin
clearCookies;
if PageLoaded=true then
begin
if index<SGrid.RowCount then
begin
Chromium1.Load('https://passport.yandex.ru/auth');
proc:=1;
inc(index);
LAbel1.Caption:=inttostr(index);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
pageloaded:=true;
index:=1;
NextPage;
end;
procedure TForm1.GoDirect;
begin
Chromium1.Load('****');
proc:=3;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
index:=Sgrid.RowCount;
clearCookies;
Chromium1.Load('****');
end;
procedure TForm1.StringVisitor(const str: ustring);
var status:string;
begin
Memo1.Text:=str;
if Pos('***',Memo1.Text)<>0 then
begin
...
PageLoaded:=true;
NextPage;
end
else
begin
....
PageLoaded:=true;
NextPage;
end;
end;
function TForm1.GetSourceHTML: string;
var
CefStringVisitor:ICefStringVisitor;
begin
CefStringVisitor := TCefFastStringVisitor.Create(StringVisitor);
Chromium1.Browser.MainFrame.GetSource(CefStringVisitor);
end;
procedure TForm1.Chromium1LoadEnd(Sender: TObject; const browser: ICefBrowser;
const frame: ICefFrame; httpStatusCode: Integer);
begin
if (HttpStatusCode = 200) and Frame.IsMain then
begin
case proc of
0:begin end;
1:begin pageloaded:=false; Auth; end;
2:begin GoDirect; end;
3:begin GetSourceHTML; end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SGrid.RowHeights[1]:=0;
proc:=0;
end;
procedure TForm1.sButton1Click(Sender: TObject);
Var I:integer;
P:TPars;
begin
if OpenDialog1.Execute then
begin
Edit2.Text:=OpenDialog1.Filename;
P:=TPars.Create;
end;
end;
end.
Буду признателен, кто подскажет как ошибку убрать.
ЗЫ. Не обессудьте, с делфи практически не работал. Спасибо.