Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Add DXE2 styles during runtime

dxe2 styles runtime

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1 mikalthor

mikalthor

    CC Lurker

  • New Member
  • Pip
  • 9 posts

Posted 01 January 2013 - 10:56 AM

I use DXE2 on Windows7 and I'm trying to change VCL styles during runtime. I'm building an MDI program and all that is changed is the main form(s). The components within the forms don't change style... in fact, they don't show up at all.

//use StyleManager to set style during runtime
TStyleManager.TrySetStyle('Smokey Quartz Kamri');

Any help is very much appreciated... thanks

Edited by mikalthor, 01 January 2013 - 10:59 AM.


#2 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 02 January 2013 - 07:53 PM

Hi mikalthor, welcome to CodeCall!

According to my experience DXE styling is pretty good. Never had problem with controls that came with Delphi itself. However I had not tried it with MDI application. I rarely do MDI applications nowadays.

But after reading your post I composed a sample MDI application, and the styling still works okay. I mean whenever I change the style in the main form, all components in both main form and mdi child form were styled properly. Of course the test application does not use all kind of controls, only most popular ones, like TEdit, TButton, TComboBox.

And I was using the same code like you did.

Maybe you could tell us more about the problem and what kind of controls you have in the mdi child forms.

Edited by LuthfiHakim, 03 January 2013 - 07:06 AM.


#3 mikalthor

mikalthor

    CC Lurker

  • New Member
  • Pip
  • 9 posts

Posted 03 January 2013 - 04:18 AM

Clip4.png

Hi LuthfiHakim,

You know, after a little more testing, I find that I'm able to place some standard controls on the fsMDIForm, but not on an fsMDIChild form. The controls on the fsMDIForm are standard Delphi XE2 controls like TButton, TMemo, TCheckBox (as you said in your post). I can even place controls in container controls like a TPanel and the style is successfully changed at runtime. However, not a single control (like a button or checkbox) will change style at runtime on an fsMDIChild form.

I wonder if we can override this by using some sort of Windows API call? Thanks for your help; I've included a screenshot this time (above), one before changing style before runtime and one after.

Edited by mikalthor, 03 January 2013 - 04:20 AM.


#4 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 03 January 2013 - 07:15 AM

That's odd. In my test project everything works fine. After seeing your screenshot I add several other controls to the mdi child form (TPanel, TBitBtn, and TSpeedBtn). And they also work okay.

Here I attach the test project. Try to compile it and check if you still have problem with changing the style.

Attached Files



#5 mikalthor

mikalthor

    CC Lurker

  • New Member
  • Pip
  • 9 posts

Posted 05 January 2013 - 12:36 PM

LuthfiHakim,
Thanks very much for taking time to put together the Demo project, I've never had anyone do that for me before. Of course it compiled and worked beautifully; I've got to say that your coding style is elegant.

I put together my own Demo project using roughly the same format (I thought), but mine doesn't work..... or I should say that it works the same as my original project. If you can find time, please compile and take a look.. There's some fluff that was added as part of beginning with the generic Embarcadero MDI Application. Again, thanks for your time....

Attached File  MDIAPP.zip   194.31KB   208 downloads

Edited by mikalthor, 05 January 2013 - 12:39 PM.


#6 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 06 January 2013 - 07:15 AM

Hi Mikalthor,

I had tried your test project, and I found completely different problem. With me the problem is that MDI children forms will be hidden when style change occured. However they still be visible for a very short time before becoming invisible. From this "flash" I believe the style change still applied correctly for controls inside those MDI children forms.

After some testing by creating new MDI application using Delphi wizard (which I believe the one you were using as the start of your project) and I found that the problem is caused by the wizard. Because all MDI applications created by the wizard will experience the same problem, while MDI application created "manually" will not get this problem (as in my test project).

I have tried to pinpoint the cause of this bug, but so far I failed. Although I believe the problem lies with inconsistent handling of CM_CUSTOMSTYLECHANGED message.

The quick workaround I could suggest you is to build your MDI project manually, like I had done with my test project. Do not use the standard actions like ones used by the MDI wizard. It's actually not very hard to code the cascade, tile, etc functions.

However I recommend to avoid building your project as MDI application. Docking is more "modern".

#7 mikalthor

mikalthor

    CC Lurker

  • New Member
  • Pip
  • 9 posts

Posted 06 January 2013 - 09:35 AM

LuthfiHakim,

Can you please suggest where I can read some more about docking... I would like to get really familiar with docking before changing anything. I am sure that this is a better method. Perhaps some online articles or a book, I can't seem to find much in Help; mainly the docking relates to controls, not forms. Do you think that there will be much re-coding involved?

I will practice with my MDI App manually as you say so that I can get more familiar with this, would ultimately like to use docking.
Thanks again for taking time to help me.

#8 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 06 January 2013 - 09:52 PM

Docking is actually easy. Basically you "parent" a window control (e.g. a form) to another window control that acts as dock host. That's the most basic of docking. You can use code like this.

  FormClient.Parent := FormHost;

Initially you may want to remove the border of FormClient, making only its client content shown in FormHost. Something like BorderStyle := bsNone;.

But latest versions of Delphi have "officially" support docking by providing libraries to support advance docking features, such as dragging a docked form into another host form, automatically create tab for docked form, e.t.c.

Can you please suggest where I can read some more about docking... I would like to get really familiar with docking before changing anything. I am sure that this is a better method. Perhaps some online articles or a book, I can't seem to find much in Help; mainly the docking relates to controls, not forms. Do you think that there will be much re-coding involved?


Well, the docking sample project shows how to dock forms. Also you might interested with these:


I think I will write tutorial(s) about docking. :)

Edited by LuthfiHakim, 06 January 2013 - 09:53 PM.





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download