0

I'm using C++ Builder 10.3 and my application is for Android, please note I'm very new to C++ Builder

I'm trying to change the font size and height of a TSpinBox but i'm unable to change the height.

I tried by best to port the following Delphi solution
Firemonkey TEdit height but with no joy and i'm a total lose. AdjustFixedSize is declared private i dont think its being overridden, i have also tried creating a setter and calling it but yet again I was unable to get it to work. The biggest problem i have is my lack of C++ Builder knowledge.

Header

class TMySpinBox : public TSpinBox{

public:
protected:
virtual void AdjustFixedSize(const TControl Ref) ;

};

CPP

TMySpinBox::TMySpinBox() : TSpinBox(0){};
void TMySpinBox::AdjustFixedSize(const TControl Ref){
  SetAdjustType(TAdjustType::None);

Code

TMySpinBox* SpinBox1 = new TMySpinBox();

SpinBox1->ControlType=TControlType::Platform;
SpinBox1->Parent=Panel1->Parent;
SpinBox1->Position->Y=16.0;
SpinBox1->Position->X=16.0;
SpinBox1->Min=2;
SpinBox1->Max=99;
SpinBox1->Font->Size=48;
SpinBox1->Visible=true;
SpinBox1->Value=2;

SpinBox1->Align=TAlignLayout::None;
SpinBox1->Height=100;
Width=100;
  • There is no need to subclass the `TSpinEdit`. You can change its `Height` property directly in the designer or in code. To change the font size, you need to remove `Size` from `TSpinEdit->StyledSettings`. Same for `Family`, `Style` and `FontColor` if you want to change those. See [this answer](https://stackoverflow.com/a/30812567/2292722) to a similar question for the correct syntax if you want to do these changes in code. – Tom Brunberg May 01 '20 at 08:54
  • @TomBrunberg If the platform is set to Windows i can alter the height in the designer and in code with no issue, but setting the platform to Android when in designer after changing the height value it just reverts to its default value, and SpinBox1->Height=100 also has no effect. – Anthony Higgins May 01 '20 at 09:31
  • @TedLyngmo my C++ skills are very limited, what im trying to do is override the control’s AdjustFixedSize method, i'm just not sure how to go about it. – Anthony Higgins May 01 '20 at 09:32
  • Yes indeed, for Android it seems really hard to do. I will come back to the issue later today if I find any solution. – Tom Brunberg May 01 '20 at 10:31
  • @TomBrunberg I might be going about this the wrong way and im now at a total loss, so any ideas will be more than welcome. – Anthony Higgins May 01 '20 at 18:49

1 Answers1

0

I gave it a try and moved a few things around - mostly into the constructor of the customized TSpinBox. I skipped using AdjustFixedSize since it doesn't seem necessary.

myspinbox.h

#ifndef myspinboxH
#define myspinboxH
//---------------------------------------------------------------------------
#include <FMX.SpinBox.hpp>

class TMySpinBox : public TSpinBox {
protected:
    // The correct signature but commented out since I didn't use it:
    //void __fastcall AdjustFixedSize(TControl* const ReferenceControl) override;
public:
    // C++ Builder constructors can be virtual and override which is not
    // standard C++. This is afaik only important if you make a custom component
    // to integrate with the IDE to support streaming it, but I'll make it
    // virtual anyway.

    // This component sets Owner and Parent to the same component. You can change that if
    // you'd like to keep them separate.
    virtual __fastcall TMySpinBox(Fmx::Types::TFmxObject* OwnerAndParent);
};

#endif

myspinbox.cpp

#pragma hdrstop

#include "myspinbox.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

__fastcall TMySpinBox::TMySpinBox(Fmx::Types::TFmxObject* OwnerAndParent) :
    TSpinBox(OwnerAndParent) // set owner
{
    // set properties
    this->Parent = OwnerAndParent;

    this->Position->Y = 16.0;
    this->Position->X = 16.0;
    this->Min = 2;
    this->Max = 99;
    this->Value = this->Min;

    this->Height = 100;
    this->Width = 100;

    // Remove the styled setting for Size to enable setting our own font size
    this->StyledSettings >>= Fmx::Types::TStyledSetting::Size;

    this->Font->Size = 48;
}

Code

// Let Panel1 own and contain the spinbox and destroy it when it itself is destroyed

TMySpinBox* SpinBox1 = new TMySpinBox(Panel1);

Disclaimer: Only tested on Windows

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • thank you so much for the code and comments, learnt a lot. Unfortunately i still cant get to to work on Android. If you use a style book you can get it to work by setting SetAdjustType and Align to None, least now using your approach i can get to the Private functions and i do feel closer to a solution. many thanks. – Anthony Higgins May 11 '20 at 14:02