Recent

Author Topic: PageControl + SynEdit - PageControl.ActivePage.Free  (Read 9932 times)

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #15 on: January 05, 2018, 03:30:52 pm »
slightly modified code but the meaning is the same and the error below
...
Also not helped
I replaced TSynEdit, because it cannot compile to me, with TMemo. I saw a demonstration. The error does not reproduced.
Lazarus 1.8 x64, Windows.
Lazarus 1.8 x32, Windows. the same error with TSynEdi checked

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #16 on: January 05, 2018, 03:38:56 pm »
Some basic changes to the provided code that should stop any sigsegv errors on the sample provided. I had no problem deleting all the pages created at start up and exit the application. as always tests where run with lazarus 1.6.4 only on windows 7.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   Tab: TTabSheet;
  4.   rSynEdit: TSynEdit;
  5.   i: integer;
  6. begin
  7.   for i := 0 to 7 do
  8.   begin
  9.     Tab := TTabSheet.Create(self);
  10.     Tab.PageControl := PageControl1;
  11.     Tab.Caption := Format('Tab%d', [i]);
  12.     Tab.PageControl.ActivePage := Tab;
  13.  
  14.     rSynEdit := TSynEdit.Create(Tab);
  15.     rSynEdit.Parent := Tab;
  16.     rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  17.     rSynEdit.PopupMenu := PopupMenu1;
  18.     rSynEdit.Align := alClient;
  19.     rSynEdit.RightEdge := 0;
  20.     rSynEdit.BorderStyle := bsNone;
  21.   end;
  22.  
  23. end;
  24.  
  25. procedure TForm1.MenuItem1Click(Sender: TObject);
  26. begin
  27.   if Assigned(PageControl1.ActivePage) then
  28.     (PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1)) as TSynEdit).CopyToClipboard;
  29. end;
  30.  
  31. procedure TForm1.MenuItem2Click(Sender: TObject);
  32. begin
  33.   if Assigned(PageControl1.ActivePage) then
  34.     ShowMessage((PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1)) as TSynEdit).Name);
  35. end;
  36.  
  37. procedure TForm1.MenuItem3Click(Sender: TObject);
  38. begin
  39.   if Assigned(PageControl1.ActivePage) then PageControl1.ActivePage.Free;
  40. end;
  41.  
  42. procedure TForm1.Button1Click(Sender: TObject);
  43. var
  44.   tab: TTabSheet;
  45. begin
  46.   if not Assigned(PageControl1.ActivePage) then Exit;
  47.   tab := PageControl1.ActivePage;
  48.   tab.Free;
  49. end;
  50.  
« Last Edit: January 05, 2018, 03:40:54 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #17 on: January 05, 2018, 03:46:41 pm »
Some basic changes to the provided code that should stop any sigsegv errors on the sample provided. I had no problem deleting all the pages created at start up and exit the application. as always tests where run with lazarus 1.6.4 only on windows 7.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   Tab: TTabSheet;
  4.   rSynEdit: TSynEdit;
  5.   i: integer;
  6. begin
  7.   for i := 0 to 7 do
  8.   begin
  9.     Tab := TTabSheet.Create(self);
  10.     Tab.PageControl := PageControl1;
  11.     Tab.Caption := Format('Tab%d', [i]);
  12.     Tab.PageControl.ActivePage := Tab;
  13.  
  14.     rSynEdit := TSynEdit.Create(Tab);
  15.     rSynEdit.Parent := Tab;
  16.     rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  17.     rSynEdit.PopupMenu := PopupMenu1;
  18.     rSynEdit.Align := alClient;
  19.     rSynEdit.RightEdge := 0;
  20.     rSynEdit.BorderStyle := bsNone;
  21.   end;
  22.  
  23. end;
  24.  
  25. procedure TForm1.MenuItem1Click(Sender: TObject);
  26. begin
  27.   if Assigned(PageControl1.ActivePage) then
  28.     (PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1)) as TSynEdit).CopyToClipboard;
  29. end;
  30.  
  31. procedure TForm1.MenuItem2Click(Sender: TObject);
  32. begin
  33.   if Assigned(PageControl1.ActivePage) then
  34.     ShowMessage((PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1)) as TSynEdit).Name);
  35. end;
  36.  
  37. procedure TForm1.MenuItem3Click(Sender: TObject);
  38. begin
  39.   if Assigned(PageControl1.ActivePage) then PageControl1.ActivePage.Free;
  40. end;
  41.  
  42. procedure TForm1.Button1Click(Sender: TObject);
  43. var
  44.   tab: TTabSheet;
  45. begin
  46.   if not Assigned(PageControl1.ActivePage) then Exit;
  47.   tab := PageControl1.ActivePage;
  48.   tab.Free;
  49. end;
  50.  
Та же ошибка возможно это связано с версией Lazarus попробую скачать пониже версию но хотя я давно не мог побороть эту ошибку как проверю отпишу если у кого есть идеи пишите буду пробовать все варианты!

The same error probably it is connected with the version of Lazarus I'll try to download lower version but although I wasn't able to overcome this error how to check otpishu if anyone has ideas please write I will try all the options!

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #18 on: January 05, 2018, 04:01:40 pm »
The same error probably it is connected with the version of Lazarus I'll try to download lower version but although I wasn't able to overcome this error how to check otpishu if anyone has ideas please write I will try all the options!
the problem has nothing to do with the lcl or its components it has to do with your code. For example, you never check if findcomponent returned nil or not and that is enough to raise a sigsegv. The problem is in your code alone.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #19 on: January 05, 2018, 04:05:12 pm »
The same error probably it is connected with the version of Lazarus I'll try to download lower version but although I wasn't able to overcome this error how to check otpishu if anyone has ideas please write I will try all the options!
the problem has nothing to do with the lcl or its components it has to do with your code and your code only. for example you never check if findcomponent returned nil or not and that is enough to raise an sigsegv. The problem is in your code alone.
Я ваш код скопировал 1 в 1 и испробовал та же ошибка еще скачал Lazarus 1.6.4 все та же ошибка Если не верите что я проверяю ваш код могу скинуть проект для меня это важней чем кому либо кто мне помогает так что я проверяю все варианты!

I copied your code 1 to 1 and tried the same error even downloaded Lazarus 1.6.4 all the same error If you do not believe what I test your code can throw off the project for me is more important than anyone else who helps me so I check all the options!
« Last Edit: January 05, 2018, 04:08:29 pm by BIT »

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #20 on: January 05, 2018, 04:12:50 pm »
The same error probably it is connected with the version of Lazarus I'll try to download lower version but although I wasn't able to overcome this error how to check otpishu if anyone has ideas please write I will try all the options!
the problem has nothing to do with the lcl or its components it has to do with your code. For example, you never check if findcomponent returned nil or not and that is enough to raise a sigsegv. The problem is in your code alone.

Сейчас еще попробую на другом компьютере возможно ошибка в системе windows

Now another try on a different computer, maybe the error in windows

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #21 on: January 05, 2018, 04:15:29 pm »
I copied your code 1 to 1 and tried the same error even downloaded Lazarus 1.6.4 all the same error If you do not believe what I test your code can throw off the project for me is more important than anyone else who helps me so I check all the options!
OK here it is in pascal, you might understand it better.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   Tab: TTabSheet;
  4.   rSynEdit: TSynEdit;
  5.   i: integer;
  6. begin
  7.   for i := 0 to 7 do
  8.   begin
  9.     Tab := TTabSheet.Create(self);
  10.     Tab.PageControl := PageControl1;
  11.     Tab.Caption := Format('Tab%d', [i]);
  12.     Tab.PageControl.ActivePage := Tab;
  13.  
  14.     rSynEdit := TSynEdit.Create(Tab);
  15.     rSynEdit.Parent := Tab;
  16.     rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  17.     rSynEdit.PopupMenu := PopupMenu1;
  18.     rSynEdit.Align := alClient;
  19.     rSynEdit.RightEdge := 0;
  20.     rSynEdit.BorderStyle := bsNone;
  21.   end;
  22.  
  23. end;
  24.  
  25. procedure TForm1.MenuItem1Click(Sender: TObject);
  26. var
  27.   vCmp:TComponent;
  28. begin
  29.   //If (sender is TSynedit) then TSynedit(Sender).CopyToClipBoard; //<--- better option.
  30.   if Assigned(PageControl1.ActivePage) then begin
  31.     vCmp := PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1));
  32.     if Assigned(vCmp) and (vCmp is TSynEdit) then begin
  33.       TSynEdit(vCmp).CopyToClipboard;
  34.     end else showmessage('synedit not found');
  35.   end;
  36. end;
  37.  
  38. procedure TForm1.MenuItem2Click(Sender: TObject);
  39. var
  40.   vCmp : TComponent;
  41. begin
  42.   if Assigned(PageControl1.ActivePage) then begin
  43.     vCmp := PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1));
  44.     if Assigned(vCmp) and (vCmp is TSynEdit) then
  45.       ShowMessage(TSynEdit(vCmp).Name);
  46.     else showmessage('synedit not found');
  47.   end
  48. end;
  49.  
  50. procedure TForm1.MenuItem3Click(Sender: TObject);
  51. begin
  52.   if Assigned(PageControl1.ActivePage) then PageControl1.ActivePage.Free;
  53. end;
  54.  
  55. procedure TForm1.Button1Click(Sender: TObject);
  56. var
  57.   tab: TTabSheet;
  58. begin
  59.   if not Assigned(PageControl1.ActivePage) then Exit;
  60.   tab := PageControl1.ActivePage;
  61.   tab.Free;
  62. end;
  63.  
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #22 on: January 05, 2018, 04:31:32 pm »
I copied your code 1 to 1 and tried the same error even downloaded Lazarus 1.6.4 all the same error If you do not believe what I test your code can throw off the project for me is more important than anyone else who helps me so I check all the options!
OK here it is in pascal, you might understand it better.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   Tab: TTabSheet;
  4.   rSynEdit: TSynEdit;
  5.   i: integer;
  6. begin
  7.   for i := 0 to 7 do
  8.   begin
  9.     Tab := TTabSheet.Create(self);
  10.     Tab.PageControl := PageControl1;
  11.     Tab.Caption := Format('Tab%d', [i]);
  12.     Tab.PageControl.ActivePage := Tab;
  13.  
  14.     rSynEdit := TSynEdit.Create(Tab);
  15.     rSynEdit.Parent := Tab;
  16.     rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  17.     rSynEdit.PopupMenu := PopupMenu1;
  18.     rSynEdit.Align := alClient;
  19.     rSynEdit.RightEdge := 0;
  20.     rSynEdit.BorderStyle := bsNone;
  21.   end;
  22.  
  23. end;
  24.  
  25. procedure TForm1.MenuItem1Click(Sender: TObject);
  26. var
  27.   vCmp:TComponent;
  28. begin
  29.   //If (sender is TSynedit) then TSynedit(Sender).CopyToClipBoard; //<--- better option.
  30.   if Assigned(PageControl1.ActivePage) then begin
  31.     vCmp := PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1));
  32.     if Assigned(vCmp) and (vCmp is TSynEdit) then begin
  33.       TSynEdit(vCmp).CopyToClipboard;
  34.     end else showmessage('synedit not found');
  35.   end;
  36. end;
  37.  
  38. procedure TForm1.MenuItem2Click(Sender: TObject);
  39. var
  40.   vCmp : TComponent;
  41. begin
  42.   if Assigned(PageControl1.ActivePage) then begin
  43.     vCmp := PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1));
  44.     if Assigned(vCmp) and (vCmp is TSynEdit) then
  45.       ShowMessage(TSynEdit(vCmp).Name);
  46.     else showmessage('synedit not found');
  47.   end
  48. end;
  49.  
  50. procedure TForm1.MenuItem3Click(Sender: TObject);
  51. begin
  52.   if Assigned(PageControl1.ActivePage) then PageControl1.ActivePage.Free;
  53. end;
  54.  
  55. procedure TForm1.Button1Click(Sender: TObject);
  56. var
  57.   tab: TTabSheet;
  58. begin
  59.   if not Assigned(PageControl1.ActivePage) then Exit;
  60.   tab := PageControl1.ActivePage;
  61.   tab.Free;
  62. end;
  63.  
Sorry but I'm in the first post wrote that there is no TObject where he go I'm interested but not this)) showmessage('synedit' not found');
Ps: In Pascal programming for 16 years I think that you understand half the words)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #23 on: January 05, 2018, 04:34:09 pm »
Sorry but I'm in the first post wrote that there is no TObject where he go I'm interested but not this)) showmessage('synedit' not found');
Ps: In Pascal programming for 16 years I think that you understand half the words)
I understand none of the words sorry. I'm out. I'll let some one that talks your language to explain.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #24 on: January 05, 2018, 04:40:20 pm »
Sorry but I'm in the first post wrote that there is no TObject where he go I'm interested but not this)) showmessage('synedit' not found');
Ps: In Pascal programming for 16 years I think that you understand half the words)
I understand none of the words sorry. I'm out. I'll let some one that talks your language to explain.
I don't want to hurt me too hard in their own language to communicate I just want to solve the problem and thank you for your help.

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #25 on: January 05, 2018, 05:06:53 pm »
Sorry but I'm in the first post wrote that there is no TObject where he go I'm interested but not this)) showmessage('synedit' not found');
Ps: In Pascal programming for 16 years I think that you understand half the words)
I understand none of the words sorry. I'm out. I'll let some one that talks your language to explain.
If you have been offended?) Ps: In Pascal programming for 16 years I think that you understand half the words)
In the Russian language this means that we understand each other well) (I hope this time the translator has translated correctly)

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #26 on: January 05, 2018, 05:17:29 pm »
Проверка на другом компьютере вызывает  ошибку

Check on another computer causing the error

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #27 on: January 05, 2018, 05:33:49 pm »
Еще раз:

Есть 10 вкладок с редактором, удаляем  вкладку 7, остается 9 вкладок, вкладка 1,2,3,4,5,6 остаются рабочими, вкладки 7,8,9 вызывают ошибку!

Again:

There are 10 tabs with the editor, remove the tab 7, is 9 tabs, tab 1,2,3,4,5,6 remain working, tabs 7,8,9 fail!

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #28 on: January 05, 2018, 05:46:22 pm »
It's difficult to me too, understand the english translation. But I think @taazz is right:

I think
the problem has nothing to do with the lcl or its components it has to do with your code. For example, you never check if findcomponent returned nil or not and that is enough to raise a sigsegv. The problem is in your code alone.

I see in your code, you use the name of the component to  obtain the reference:

Code: Pascal  [Select][+][-]
  1. 'syed' + IntToStr(PageControl1.ActivePageIndex + 1)

That's a bad idea. Every time you delete pages, the name of the SynEdit is not yet related to the "PageControl1.ActivePageIndex".

As I told you in other post: You really need to include better error routines in your code.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #29 on: January 05, 2018, 05:47:17 pm »
One last effort to explain.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MenuItem1Click(Sender: TObject);
  2. var
  3.   vCmp:TComponent;
  4. begin
  5.   if Assigned(PageControl1.ActivePage) then begin
  6.     vCmp := PageControl1.ActivePage.FindComponent('syed' + IntToStr(PageControl1.ActivePageIndex + 1));
  7.     if Assigned(vCmp) and (vCmp is TSynEdit) then begin
  8.       TSynEdit(vCmp).CopyToClipboard;
  9.     end else showmessage('synedit not found');
  10.   end;
  11. end;
  12.  
activepageindex is not always synchronised with the synedit name you can't use it.
try this.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MenuItem1Click(Sender: TObject);
  2. begin
  3.   if (ActiveControl is TSynEdit) then TSynEdit(ActiveControl).CopyToClipboard;
  4. end;
  5.  
If you have been offended?)
I'm not offended no. But I can't think of any more ways to say the same thing, perhaps some one can translate to Russian to help.
« Last Edit: January 05, 2018, 05:53:35 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018