Creating array of TsButton at runtime

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #32962
    JanK
    Participant

    I'm trying to create an array of TsButtons at runtime, with a TsPanel as their parent. They should have another sSkinManager then the rest of the form. I already added second sSkinManager to the form at design time. Adding a TsButton at design time works without problems.

    However, when creating the controls at runtime, the buttons don't behave correctly. They look like a TLabel, with skinned background, as if the button (or panel) didn't refresh/repaint correctly.
    The code is about as follows (excerpt):

    CODE
    buttonsArray : array of TsButton;

    // Handling of array, etc.
    // code to show buttons…..

        SetLength(buttonsArray, Table.RecordCount);
        nNumber:=0;
        while not Eof do begin
          buttonsArray[nNumber] := TsButton.Create(self);
          buttonsArray[nNumber].SkinData.FSkinManager:=sSkinManager2;
          buttonsArray[nNumber].SkinData.SkinSection:='BUTTON';
          buttonsArray[nNumber].Parent:=PanelTags;  // this is a TsPanel with SkinManager1
          buttonsArray[nNumber].Left:=nLeft;
          buttonsArray[nNumber].Top:=nTop;
          buttonsArray[nNumber].Width:=nWidth;
          buttonsArray[nNumber].Caption:=cTitle;
          buttonsArray[nNumber].OnClick:=BtnClick;
          buttonsArray[nNumber].Visible:=True;
          nLeft:=nLeft+nWidth+10;
          Next;
          Inc(nNumber);
        end

    What am I missing here? Any ideas?
    Thanks in advance,

    Regards
    Jan
    Using Delphi2009, AlphaControls 6.22 Trial

    #39257
    Support
    Keymaster

    Hello
    You must be sure that second SkinManager is created and available before creating buttons.
    If is possible to make a little example application for tests then it will be very helpful.

    #39269
    JanK
    Participant

    Thanks, I enclosed an example with all the unnecessary code stripped from my project. In the SkinManagers, you have to set the skindirectory manually, before compiling. Skinmanager 2 is set at design time.

    The generated buttons should have the skin provided by the second skinmanager, and should toggle the “Down” property when pressed.

    Two questions:
    1) How do I get the skinning right?
    2) When the buttons are pressed, a runtime error is generated at formclose?

    Thanks in advance,

    Regards
    Jan

    #39278
    Support
    Keymaster

    Thank you

    You must change this line

    CODE
    buttonsArray[nNumber].SkinData.FSkinManager:=sSkinManager2;

    to

    CODE
    buttonsArray[nNumber].SkinData.SkinManager:=sSkinManager2;


    Skinning data will be updated in this case, and problem must be solved.

    Also I can suggest you to move this line :

    CODE
    buttonsArray[nNumber].Parent:=PanelTags;

    after “Visible:=True;”. And remove “Visible:=True;” because button is visible already when created.

    #39301
    JanK
    Participant

    Thanks Serge, that helped a lot! One character, big change…
    Besides, the access violation I mentioned was raised by the “TsButton.Refresh” method. But that line was also deleted now.

    Regards
    Jan

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.