Recent

Author Topic: [SOLVED] TECTabCtrl TabIndex bug? -> No, my fault!  (Read 2452 times)

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
[SOLVED] TECTabCtrl TabIndex bug? -> No, my fault!
« on: June 07, 2020, 07:27:54 pm »
Hello friends,

here again struggling with this pretty control, not sure if it is a bug or -more probable- my fault. I am using two ectabctrls in a frame (see picture, bottom left and right). Notebook pages containing this frames  are added or removed on demand.

Whenever I try to add a second frame appears an access violation in relation to this ectabctrls and their TabIndex.

I'll post some source code. No clue of what's wrong
« Last Edit: June 08, 2020, 09:53:04 pm by Raul_ES »
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TECTabCtrl TabIndex bug?
« Reply #1 on: June 07, 2020, 07:31:23 pm »
I tried overriding the constructor method, but it complains that the controls have no parent:
Code: Pascal  [Select][+][-]
  1. constructor TFrame_shoppinglistHDSqt.Create(TheOwner: TComponent);
  2. begin
  3.   inherited Create(TheOwner);
  4.      ECTabCtrl_Right.TabIndex:=0;
  5.      ECTabCtrl_Left.TabIndex:=0;
  6. end;
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TECTabCtrl TabIndex bug?
« Reply #2 on: June 07, 2020, 07:36:30 pm »
This is the procedure responsible to create the new page with the frame. It works perfectly when no ECTabCtrl is used. The fact is that POS pages and other kind works fine.

Code: Pascal  [Select][+][-]
  1. procedure TmainScreen.createNewFrameSHOPPINGLIST(tabsheetSHOPPINGLISTtheme: Integer);
  2.  
  3. var
  4. pageCounter,p: integer;
  5. canAddPage: boolean;
  6. newpageSHOPPINGLIST: TPage;
  7. newframeSHOPPINGLIST: TFrame;
  8. YY,MN,DD, HH,MM,SS,ms : Word;
  9. S: String;
  10. I,n,m: Integer;
  11.  
  12. begin
  13. pageCounter := Notebook.PageCount + 1;
  14.  
  15.         I := Notebook.Pages.Add(IntToStr(pageCounter));
  16.         newpageSHOPPINGLIST := Notebook.Page[I];
  17.  
  18.         with newpageSHOPPINGLIST do
  19.           begin
  20.  
  21.             DeCodeDate (Date,YY,MN,DD);
  22.             DeCodeTime(Time,HH,MM,SS,ms);
  23.  
  24.             Name := 'pageshoppinglist' + format ('%d%d%d',[dd,mn,yy]) +
  25.                                 format ('%d%d%d%d',[hh,mm,ss,ms]);
  26.  
  27.             Caption := 'Cartera ' + '[]'; //+ IntToStr(pageCounter);
  28.             //Verificar si ya existe una página con el mismo pageCounter.
  29.  
  30.         //if (tabsheetPOStheme = POS_FARMATIC) then
  31.         //    newframePOS := TFrame_POS_farmaticWin.Create(newtabsheet);
  32.        // if (tabsheetPOStheme = POS_NIXFARMA) then
  33.        //     newframePOS := TFrame_POS_nixfarmaWin.Create(newtabsheet);
  34.  
  35.             if (tabsheetSHOPPINGLISTtheme = HDS) then
  36.             newframeSHOPPINGLIST := TFrame_shoppinglistHDSqt.Create(newpageSHOPPINGLIST);
  37.              with newframeSHOPPINGLIST do
  38.                begin
  39.                  Name := 'frame' + format ('%d%d%d',[dd,mm,yy]) +
  40.                                    format ('%d%d%d%d',[hh,mm,ss,ms]);
  41.                  Parent := newpageSHOPPINGLIST;
  42.                  Align := alClient;
  43.                end;
  44.           end;
  45.         // activar la nueva página
  46.         Notebook.PageIndex:= I;
  47.         Notebook.Page[I].Visible :=True;
  48.  
  49.         ECTabCtrl_sheetTab.AddTab(etaLast,True);
  50.         ECTabCtrl_sheetTab.Tabs.Items[ECTabCtrl_sheetTab.TabIndex].Text:=newpageSHOPPINGLIST.Caption ;
  51.  
  52.         ECTabCtrl_sheetTab.Tabs.Items[ECTabCtrl_sheetTab.TabIndex].FontOptions.FontStyles:=[fsBold];
  53.         ECTabCtrl_sheetTab.Tabs.Items[ECTabCtrl_sheetTab.TabIndex].FontOptions.FontColor:= clGreen;
  54.  
  55.         if Notebook.PageIndex <> 0 then begin
  56.  
  57.         ComboBox_sheets.Items.Add('['+'] '+newpageSHOPPINGLIST.Caption);
  58.         end
  59.         else if Notebook.PageIndex = 0 then
  60.              ComboBox_sheets.Items.Add('['+'] '+newpageSHOPPINGLIST.Caption);
  61.  
  62.         ComboBox_sheets.ItemIndex:=Notebook.PageIndex;
  63.  
  64.         Label_sheets.Caption := 'Pantallas ('+IntToStr(Notebook.PageCount)+'):';
  65.  
  66. end;
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: TECTabCtrl TabIndex bug?
« Reply #3 on: June 07, 2020, 07:56:50 pm »
Access violation looks like component is not created at all. But I do not use frames much.
Do you have Call Stack window active? It may give useful info.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 7587
Re: TECTabCtrl TabIndex bug?
« Reply #4 on: June 07, 2020, 08:32:14 pm »
Try setting the parent before setting any other parameters related to viewing...


the part where you override the constructor...

Inherited Create.....
Parent := TheOwner;

Try that.
The only true wisdom is knowing you know nothing

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TECTabCtrl TabIndex bug?
« Reply #5 on: June 07, 2020, 08:56:26 pm »
Inherited Create.....
Parent := TheOwner;

I get the following compiler error:

Quote
frame_shoppinglist_hdsqt.pas(173,67) Error: Incompatible type for arg no. 1: Got "TComponent", expected "TWinControl"
control.inc(4341,20) Hint: Found declaration: SetParent(TWinControl);
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TECTabCtrl TabIndex bug?
« Reply #6 on: June 07, 2020, 09:01:18 pm »
Access violation looks like component is not created at all. But I do not use frames much.
Do you have Call Stack window active? It may give useful info.

I don't know how to use the call stack. I'll check it right now. Any tutorial or quick guide or recommended readings?

By the way, the controls are located in the frame. Any new instance of the frame must create all the components within, ain't right?
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

PascalDragon

  • Hero Member
  • *****
  • Posts: 6349
  • Compiler Developer
Re: TECTabCtrl TabIndex bug?
« Reply #7 on: June 07, 2020, 09:12:49 pm »
When the exception happens use View -> Debugger Windows -> Call stack or Ctrl + Alt + S to show the call stack window. It will display from where the function was called.

jamie

  • Hero Member
  • *****
  • Posts: 7587
Re: TECTabCtrl TabIndex bug?
« Reply #8 on: June 07, 2020, 09:13:52 pm »

https://wiki.freepascal.org/Frames


Scroll down, it shows you how to set the parent..

It could be that you may need to set the parent outside the constructor..
The only true wisdom is knowing you know nothing

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TECTabCtrl TabIndex bug?
« Reply #9 on: June 07, 2020, 10:04:45 pm »
If I have read correctly, I think that the parent has to be set from within the form that contains the frame, not from the frame itself. It has sense because a frame can be inserted into different parents, a form, a groupbox...

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Frame := TFrame1.Create(GroupBox1);
  4.   Frame.Parent := GroupBox1;
  5. end;

The parent has been already defined in the procedure TmainScreen.createNewFrameSHOPPINGLIST(tabsheetSHOPPINGLISTtheme: Integer)
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TECTabCtrl TabIndex bug?
« Reply #10 on: June 07, 2020, 10:05:59 pm »
When the exception happens use View -> Debugger Windows -> Call stack or Ctrl + Alt + S to show the call stack window. It will display from where the function was called.

Thanks,

I am doing something wrong. I run the program,and when the access violation message appears I execute the call stack but I get an empty window. ??
« Last Edit: June 07, 2020, 10:22:40 pm by Raul_ES »
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

jamie

  • Hero Member
  • *****
  • Posts: 7587
Re: TECTabCtrl TabIndex bug?
« Reply #11 on: June 07, 2020, 10:23:01 pm »
Each time you create a frame you always need to specify the parent because for each one that you have created its a different object in memory and it needs to know the display canvas. The Parent determines that.

 I have been looking at another possible issue and that is the naming of the frames. Its possible there is a duplication taking place because you are recreating the same frame more than once at runtime without changing the name of the frame and it may be that the same owner control is being used each time. This would create a problem where as it would already see a control in the list of the same name..
   
  Thinking of how that can resorted at the moment. I suppose if you could set the NAME := '' it may allow multiples of the same control in there.
The only true wisdom is knowing you know nothing

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: TECTabCtrl TabIndex bug?
« Reply #12 on: June 07, 2020, 10:51:15 pm »
Each time you create a frame you always need to specify the parent because for each one that you have created its a different object in memory and it needs to know the display canvas. The Parent determines that.

 I have been looking at another possible issue and that is the naming of the frames. Its possible there is a duplication taking place because you are recreating the same frame more than once at runtime without changing the name of the frame and it may be that the same owner control is being used each time. This would create a problem where as it would already see a control in the list of the same name..
   
  Thinking of how that can resorted at the moment. I suppose if you could set the NAME := '' it may allow multiples of the same control in there.

To avoid frame and page name duplication (a problem I detected few weeks ago) I use a combination of name+timestamp, so that the names are unique. The previous version used  an incremental naming frame1, frame2, page1, page2... but gave some problems when deleting pages and inserting new ones.

Code: Pascal  [Select][+][-]
  1.  newframeSHOPPINGLIST := TFrame_shoppinglistHDSqt.Create(newpageSHOPPINGLIST);
  2.              with newframeSHOPPINGLIST do
  3.                begin
  4.                  Name := 'frame' + format ('%d%d%d',[dd,mm,yy]) +
  5.                                    format ('%d%d%d%d',[hh,mm,ss,ms]);
  6.                  Parent := newpageSHOPPINGLIST;
  7.                  Align := alClient;

Maybe it would be a good idea to hash the name with some hashing algorithm.
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

jamie

  • Hero Member
  • *****
  • Posts: 7587
Re: TECTabCtrl TabIndex bug?
« Reply #13 on: June 07, 2020, 11:05:46 pm »
Are you using this Method of creating for a new entry for the first initial one when program starts?

in other words,  you shouldn't have any pages created when program starts and this method should be called for all including the first page otherwise you'll have the first one with still the default name and when you create the next one will also still have the default name.

The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: TECTabCtrl TabIndex bug?
« Reply #14 on: June 08, 2020, 08:51:41 am »
Note that for controls created at run-time setting the Name is completely superfluous most of the times. That property is mainly used by the IDE (for the component streaming mechanism and form<->unit synchronization, IIRC).
« Last Edit: June 08, 2020, 08:53:24 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018