删除后TChromium无法正常工作并再次创建组件

时间:2015-03-13 20:06:23

标签: delphi delphi-7 tchromium

这是我的代码:

主页按钮:

LimparComponentes(Self);
CriarTela(Janela, Self, Self.DsnStage);

LimparComponentes程序:

var
myListWeb: TList;

myListWeb := TList.Create;

for i := 0 to Form.ComponentCount - 1 do
begin
  if (Form.Components[i].ClassType = TNeocWebBrowser) then
    begin
      if ParentIsStage(TNeocWebBrowser(Form.Components[i])) then
      begin
        myListWeb.Add(Form.Components[i]);
      end;
    end
end;

for i := 0 to (MyListWeb.Count - 1) do
  begin
    obj := myListWeb.items[i];
    FreeAndNil(obj);
  end;
  myListWeb.Clear;

CriarTela程序:

for j := 0 to TelaC.ListaWebs.Count - 1 do
    begin
      complist.Add(CreateWeb(TelaC.ListaWebs.getWeb(j), Form, carroussel));
    end;

CreateWeb功能

function CreateWeb(obj: TWeb; Form: TForm; AParent: TWinControl): pointer;
begin
  if Form.ClassType = TFormSimulando then
    result := CreateWebReal(obj, form, aparent, TNeocWebBrowser.Create(Form))
  else
    result := CreateWebFake(obj, form, aparent,
      TNeoWebBrowserPanel.Create(form));
end;

CreateWebReal函数:

function CreateWebReal(obj: TWeb; Form: TForm; AParent: TWinControl; ref:
  pointer): TNeocWebBrowser;
var
  comp: TComponent;
  NewName: string;
  _nmesas: integer;
  tempURL: string;
begin
  _nmesas := obj.Indice;
  NewName := 'Web_' + IntToStr(_nmesas);
  comp := form.FindComponent(NewName);
  while Assigned(comp) do
  begin
    _nmesas := _nmesas + 1;
    NewName := 'Web_' + IntToStr(_nmesas);
    comp := form.FindComponent(NewName);
  end;

  if not Assigned(ref) then
    Result := TNeocWebBrowser.Create(Form)
  else
    Result := TNeocWebBrowser(ref);

  with Result do
  begin
    //ParentWindow := AParent.Handle;
    TWinControl(Result).Parent := AParent;
    CName := NewName;
    obj.Nome := newName;
    ShowHint := Form.ClassType <> TFormSimulando; //true;
    Hint := 'Web: ' + NewName;
    CHandle := obj.chandle;
    Seed := obj.semente;
    SeedJanela := obj.sementejanela;
    objBotaoEstrutura := obj;

    //    PopupMenu := getPopupMenu(form);

    Left := ZoomInteger(obj.esquerda);
    Top := ZoomInteger(obj.topo);
    Width := ZoomInteger(obj.largura);
    Height := ZoomInteger(obj.altura);
    Endereco := obj.Endereco;

    if Form.ClassType = TFormSimulando then
    begin
      //      Result.Navigate(Endereco);

      if Assigned(Result.Browser) then
        if ASsigned(Result.Browser.GetMainFrame) then
          Result.Browser.GetMainFrame.LoadUrl(Endereco);

    end;

    Repaint;
  end;
end;

TNeocWebBrowser组件:

unit NeocWebBrowser;

interface

uses
  SysUtils, Classes, Controls, cefvcl, ceflib,
  SimpleTimer, Graphics;

type
  TNeocWebBrowser = class(TChromium)
  private
    FEndereco: String;
    FName: string;
  protected
  public
    Seed: Integer;
    SeedJanela: Integer;
    CHandle: Integer;
    objBotaoEstrutura: Pointer;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy(); override;
  published
    property Endereco: string read FEndereco write FEndereco;
    property CName: string read fname write fname;
    property OnClick;
    property OnMouseUp;
    property OnMouseDown;
    property OnMouseMove;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Neocontrol', [TNeocWebBrowser]);
end;

constructor TNeocWebBrowser.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Parent := TWinControl(AOwner);
  Height := 30;
  Width := 30;
  Visible := True;
end;

destructor TNeocWebBrowser.Destroy;
begin

  inherited;
end;

end.

基本上我的问题是:我可以打开TNeocWebBrowser一次,但是当我点击主页按钮或我更改屏幕并返回上一屏幕的任何按钮时,TNeocWebBrowser不再显示。我需要关闭此表单并再次打开以查看TNeocWebBrowser。请下载视频以更好地了解我的问题。

Video explanation about the problem

非常感谢!

1 个答案:

答案 0 :(得分:0)

我更改了这一行:

if Assigned(Result.Browser) then
        if ASsigned(Result.Browser.GetMainFrame) then
          Result.Browser.GetMainFrame.LoadUrl(Endereco);

有:

Result.Load(Endereco);

工作正常。