[SOLVED] TECTabCtrl TabIndex bug? -> No, my fault! lazarus / 31-LCL ---------------------------------------------------------------------- Raul_ES · 2020-06-07 17:27 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 ---------------------------------------------------------------------- Raul_ES · 2020-06-07 17:31 I tried overriding the constructor method, but it complains that the controls have no parent: 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 constructor TFrame_shoppinglistHDSqt.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);     ECTabCtrl_Right.TabIndex:=0;     ECTabCtrl_Left.TabIndex:=0;end; ---------------------------------------------------------------------- Raul_ES · 2020-06-07 17:36 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TmainScreen.createNewFrameSHOPPINGLIST(tabsheetSHOPPINGLISTtheme: Integer); varpageCounter,p: integer;canAddPage: boolean;newpageSHOPPINGLIST: TPage;newframeSHOPPINGLIST: TFrame;YY,MN,DD, HH,MM,SS,ms : Word;S: String;I,n,m: Integer; beginpageCounter := Notebook.PageCount + 1;         I := Notebook.Pages.Add(IntToStr(pageCounter));        newpageSHOPPINGLIST := Notebook.Page[I];         with newpageSHOPPINGLIST do          begin             DeCodeDate (Date,YY,MN,DD);            DeCodeTime(Time,HH,MM,SS,ms);             Name := 'pageshoppinglist' + format ('%d%d%d',[dd,mn,yy]) +                                format ('%d%d%d%d',[hh,mm,ss,ms]);             Caption := 'Cartera ' + '[]'; //+ IntToStr(pageCounter);            //Verificar si ya existe una página con el mismo pageCounter.         //if (tabsheetPOStheme = POS_FARMATIC) then        //    newframePOS := TFrame_POS_farmaticWin.Create(newtabsheet);       // if (tabsheetPOStheme = POS_NIXFARMA) then       //     newframePOS := TFrame_POS_nixfarmaWin.Create(newtabsheet);             if (tabsheetSHOPPINGLISTtheme = HDS) then            newframeSHOPPINGLIST := TFrame_shoppinglistHDSqt.Create(newpageSHOPPINGLIST);             with newframeSHOPPINGLIST do               begin                 Name := 'frame' + format ('%d%d%d',[dd,mm,yy]) +                                 format ('%d%d%d%d',[hh,mm,ss,ms]);                 Parent := newpageSHOPPINGLIST;                 Align := alClient;               end;          end;        // activar la nueva página        Notebook.PageIndex:= I;        Notebook.Page[I].Visible :=True;       ECTabCtrl_sheetTab.AddTab(etaLast,True);        ECTabCtrl_sheetTab.Ta bs.Items[ECTabCtrl_sheetTab.TabIndex].Text:=newpageSHOPPINGLIST.Captio n ;         ECTabCtrl_sheetTab.Tabs.Items[ECTabCtrl_sheetTab.TabIndex] .FontOptions.FontStyles:=[fsBold];        ECTabCtrl_sheetTab.Tabs.Item s[ECTabCtrl_sheetTab.TabIndex].FontOptions.FontColor:= clGreen;       if Notebook.PageIndex <> 0 then begin         ComboBox_sheets.Items.Add('['+'] '+newpageSHOPPINGLIST.Caption);      end        else if Notebook.PageIndex = 0 then             ComboBox_sheets.Items.Add('['+'] '+newpageSHOPPINGLIST.Caption);       ComboBox_sheets.ItemIndex:=Notebook.PageIndex;         Label_sheets.Caption := 'Pantallas ('+IntToStr(Notebook.PageCount)+'):'; end; ---------------------------------------------------------------------- Blaazen · 2020-06-07 17:56 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. ---------------------------------------------------------------------- jamie · 2020-06-07 18:32 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. ---------------------------------------------------------------------- Raul_ES · 2020-06-07 18:56 Quote from: jamie on June 07, 2020, 08:32:14 pmInherited Create..... Parent := TheOwner; I get the following compiler error: Quoteframe_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); ---------------------------------------------------------------------- Raul_ES · 2020-06-07 19:01 Quote from: Blaazen on June 07, 2020, 07:56:50 pmAccess 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? ---------------------------------------------------------------------- PascalDragon · 2020-06-07 19:12 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 · 2020-06-07 19:13 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.. ---------------------------------------------------------------------- Raul_ES · 2020-06-07 20:04 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  Frame := TFrame1.Create(GroupBox1);  Frame.Parent := GroupBox1;end; The parent has been already defined in the procedure TmainScreen.createNewFrameSHOPPINGLIST(tabsheetSHOPPINGLISTtheme: Integer) ---------------------------------------------------------------------- Raul_ES · 2020-06-07 20:05 Quote from: PascalDragon on June 07, 2020, 09:12:49 pmWhen 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. ?? ---------------------------------------------------------------------- jamie · 2020-06-07 20:23 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. ---------------------------------------------------------------------- Raul_ES · 2020-06-07 20:51 Quote from: jamie on June 07, 2020, 10:23:01 pmEach 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  newframeSHOPPINGLIST := TFrame_shoppinglistHDSqt.Create(newpageSHOPPINGLIST);             with newframeSHOPPINGLIST do               begin                 Name := 'frame' + format ('%d%d%d',[dd,mm,yy]) +                                 format ('%d%d%d%d',[hh,mm,ss,ms]);                 Parent := newpageSHOPPINGLIST;                 Align := alClient; Maybe it would be a good idea to hash the name with some hashing algorithm. ---------------------------------------------------------------------- jamie · 2020-06-07 21:05 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. ---------------------------------------------------------------------- lucamar · 2020-06-08 06:51 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). ---------------------------------------------------------------------- howardpc · 2020-06-08 09:12 If you write as many bugs as I do, setting Name is also a great help when debugging, much later, code that "ought to work". ---------------------------------------------------------------------- Raul_ES · 2020-06-08 19:46 Quote from: jamie on June 07, 2020, 11:05:46 pmAre 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. This method is used whenever is needed to add a page with the shopping list frame. It is the only metrhod in the whole program to achieve this. The rest of page types have their own methods (I need to polish this because I am repeating code). The default behaivour of the program is to start with an empty notebook. The user will then choose what kind of session to open:  a point of sale, customer card, diary, accounting book, shopping list.... Depending on the configuration the program will instead open a certain type of page or none. Other option could be to use a random number generator to create the name. ---------------------------------------------------------------------- Raul_ES · 2020-06-08 19:51 Actually I apply it for both page names and frame names to avoid any possibility of duplicity: 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 I := Notebook.Pages.Add(IntToStr(pageCounter));        newpageSHOPPINGLIST := Notebook.Page[I];         with newpageSHOPPINGLIST do          begin             DeCodeDate (Date,YY,MN,DD);            DeCodeTime(Time,HH,MM,SS,ms);             Name := 'pageshoppinglist' + format ('%d%d%d',[dd,mn,yy]) +                                format ('%d%d%d%d',[hh,mm,ss,ms]);             Caption := 'Cartera ' + '[]';             if (tabsheetSHOPPINGLISTtheme = HDS) then          newframeSHOPPINGLIST := TFrame_shoppinglistHDSqt.Create(newpageSHOPPINGLIST);             with newframeSHOPPINGLIST do               begin                 Name := 'frame' + format ('%d%d%d',[dd,mm,yy]) +                                 format ('%d%d%d%d',[hh,mm,ss,ms]);                 Parent := newpageSHOPPINGLIST;                 Align := alClient;                end;          end;         Notebook.PageIndex:= I;        Notebook.Page[I].Visible :=True; ---------------------------------------------------------------------- Raul_ES · 2020-06-08 19:52 Thank you all for your help :-) regards