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



这是我的代码:

主页按钮:

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

LimparComponentes Procedure:

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;

创建网页功能

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;

创建网络真实功能:

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;

网络浏览器组件:

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。请下载视频以更好地了解我的问题。

有关问题的视频说明

谢谢!

我更改了这一行:

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

为:

Result.Load(Endereco);

它工作正常。

相关内容

  • 没有找到相关文章

最新更新