Recent

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

BIT

  • Full Member
  • ***
  • Posts: 158
PageControl + SynEdit - PageControl.ActivePage.Free
« on: January 05, 2018, 09:43:49 am »
Здравствуйте возникла не преодолимая ошибка c динамическими созданными компонентами TabSheet+TSynEdit (PageControl.ActivePage.Free)
Если удалить последнею вкладку все работает отлично, а если удалить любую другую предыдущие вкладки по index в основном 2 теряют sender внутри TabSheet то есть больше нельзя скопировать вставить текст обратиться к SynEdit по имени и т.п.

Hello was no insurmountable error c dynamic created components TabSheet+TSynEdit (PageControl.ActivePage.Free)
If you remove the last tab, everything works fine, but if remove any other previous tab index is basically 2 lose a sender inside a TabSheet that is no longer possible to copy paste the text to refer to SynEdit by name, etc.


Еще раз:

Есть 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!

Так создаю:
So creating:
Code: Pascal  [Select][+][-]
  1. var
  2.  Tab: TTabSheet;
  3.   rSynEdit: TSynEdit;  
  4.  
  5. ....................................................................
  6.  
  7.   Tab := TTabSheet.Create(self);
  8.   Tab.PageControl := PageControl1;
  9.   Tab.Caption := TabCaption;
  10.   Tab.PageControl.ActivePage := Tab;
  11.  
  12.   rSynEdit := TSynEdit.Create(Tab);
  13.   rSynEdit.Parent := Tab;
  14.   rSynEdit.Align := alClient;
  15.   rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  16.  
  17.  


Так удаляю:
So remove:
Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.MenuItem16Click(Sender: TObject);
  3. begin
  4.   PageControl1.ActivePage.Free;
  5.  end;    
  6.  
  7.  

VIDEO : https://youtu.be/N8PC2XOx5dc
Прикрепил картинку тут я удалил ActivePage и после в активной вкладке попытался скопировать текст в буфер обмена и получил ошибку.
Attached the picture here I have removed ActivePage and after the active tab has tried to copy the text to clipboard and got an error.
« Last Edit: January 05, 2018, 05:34:06 pm by BIT »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #1 on: January 05, 2018, 10:52:32 am »
Use Applicatione.ReleaseComponent() instead?

Bart

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #2 on: January 05, 2018, 10:57:54 am »
Use Applicatione.ReleaseComponent() instead?

Bart
Пробовал все тоже самое даже пытался удалять по отдельности отвязывать друг от друга ничего не помогает((

Tried all the same even tried to remove individually, to decouple from each other helps nothing((

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #3 on: January 05, 2018, 11:04:30 am »
Use Applicatione.ReleaseComponent() instead?

Bart
PageControl1.ActivePage.Free; Удаляет компонент и все что в нем вложено но еще что то зацепляет по index компонентов других вкладок а вот что понять не могу
Кстати если удалить компонент SynEdit отдельно не удаляя самой вкладки тогда остальные SynEdit работают отлично

PageControl1.ActivePage.Free; Removes a component and all that invested in it but still that gear for index components the other tabs but what I can not understand
By the way if you remove SynEdit component separately without deleting the tab itself then the rest SynEdit works fine

VIDEO : https://youtu.be/N8PC2XOx5dc


« Last Edit: January 05, 2018, 12:13:29 pm by BIT »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #4 on: January 05, 2018, 12:20:52 pm »
You can't use TTabsheet.Free in this case because tabsheets are managed internally by the control.
You need access to the protected RemovePage() method.
Note that you are not allowed to remove the last tabsheet if it is the only one remaining (a widgetset limitation I think).

Try this: in a new Lazarus project drop a button and a pagecontrol on the main form.
Complete as follows:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, Forms, Controls, ComCtrls, StdCtrls, SynEdit;
  9.  
  10. type
  11.  
  12.   TPageControl = class(ComCtrls.TPageControl)  // this is a hack to give access to protected methods
  13.   end;
  14.  
  15.   TForm1 = class(TForm)
  16.     PageControl1: TPageControl;
  17.     RemoveButton: TButton;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure RemoveButtonClick(Sender: TObject);
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. var
  33.   Tab: TTabSheet;
  34.   rSynEdit: TSynEdit;
  35.   i: Integer;
  36. begin
  37.   for i:=0 to 3 do begin
  38.     Tab := TTabSheet.Create(self);
  39.     Tab.PageControl := PageControl1;
  40.     Tab.Caption := Format('Tab%d',[i]);
  41.     Tab.PageControl.ActivePage := Tab;
  42.  
  43.     rSynEdit := TSynEdit.Create(Tab);
  44.     rSynEdit.Parent := Tab;
  45.     rSynEdit.Align := alClient;
  46.     rSynEdit.RightEdge := 0;
  47.     rSynEdit.BorderStyle := bsNone;
  48.   end;
  49. end;
  50.  
  51. procedure TForm1.RemoveButtonClick(Sender: TObject);
  52. var
  53.   tab: TTabSheet;
  54. begin
  55.   tab:=PageControl1.ActivePage;
  56.   if Assigned(tab) and
  57.     (PageControl1.PageCount > 1) then // you cannot remove the last tabsheet
  58.     PageControl1.RemovePage(tab.TabIndex);
  59. end;
  60.  
  61. end.

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #5 on: January 05, 2018, 12:29:54 pm »
You can't use TTabsheet.Free in this case because tabsheets are managed internally by the control.
You need access to the protected RemovePage() method.
Note that you are not allowed to remove the last tabsheet if it is the only one remaining (a widgetset limitation I think).

Try this: in a new Lazarus project drop a button and a pagecontrol on the main form.
Complete as follows:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, Forms, Controls, ComCtrls, StdCtrls, SynEdit;
  9.  
  10. type
  11.  
  12.   TPageControl = class(ComCtrls.TPageControl)  // this is a hack to give access to protected methods
  13.   end;
  14.  
  15.   TForm1 = class(TForm)
  16.     PageControl1: TPageControl;
  17.     RemoveButton: TButton;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure RemoveButtonClick(Sender: TObject);
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. var
  33.   Tab: TTabSheet;
  34.   rSynEdit: TSynEdit;
  35.   i: Integer;
  36. begin
  37.   for i:=0 to 3 do begin
  38.     Tab := TTabSheet.Create(self);
  39.     Tab.PageControl := PageControl1;
  40.     Tab.Caption := Format('Tab%d',[i]);
  41.     Tab.PageControl.ActivePage := Tab;
  42.  
  43.     rSynEdit := TSynEdit.Create(Tab);
  44.     rSynEdit.Parent := Tab;
  45.     rSynEdit.Align := alClient;
  46.     rSynEdit.RightEdge := 0;
  47.     rSynEdit.BorderStyle := bsNone;
  48.   end;
  49. end;
  50.  
  51. procedure TForm1.RemoveButtonClick(Sender: TObject);
  52. var
  53.   tab: TTabSheet;
  54. begin
  55.   tab:=PageControl1.ActivePage;
  56.   if Assigned(tab) and
  57.     (PageControl1.PageCount > 1) then // you cannot remove the last tabsheet
  58.     PageControl1.RemovePage(tab.TabIndex);
  59. end;
  60.  
  61. end.

сейчас попробую ваш код а вот VIDEO: https://youtu.be/N8PC2XOx5dc с моей ошибкой
now I will try your code and here is the VIDEO: https://youtu.be/N8PC2XOx5dc my mistake

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #6 on: January 05, 2018, 12:32:20 pm »
You can't use TTabsheet.Free in this case because tabsheets are managed internally by the control.
that is a bug not a feature and needs to be reported.
You need access to the protected RemovePage() method.
isn't this method called indirectly by setting the ttabsheet.pagecontrol := nil ?
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 #7 on: January 05, 2018, 12:34:59 pm »
You can't use TTabsheet.Free in this case because tabsheets are managed internally by the control.
that is a bug not a feature and needs to be reported.
You need access to the protected RemovePage() method.
isn't this method called indirectly by setting the ttabsheet.pagecontrol := nil ?
Пробовал nil self указывал компонент parent вообщем пока ничего не помогает
Tried nil self component parent indicated generally while helps nothing

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #8 on: January 05, 2018, 01:01:53 pm »
 Application.ReleaseComponent(PageControl 1.ActivePage);
    PageControl1.ActivePage.Free;
      PageControl1.ActivePage.Destroy;
        PageControl1.RemoveControl(PageControl1.ActivePage);
          PageControl1.RemoveComponent(PageControl1.ActivePage);
                                                                 
                        не помогает((( >:(
« Last Edit: January 05, 2018, 01:12:58 pm by BIT »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #9 on: January 05, 2018, 01:28:36 pm »
tested on lazarus 1.6.4 I see no problem to free any tabsheet at any position from both pagecontrol and extendednotebook components. I do not have lazarus 1.8 installed so I can't test it for now. Find attached my test application. As far as I can tell it should work.

Edit:
Sorry I attached the wrong sample application re download the new one.
« Last Edit: January 05, 2018, 01:39:50 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 #10 on: January 05, 2018, 01:32:12 pm »
You can't use TTabsheet.Free in this case because tabsheets are managed internally by the control.
You need access to the protected RemovePage() method.
Note that you are not allowed to remove the last tabsheet if it is the only one remaining (a widgetset limitation I think).

Try this: in a new Lazarus project drop a button and a pagecontrol on the main form.
Complete as follows:

slightly modified code but the meaning is the same and the error below

Code: Pascal  [Select][+][-]
  1.  
  2. unit Unit1;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
  10.   StdCtrls, ComCtrls, Menus;
  11.  
  12. type
  13.  
  14.   TPageControl = class(ComCtrls.TPageControl)
  15.     // this is a hack to give access to protected methods
  16.   end;
  17.  
  18. type
  19.  
  20.   { TForm1 }
  21.  
  22.   TForm1 = class(TForm)
  23.     Button1: TButton;
  24.     MenuItem1: TMenuItem;
  25.     PageControl1: TPageControl;
  26.     PopupMenu1: TPopupMenu;
  27.     procedure Button1Click(Sender: TObject);
  28.     procedure FormCreate(Sender: TObject);
  29.     procedure MenuItem1Click(Sender: TObject);
  30.   private
  31.  
  32.   public
  33.  
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43. { TForm1 }
  44.  
  45. procedure TForm1.FormCreate(Sender: TObject);
  46. var
  47.   Tab: TTabSheet;
  48.   rSynEdit: TSynEdit;
  49.   i: integer;
  50. begin
  51.   for i := 0 to 7 do
  52.   begin
  53.     Tab := TTabSheet.Create(self);
  54.     Tab.PageControl := PageControl1;
  55.     Tab.Caption := Format('Tab%d', [i]);
  56.     Tab.PageControl.ActivePage := Tab;
  57.  
  58.     rSynEdit := TSynEdit.Create(Tab);
  59.     rSynEdit.Parent := Tab;
  60.     rSynEdit.Name := 'syed' + IntToStr(PageControl1.PageCount);
  61.     rSynEdit.PopupMenu := PopupMenu1;
  62.     rSynEdit.Align := alClient;
  63.     rSynEdit.RightEdge := 0;
  64.     rSynEdit.BorderStyle := bsNone;
  65.   end;
  66.  
  67. end;
  68.  
  69. procedure TForm1.MenuItem1Click(Sender: TObject);
  70. begin
  71.   (PageControl1.ActivePage.FindComponent('syed' + IntToStr(
  72.     PageControl1.ActivePageIndex + 1)) as TSynEdit).CopyToClipboard;
  73.  
  74. end;
  75.  
  76. procedure TForm1.Button1Click(Sender: TObject);
  77. var
  78.   tab: TTabSheet;
  79. begin
  80.   tab := PageControl1.ActivePage;
  81.   if Assigned(tab) and (PageControl1.PageCount > 1) then
  82.     // you cannot remove the last tabsheet
  83.     PageControl1.RemovePage(tab.TabIndex);
  84. end;
  85.  
  86. end.

Also not helped

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #11 on: January 05, 2018, 01:43:21 pm »
tested on lazarus 1.6.4 I see no problem to free any tabsheet at any position from both pagecontrol and extendednotebook components. I do not have lazarus 1.8 installed so I can't test it for now. Find attached my test application. As far as I can tell it should work.

Edit:
Sorry I attached the wrong sample application re download the new one.

Удалить нет проблемы но и больше доступа ниже по Index нету к вложенным в вкладку компонентам это во всех версиях Lazarusa так было просто я сейчас только поднял вопрос

Remove no problem but more access lower Index not attached to the tab component is in all versions of Lazarusa was so simple I just raised the issue

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #12 on: January 05, 2018, 02:14:48 pm »
Actually I think your problem is not related to TPageControl or TTabsheet, but how you use synedit clipboard functionality.
The error message you get appears to show that a synedit you expect to be instantiated is not.

As with nearly all bugs, getting others to help you locate them without providing a compilable example that shows the bug, is almost certain to result in a wild goose chase.

BIT

  • Full Member
  • ***
  • Posts: 158
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #13 on: January 05, 2018, 02:36:44 pm »
Прикрепил пример и видео как вызвать ошибку https://youtu.be/VtExS2W8oWs

Attached example and video how to cause an error https://youtu.be/VtExS2W8oWs

Example https://drive.google.com/open?id=1pltuCnMphmWqybPGv7XtXSwCePR7vxef

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: PageControl + SynEdit - PageControl.ActivePage.Free
« Reply #14 on: January 05, 2018, 03:26:12 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.

 

TinyPortal © 2005-2018