Jump to content
kokoslolos

Properties and design time code

Recommended Posts

Hi,

 

First of all, I'm not an expert in writing design time code, but this what I'm trying to achieve.

 

I have my own custom TAction descendant, lets call it TXAction, with extra published properties (like ActionCode, ActionID, ActionName, ActionDescription ...), in design time time package that is installed in the IDE.

Then I have a base form with some default TXAction components with some default properties set like ActionDescription with a place holder i.e "Export [fn] to xls" where the "[fn]" will be replaced in design time with the Form Name.

 

In the TXAction Loaded overridden method, I have this code:

 

procedure TXAction.Loaded;
var
  aIXRBaseForm : IXRBaseForm;
begin
  inherited;

  if (csDesigning in ComponentState) and (Owner<>nil) then
  begin
    if Supports(Owner, IXRBaseForm, aIXRBaseForm) then
    begin
      if ActionCode = ('.' + IntToStr(ActionID)) then
         ActionCode := aIXRBaseForm.FormCode + ActionCode;

      if (AnsiPos('[fn]', ActionDescription) > 0) and (aIXRBaseForm.FormName <> '') then
        ActionDescription := StringReplace(ActionDescription, '[fn]', aIXRBaseForm.FormName, [rfReplaceAll]);
    end;
  end;
end;

The code above works as expected, I have several descendant forms that inherit from this base form, and when I open them in the IDE,

these inherited TXActions instead of the placeholder "[fn]" in the description, they are replaced with the Form's name.

 

My problem is that the Save All button in the IDE is not activated for the form to indicated there was a change, like it does when a property is changed in the object inspector,

so that the user can save it and store these changes in the .dfm.

Although, if the Save button which is always enabled is clicked, the changes are saved!

 

This leads me to thinking if I'm indeed doing this right, is this the correct way to change properties in design time?

How can I make the Save All button enabled?

 

Thank you.

 

 

 

 

 

Share this post


Link to post

Another question,

In case cases is the TForm Designer property nil?

I'm trying to use this to notify designer that something us modified but it's always nil.

Does it have to be run from an installed design package?

 

Thanks!

Share this post


Link to post
1 minute ago, kokoslolos said:

I'm trying to use this to notify designer that something us modified but it's always nil.

How did you verify this? Of course if you just run the code in an application of yours it will be nil.

 

After you modified the code, you need to recompile the package which contains the code for the component and you need to make sure the IDE is actually using that modified version.

 

If everything else fails, you need to debug the package by running a second instance of the IDE under the debugger.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×