Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to get the inital property values in a component constructor?

softmansoftman Posts: 157Member
Hi

I'm writing a color button component. The backgound color will be adjustable, and it will display a bitmap, and this bitmap changes to an another bitmap, while the button is down.
The component works fine. When I assign a bitmap to the Image property, at design time, it appeares on the surface of the button, because the property calles the SetImage procedure. But when I run the application, the image only shown after the first button click. In this case, the button is created, but the SetImage procedure will not run. The Delphi assigns the data to my Image property like Image.Date = .......
I'v tried to get the image data in the constructor, but that time it does not exist.
I would appriciate any help.

Thanks! softman.

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hi
    :
    : I'm writing a color button component. The backgound color will be adjustable, and it will display a bitmap, and this bitmap changes to an another bitmap, while the button is down.
    : The component works fine. When I assign a bitmap to the Image property, at design time, it appeares on the surface of the button, because the property calles the SetImage procedure. But when I run the application, the image only shown after the first button click. In this case, the button is created, but the SetImage procedure will not run. The Delphi assigns the data to my Image property like Image.Date = .......
    : I'v tried to get the image data in the constructor, but that time it does not exist.
    : I would appriciate any help.
    :
    : Thanks! softman.
    :
    :
    Try calling the Repaint() method in the constructor. This should force the button to paint itself.
  • softmansoftman Posts: 157Member
    Thank you for your advice, but unfortunately it does not work. The image property Bitmap value is empty, when constructor runs, so repaint didn't do anything. I'v checked in the constructor and Image.Empty was true;



    : : Hi
    : :
    : : I'm writing a color button component. The backgound color will be adjustable, and it will display a bitmap, and this bitmap changes to an another bitmap, while the button is down.
    : : The component works fine. When I assign a bitmap to the Image property, at design time, it appeares on the surface of the button, because the property calles the SetImage procedure. But when I run the application, the image only shown after the first button click. In this case, the button is created, but the SetImage procedure will not run. The Delphi assigns the data to my Image property like Image.Date = .......
    : : I'v tried to get the image data in the constructor, but that time it does not exist.
    : : I would appriciate any help.
    : :
    : : Thanks! softman.
    : :
    : :
    : Try calling the Repaint() method in the constructor. This should force the button to paint itself.
    :

  • zibadianzibadian Posts: 6,349Member
    : Thank you for your advice, but unfortunately it does not work. The image property Bitmap value is empty, when constructor runs, so repaint didn't do anything. I'v checked in the constructor and Image.Empty was true;
    :
    :
    :
    : : : Hi
    : : :
    : : : I'm writing a color button component. The backgound color will be adjustable, and it will display a bitmap, and this bitmap changes to an another bitmap, while the button is down.
    : : : The component works fine. When I assign a bitmap to the Image property, at design time, it appeares on the surface of the button, because the property calles the SetImage procedure. But when I run the application, the image only shown after the first button click. In this case, the button is created, but the SetImage procedure will not run. The Delphi assigns the data to my Image property like Image.Date = .......
    : : : I'v tried to get the image data in the constructor, but that time it does not exist.
    : : : I would appriciate any help.
    : : :
    : : : Thanks! softman.
    : : :
    : : :
    : : Try calling the Repaint() method in the constructor. This should force the button to paint itself.
    : :
    :
    :
    Do you call the Repaint method in the SetImage()? If not you could try it, because it the SetImage() will probably be called on loading the form resources.
  • softmansoftman Posts: 157Member
    Hi!

    I'v tried to call the repaint method in my SetImage procedure, but it did not do anything. So I tried with a breakpoint, if the Setimage procedure runs. It does not run after loading resources. But somehow I figured out the solution. I had to override the 'Loaded' virtual method, which runs, after the resource is loaded. That time, all the properties are loaded (after inherited), so I assigned my Image property value to my button picture, and this way it worked out.

    Thank's for your help!


    : : Thank you for your advice, but unfortunately it does not work. The image property Bitmap value is empty, when constructor runs, so repaint didn't do anything. I'v checked in the constructor and Image.Empty was true;
    : :
    : :
    : :
    : : : : Hi
    : : : :
    : : : : I'm writing a color button component. The backgound color will be adjustable, and it will display a bitmap, and this bitmap changes to an another bitmap, while the button is down.
    : : : : The component works fine. When I assign a bitmap to the Image property, at design time, it appeares on the surface of the button, because the property calles the SetImage procedure. But when I run the application, the image only shown after the first button click. In this case, the button is created, but the SetImage procedure will not run. The Delphi assigns the data to my Image property like Image.Date = .......
    : : : : I'v tried to get the image data in the constructor, but that time it does not exist.
    : : : : I would appriciate any help.
    : : : :
    : : : : Thanks! softman.
    : : : :
    : : : :
    : : : Try calling the Repaint() method in the constructor. This should force the button to paint itself.
    : : :
    : :
    : :
    : Do you call the Repaint method in the SetImage()? If not you could try it, because it the SetImage() will probably be called on loading the form resources.
    :

Sign In or Register to comment.