This Code get Error on Lazarus and Work on Delphi lazarus / 13-General ---------------------------------------------------------------------- XyberX · 2017-03-24 19:29 Code down side have one error on Lazarus 1.6 who due close the app.   But on Delphi Work normal. Uses TypInfo; Procedure TForm1.ListProps; Var  ListaPropriedades : TPropList;  Contador          : Integer; begin  // Preenche uma lista com as propriedades do objeto  GetPropList(TypeInfo(TForm), [tkMethod, tkProcedure], @ListaPropriedades);  // Executa um loop nas propriedades do objeto  Memo1.Clear;  Try   For Contador := 0 to Length(ListaPropriedades) -1 do    Memo1.Lines.Add(ListaPropriedades[Contador]^.Name);  Except  End; end; ---------------------------------------------------------------------- Thaddy · 2017-03-24 20:22 You should test for nil, also in Delphi, that also throws an access violation,,,(in 10.1) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListProps;Var ListaPropriedades : TPropList; Contador          : Integer;begin ListaPropriedades :=Default(TpropList);  //make sure all nil; // Preenche uma lista com as propriedades do objeto GetPropList(TypeInfo(TForm), [tkMethod, tkProcedure], @ListaPropriedades); // Executa um loop nas propriedades do objeto Memo1.Clear; Try  For Contador := Low(ListaPropriedades) to High(ListaPropriedades) do   if ListaPropriedades[Contador]<> nil then  //test for nil       Memo1.Lines.Add(ListaPropriedades[Contador]^.Name); Except   On E:Exception do    Showmessage(e.message); End;end; Your code simply crashes also in Delphi: ---------------------------------------------------------------------- XyberX · 2017-03-24 20:30 Thanks.  Delphi no need this because, he bring only methods <> NIL ---------------------------------------------------------------------- XyberX · 2017-03-24 20:32 I test, problem still... ---------------------------------------------------------------------- Thaddy · 2017-03-24 20:55 I tested the same code in Laz 1.7 + FPC trunk and Delphi Berlin. Behavior is the same. Your code crashes also in Delphi, same error...  My code doesn't, See the screenshot above from the delphi debugger. ---------------------------------------------------------------------- Thaddy · 2017-03-24 21:10 Quote from: XyberX on March 24, 2017, 09:30:26 pm Thanks.  Delphi no need this because, he bring only methods <> NIL That is not true. Same behavior. Note that Delphi will eat the exception during debugging when using except {empty} end; but that will not always work at runtime and outside of the IDE. You should handle the exception. Then you can see that Delphi has the exact same one. If you run your Lazarus project without debugging it will also eat the exception... btw,,, But your code is bad. ---------------------------------------------------------------------- XyberX · 2017-03-24 22:55 What you say? If you need i put one vídeo. My code  is right and i use Berlin.  If you need one prove i due  for you if you need im nos noob and Bring This problem for test because lazarus stable have the problem, you believe ir not  i put one vídeo if necessary ---------------------------------------------------------------------- Deepaak · 2017-03-25 03:26 Quote from: XyberX on March 24, 2017, 11:55:33 pm What you say? If you need i put one vídeo. My code  is right and i use Berlin.  If you need one prove i due  for you if you need im nos noob and Bring This problem for test because lazarus stable have the problem, you believe ir not  i put one vídeo if necessary Please proceed with video? As  your code generate error in delphi. Maybe you are missing something, ASFAIK Lazarus don't have problem. ---------------------------------------------------------------------- Thaddy · 2017-03-25 05:19 As anybody can test that the code crashes under the delphi debugger and in debug mode I would like to see that video. Summary: The code eats the access violations in release mode Both in Delphi and in Lazarus. The code will show the access violations under debugger both in Delphi and in Lazarus. The code uses a fixed array of pointers (16380 in Delphi, 65536 in Lazarus) that is not initialized. The code uses Length() on a fixed array, which is the same as as one of the above numbers. Contrary to a dynamic array Length() will not return the actual number of elements used. Not in Lazarus and not in Delphi. What happens is that the array likely has a lot of nil pointers left and the code tries to read records field on a nil polinter... BOOM! What he should do and what I did for him 1.  Initialize the array so you can be sure they are all nil's in the first place. 1a.The pointers are on the stack and the stack is dirty. Do use Defaut() 2.  Check if you are reading a valid entry by checking for nil 3.  Don't eat the exceptions, but handle them. Or write in such a way you don't need them. 4.  Use proper settings for debug and release. Now make the movie and show us how you solved it. Maybe the best way to demonstrate this is to show you do not even need the exception if you write proper code. Works in Delphi and in Freepascal: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListProps;Var ListaPropriedades : TPropList; Contador          : Integer;begin  ListaPropriedades := Default(TPropList);  // initialize  GetPropList(TypeInfo(TForm), [tkMethod, tkProcedure], @ListaPropriedades);  Memo1.Clear;  For Contador := Low(ListaPropriedades) to High(ListaPropriedades) do    if ListaPropriedades[Contador] <> nil then      memo1.Lines.Add(String(ListaPropriedades[contador]^.name))  // cast removes warning    else      Break; // We're done when we meet nilend; ---------------------------------------------------------------------- ASerge · 2017-03-25 06:39 Quote from: XyberX on March 24, 2017, 08:29:08 pm  Code down side have one error on Lazarus 1.6 who due close the app.   But on Delphi Work normal. I think in Delphi it is also a mistake, because you list an uninitialized data array. Better: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListProps;var  PropList: TPropList;  Info: PTypeInfo;  MethPropCnt: Integer;  i: Integer;begin  Info := TypeInfo(TForm);  MethPropCnt := GetPropList(Info, [tkMethod, tkProcedure], @PropList);  for i := 0 to MethPropCnt - 1 do    Memo1.Lines.Append(PropList[i]^.Name);end;But it will allocate a very large array on the stack, so even better Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListProps;var  PropList: PPropList; // Change to Pointer  Info: PTypeInfo;  AllPropCnt: Integer;  MethPropCnt: Integer;  i: Integer;begin  Info := TypeInfo(TForm);  AllPropCnt := GetTypeData(Info)^.PropCount;  if AllPropCnt > 0 then  begin    GetMem(PropList, SizeOf(PPropInfo) * AllPropCnt);    try      MethPropCnt := GetPropList(Info, [tkMethod, tkProcedure], PropList); // No @      for i := 0 to MethPropCnt - 1 do        Memo1.Lines.Append(PropList^[i]^.Name); // Add ^    finally      FreeMem(PropList);    end;  end;end; ---------------------------------------------------------------------- Thaddy · 2017-03-25 06:41 @ASerge That's why I introduced a default. But the use of propcount is a good one. (gets rid of my break) Note his code simply raises an exception in both Delphi AND Lazarus. ---------------------------------------------------------------------- ASerge · 2017-03-25 07:04 Quote from: Thaddy on March 25, 2017, 07:41:53 am@ASerge That's why I introduced a default. There is no need to Default, because the method GetPropList returns the number of initialized elements. Perhaps only for debugging purposes. ---------------------------------------------------------------------- XyberX · 2017-03-25 17:25 Thanks, you code work on Lazarus 1.6.4 REV 54278.  This is for my REST Dataware for Lazarus, I need know what Methods have on class for publish this.  Thanks again.