views:

174

answers:

2

Someway to override Delphi default procedures at Design Time ?

I need to override the InstanceSize at design time, I did it runtime using FastCode method:

FastcodeAddressPatch(FastcodeGetAddress(@SInstanceSize), @TWinControl.RfInstanceSize);

But, is there some way to do it at Design time ?

Tks in advice

+4  A: 

"Design time" is really just "run time," but in the context of the IDE instead of the context of your program. Put your code in a design-time package and load it in the IDE. The IDE will call all the Register procedures in your package's units, at which time you can run whatever code you need.

  1. Make a new package project (.dpk file).
  2. Set project preferences so it's a design-time package.
  3. Add a new, blank unit to it.
  4. Add a procedure to the interface section named Register. It must have a capital R and the rest lowercase.
  5. Implement that procedure however you want (such as by putting your call to FastcodeAddressPatch there).
  6. Compile and install the package.

I'm a little wary about what it looks like you're trying to do in step 5, but I'll let you work that out for yourself.

Rob Kennedy
I want to override the DefineProperties of TWinControl.How can I do this the way you say ?
SaCi
"The way I say" has nothing to do with overriding or patching anything. It only had to do with *where* you can put your code to ensure it runs *when* you want to. *What* you do with that is up to you. (If you want to know how to patch VCL functions, ask that in a new question. From what you've posted, I figured you already knew how to do that part.)
Rob Kennedy
+1 for a clear explanation.
Jeroen Pluimers
The problem to put the code, is not only to add the code.The problem is 'cause the code isn't called. Why ? 'Cause there's no way to override TwinControl procedure without inheriting a class from it.A recurse that I use to do it is using FastcodeAddressPatch to override the the method. But it only work runtime.
SaCi
A ok, If I add FastcodeAddressPatch on Register procedure, it don't work. Why ? I don't know.While using it at runtime it must be the first unit in the project, maybe this give us a hint about why it doesn't run there.
SaCi
+1  A: 

If by "at design-time" you mean "change the way your components behave while in the Form Designer", that's something you really shouldn't be trying to do. The Form Designer is part of the IDE, which is all Delphi code being run in BDS.exe. If you alter TObject under the Form Designer, you alter it for the entire IDE, with potentially disastrous results.

Mason Wheeler
I know the risks but it's to my studies.Do you know any way to do this ?
SaCi