DefineProperties

i build a TMainMenu descendant component:

type TActionMenu = class(TMainMenu)

for this object, i dont want the property 'Items' to be persistent; that is, it's properties and values should not be saved to the form definition (.dfm)

for this purpose i overriden the method TMainMenu.DefineProperties. it looks like this:

procedure TActionMenu.DefineProperties(Filer: TFiler);
begin
  inherited DefineProperties(Filer);
  Filer.DefineProperty('Items', nil, nil, False);
end;

this seems to work. (it also works with two dummy Read and Write function)

the problem here is that Items is a member object of the type TMenuItem, over wich streaming i have no influence.

so far the definition of a TActionMenu with a few items looks like this (in .dfm):

  object ActionMenu1: TActionMenu
    Images = imgActions
    ActionList = aclActions
    Left = 56
    Top = 28
    object TMenuItem
      Caption = 'Edit'
      object TMenuItem
        Action = acEditCut
      end
      object TMenuItem
        Action = acEditCopy
      end
      object TMenuItem
        Action = acEditPaste
      end
      object TMenuItem
        Action = acEditDelete
      end
      object TMenuItem
        Action = acEditSelectAll
      end
      object TMenuItem
        Action = acEditUndo
      end
      object TMenuItem
        Action = acEditRedo
      end
    end
  end

so the question is: is there any way i can prevent the information over the TMenuItem object to be stored?

so it will look like this (with the same items, only they are not stored):

  object ActionMenu1: TActionMenu
    Images = imgActions
    ActionList = aclActions
    Left = 56
    Top = 28
  end

topkapi
topkapiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
You can use the stored directive:

eg:
property MyProperty : Integer read FMyProperty write FMyProperty stored false;

Cheers,

Raymond.
0
topkapiAuthor Commented:
i tried it this way:

type
  TActionMenu = class(TMainMenu)

  { . . . }
 
  published
    // redifine property from parent as not stored
  property Items stored False;

  { . . . }

  end;

this didn't work....
(Save, use Alt+F12 to see the DFM, items are still there)


topkapi
0
topkapiAuthor Commented:
or, maybe we can solve this the other way round...

if the form cntaining the TActionMenu is saved, the entries in the dfm are created, but the corrosponding TMenuItems varaibles are never added to the form.

if someone can show me how to add the items to the form, im also happy.

topkapi
0
kambizCommented:
Try to test this template:

protected
  procedure TActionMenu.WriteState(Writer: TWriter); overide;


procedure TActionMenu.WriteState(Writer: TWriter);
begin
  Items.Clear;
  inherited WriteState(Writer);
  RebuildItems; // here rebuild your list by using actions
end;

I hope this helps you
Kambiz
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
topkapiAuthor Commented:
it works perfect.

thanks a lot.

for those that are interested, here is the complete component sourde:

unit ActionMenu;

{-------------------------------------------------------------------------------

  Name        : TActionMenu
  Descr       : TActionMenu is a TMainMenu descendant that creates its own
                items, based upon an TActionList assigned to it. It also uses
                (if available) the TImageList assigned to the TActionList.
  Last Update : Januari 2000
  Copyright   :

      Copyright© 2000 Remco Christiaan Kapinga.

      This software is created by Remco Christiaan Kapinga. You can reach
      me via E-Mail on the following address :  r.kapinga@cable.a2000.nl.
      On my homepage (http://people.a2000.nl/rkapinga)  you can find some
      more code samples.

      This software is free  software;  you  can  redistribute it  and/or
      modify  it under  the  terms of the  GNU General Public License  as
      published  by the Free Software Foundation; either version 2 of the
      License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful, but
      WITHOUT   ANY  WARRANTY;  without  even  the  implied  warranty  of
      MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      General Public License for more details.

      You  can find  a copy  of the  GNU  General  Public License  on the
      following web site : http://www.gnu.org/copyleft/gpl.html

-------------------------------------------------------------------------------}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ActnList;

type
  TActionMenu = class(TMainMenu)
  private
    FActionList: TCustomActionList;
    procedure SetActionList(Value: TCustomActionList);

  protected
    procedure WriteState(Writer: TWriter); override;

    procedure RebuildMenu; virtual;

  public
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;

  published
    property ActionList: TCustomActionList read FActionList write SetActionList;

  end;

implementation

procedure TActionMenu.RebuildMenu;
var
  I: integer;
  TmpItem: TMenuItem;
  Catagory: string;
  SubMenu: TMenuItem;
begin
  // Clear the current Menu.
  Items.Clear;

  if FActionList = nil then
    Exit;

  // Create new menu based on the action list...
  for I := 0 to FActionList.ActionCount -1 do
  begin
    // Find out what catagory the action is listed in.
    Catagory := FActionList.Actions[I].Category;

    // Create a submenu for the catagory if non-existent.
    SubMenu := Items.Find(Catagory);
    if SubMenu = nil then
    begin
      SubMenu := TMenuItem.Create(Self);
      SubMenu.Caption := Catagory;
      SubMenu.GroupIndex := FActionList.Actions[I].Tag;
      Items.Add(SubMenu);
    end;

    // Create the item and add to SubMenu.
    TmpItem := TMenuItem.Create(Self);
    TmpItem.Action := FActionList.Actions[I];
    TmpItem.GroupIndex := FActionList.Actions[I].Tag;
    SubMenu.Add(TmpItem);
  end; // for
end;


procedure TActionMenu.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;

  if (AComponent = FActionList) and (Operation = opRemove) then
    ActionList := nil;
end;


procedure TActionMenu.SetActionList(Value: TCustomActionList);
begin
  if Value <> FActionList then
  begin
    FActionList := Value;

    if FActionList = nil then
      Images := nil
    else begin
      FActionList.FreeNotification(Self);
      Images := FActionList.Images;
    end;

    if not (csReading in ComponentState) then
      RebuildMenu;
  end;
end;

procedure TActionMenu.WriteState(Writer: TWriter);
begin
  Items.Clear;
  inherited WriteState(Writer);
  RebuildMenu;
end;

end.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.