Bom dia a todos. Estou fazendo um menu treeview para meu sistema. Fiz o código mostrado abaixo. Ele executou perfeitamente algumas vezes depois começou dar access violation, passei para outra máquina, funcionou umas duas vezes e depois o mesmo erro. Acredito que seja algum problema de memória, mas não consigo corrigir. Alguém poderia me ajudar?
Desde já agradeço. Código: TMenu = Record iId_Nivel: Integer; sDs_Opcao: String; iId_Nivel_Ch: Integer; // sNm_Form: String; end; pMenu = ^TMenu; procedure TfrmMenuModulos.FormCreate(Sender: TObject); var Menu: pMenu; sTexto: String; tnInd: TTreeNode; aNode: Array of TTreeNode; i: Integer; begin inherited; VerificaQuery; if LoginUsuario then Inicializa_Menu; All_QryAux.Close; All_QryAux.SQL.Clear; All_QryAux.SQL.Add(' SELECT ID_NIVEL,'); All_QryAux.SQL.Add(' DS_OPCAO,'); All_QryAux..SQL.Add(' ID_NIVEL_CHAMAR,'); All_QryAux.SQL.Add(' NM_FORM'); All_QryAux.SQL.Add(' FROM CTRL_MENU'); All_QryAux.SQL.Add(' WHERE ID_PROJETO = ' + IntToStr(dmDataBase.id_Projeto)); All_QryAux.SQL.Add(' AND ID_MODULO = ' + IntToStr(dmDataBase.id_Modulo)); All_QryAux.SQL.Add(' ORDER BY ID_NIVEL, ID_ITEM'); All_QryAux.Open; i := 0; tvMenu.Items.Clear; SetLength(aNode, All_QryAux.RecordCount); All_QryAux.First; While not All_QryAux.Eof do begin New(Menu); Menu^.iId_Nivel := All_QryAux.FieldByName('ID_NIVEL').AsInteger; Menu^.sDs_Opcao := All_QryAux.FieldByName('DS_OPCAO').AsString; Menu^.iId_Nivel_Ch := All_QryAux.FieldByName('ID_NIVEL_CHAMAR').AsInteger; // Menu^.sNm_Form := All_QryAux.FieldByName('NM_FORM').AsString; sTexto := Trim(All_QryAux.FieldByName('DS_OPCAO').AsString); If All_QryAux.FieldByName('ID_NIVEL').AsInteger = 1 then aNode[i]:= tvMenu.Items.AddObject(Nil, sTexto, Menu) else begin tnInd := IndiceHie(Menu); aNode[i] := tvMenu.Items.AddChildObject(tnInd, sTexto, Menu); end; Inc(i); All_QryAux.Next; Dispose(Menu); end; For i := Low(aNode) to High(aNode) do If aNode[i] <> Nil then aNode[i].Expanded:= True; tvMenu.FullCollapse; end; function TfrmMenuModulos.IndiceHie(p_Hie: pMenu): TTreeNode; Var i: Integer; begin Result:= Nil; For i := 0 to tvMenu.Items.Count do begin If (pMenu(tvMenu.Items[i].Data)^.iId_Nivel_Ch = p_Hie^.iId_Nivel) then begin Result:= tvMenu..Items[i]; Break; end; end; end; Novos endereços, o Yahoo! que você conhece. Crie um email novo com a sua cara @ymail.com ou @rocketmail.com. http://br.new.mail.yahoo.com/addresses [As partes desta mensagem que não continham texto foram removidas]