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.

9
  • 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). Nov 3, 2012 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 3, 2012 at 15:28
  • 3
    It already exists. VCL styles. Introduced in XE2. Nov 3, 2012 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 code.google.com/p/dwscript, for instance. Nov 4, 2012 at 8: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 6, 2012 at 20:45

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.