1

How can I run some code to change something on a Form in design time?

I have tried this but this works only in Run Time:

constructor TForm1.Create(AOwner: TComponent);
begin
  inherited;
  Form1.Font.Color := clRed;
end;

I know there are "magic" procedures like "Register" and there is "initialization" but I don't think these can help here.

Please note that my point is not just changing the font color to red but rather doing complex change of the form appearance and I want to see in Design Time.

Tom
  • 2,962
  • 3
  • 39
  • 69
  • 1
    Not possible. The Delphi code is *compiled* not some interpreted scripting language. You can go the other way, though. Do your modifications in the designer and create the runtime code afterwards. I think this is a default feature in the Delphi IDE (if not, use GExperts.org). – Jørn E. Angeltveit Nov 03 '12 at 13:50
  • I can't do the changes in the designer 'cause they are too complex. I just need a fast preview of the changes and compiling the program each time and checking if this is fine takes a hell lot of time. Perhaps I can do something like this: separate one procedure from the project, put it in another package, create a BAT file to recompile just this file. But then- how to tell Delphi designer to reload the package? Or maybe I should make a new package which parses the layout/design saved in a file. This should work, shouldn't it? It just needs a pretty advanced parser to support the complex syntax – Tom Nov 03 '12 at 15:28
  • Could you tell us more. What's the ultimate goal. – David Heffernan Nov 03 '12 at 15:52
  • The goal is to create a skinning function. So I can set one skin at design time, see how everything looks, position the elements and stuff. And then at runtime I can just switch skins- and all the colors and images will be replaced. – Tom Nov 03 '12 at 16:20
  • 3
    It already exists. VCL styles. Introduced in XE2. – David Heffernan Nov 03 '12 at 21:25
  • 1
    If **Skinning by code** is your ultimate goal, then you can't use the Delphi-code to handle the skinning. The Delphi code is compiled in to native code, and it's not possible to inject such compiled code to your executables later on. The "skinning code" you're trying to run should be pure scrips that your application can parse and apply runtime. Take a look at http://code.google.com/p/dwscript/, for instance. – Jørn E. Angeltveit Nov 04 '12 at 08:15
  • 1
    @DavidHeffernan I use Delphi 2005 and Lazarus. I don't think Lazarus will have VCL styles soon and I don't want to buy another crappy Delphi after spending so much money on something as crappy as my Delphi 2005. Borland/Embarcadero never even bother to fix the bugs in their products and they just keep releasing new versions instead. – Tom Nov 06 '12 at 20:45
  • @JørnE.Angeltveit I just need a very simple skinning function, like changing font colors, background and text colors, a few images. So I definitely can skin by code. – Tom Nov 06 '12 at 20:56
  • http://stackoverflow.com/questions/691997/component-initialization-runtime-vs-designtime – Shannon Matthews Jun 24 '13 at 10:13

1 Answers1

1

If you're going to do a lot of this, or complex manipulations, you'll probably be better off doing this design work at runtime. Creating property editors is not a lot of work, and manipulating the widget tree at run time neither.

Stephan Eggermont
  • 15,847
  • 1
  • 38
  • 65