【问题标题】:Delphi XE5 ComponentCount segmentation fault (Search parented tcomponent )Delphi XE5 ComponentCount 分段错误(搜索父级 tcomponent )
【发布时间】:2013-12-10 19:21:48
【问题描述】:

此代码收集指定根组件中的所有 TFMXControl。检查父级和组件名称前导。此代码在 Win32 32.bit windows 目标中运行良好,但在 LANC soubrutine 第一行出现页面错误的 Nexus(android 平台)中无法正常工作。我不知道.. :(

procedure  Twmenetlevel.collectXMLControl(root:TComponent;parent:Tcomponent;fieldleading:string;xmlnode:IXMLNode;controlsetting:boolean);
var n:IXMLNode;



procedure feldolgozas(c:tfmxobject);
var s:string;
    node:IXMLNode;
begin
    if lowercase(copy(c.Name,1,3))=fieldleading then
    begin
       s:=withoutnumbers(lowercase(c.Name));

       node:=xmlnode.ChildNodes.FindNode(s);
       if not assigned(node) then
       begin
         node:=xmlnode.AddChild(s);
       end;
       case controlsetting of
       false: begin //olvasás a kontrollokból az XML-be
          if c is tedit then
            node.Text:=(c as tedit).Text;
          if c is Tcalendaredit then
            node.Text:=(c as tCALENDARedit).Text;
          if c is TTimeEdit then
            node.Text:=(c as TTimeEdit).Text;
          if c is TNumberBox then
            node.Text:=(c as TNumberBox).Text;
       end;
       true:begin  // a kontrollok beállítása XML szerint
          if c is tedit then
            (c as tedit).Text:=node.Text;
          if c is Tcalendaredit then
            (c as tCALENDARedit).Text:=node.Text;
          if c is TTimeEdit then
            (c as TTimeEdit).Text:=node.Text;
          if c is TNumberBox then
            (c as TNumberBox).Text:=node.Text;

       end;
       end;
    end;
end;

function isparent(parent:tcomponent;prechild:tfmxobject):boolean;
begin
    result:=false;
    if assigned(prechild) then
    begin
        if prechild.parent=parent then
          result:=true
        else
        begin
           result:=isparent(parent,prechild.parent);
        end;
    end;
end;

procedure lanc(c:tcomponent);
var i,j:integer;
  cp:tcomponent;
begin
  j:=c.ComponentCount;
  for i := 0 to c.ComponentCount-1 do
  begin
    cp:=c.components[i];
    if (cp is tfmxobject) then
    begin
      if (isparent(parent,cp as tfmxobject)) then
      begin
         feldolgozas(c.components[i] as tfmxobject);
      end;
    end;
    lanc(c.components[i]);
  end;
end;

begin
   lanc(root);
end;

这也不起作用,但它非常简单。 (Win32工作正常) (Tform1 简单的移动表单)

procedure TForm1.Button1Click(Sender: TObject);
    var
    i: Integer;
    s:string;
begin

for i := 0 to self.ComponentCount-1 do
begin
  s:=s+self.Components[i].Name;

end;
end;

【问题讨论】:

    标签: android delphi tcomponent


    【解决方案1】:

    第一行,即您声称错误的那一行,是:

    j:=c.ComponentCount;
    

    由于j 是一个局部变量,我们可以断定c 是问题所在。因此,显然c 不是对实例的有效引用。

    现在,c 是函数的参数,你传递了root。由此我得出结论,您传递给Twmenetlevel.collectXMLControl 的参数root 无效。

    因此,下一步是查看对Twmenetlevel.collectXMLControl 的调用,并找出您传递的参数无效的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多