2013-11-25 1 views
0

Этот код собирает все TFMXControls в указанном корневом компоненте. Проверьте родителя и имя компонента. Этот код отлично работает в Win32 32.bit, но не в Nexus (платформа Android) с ошибкой страницы в первой строке LANC. Я понятия не имею .. :(Ошибка сегментации компонента Delphi XE5 (поиск по исходному tcomponent)

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; 

ответ

1

Первая линия линия, что вы утверждаете недостатки, является:

j:=c.ComponentCount; 

Поскольку j является локальной переменной, мы можем подставить что проблема связана с c. Итак, ясно, что c не является действительной ссылкой на экземпляр.

Теперь, c является параметром функции, и вы прошли root. Из чего я заключаю, что root, параметр, который вы передали Twmenetlevel.collectXMLControl, недействителен.

Итак, ваш следующий шаг - посмотреть на вызов Twmenetlevel.collectXMLControl и выяснить, почему переданный вами параметр недействителен.