Board index » cppbuilder » ActionManager & MRU Files List in BCB6/2006

ActionManager & MRU Files List in BCB6/2006


2006-02-15 05:39:04 AM
cppbuilder48
Hi!
I'm trying to implement a MRU files list in BCB6/2006 using Borlands
TActionManager, TActionMenu, etc., components, after the model provided
in the Delphi Example Programs.
My current problem is that I'm trying to render the following Delphi
code into BCB C++:
Quote
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
procedure TForm1.FindReopenMenuItem(AClient: TActionClient);
begin
// Find the Reopen item by looking at the item caption
if AClient is TActionClientItem then
if Pos('Reopen...', TActionClientItem(AClient).Caption) <>0 then
ReopenMenuItem := AClient as TActionClientItem
end;
procedure TForm1.FindOpenToolItem(AClient: TActionClient);
begin
// Find the Open item by looking at the item caption
if AClient is TActionClientItem then
if Pos('Open', TActionClientItem(AClient).Caption) <>0 then
OpenToolItem := AClient as TActionClientItem;
end;
procedure TForm1.FormCreate(Sender: TObject);
procedure SetupItemCaptions(AnItem: TActionClientItem);
var
I: Integer;
begin
if Assigned(AnItem) then
for I := 0 to AnItem.Items.Count - 1 do
TCustomAction(ReopenActionList1.Actions[I]).Caption :=
Copy(AnItem.Items[I].Caption, 5, MaxInt);
end;
begin
........
// Find the Reopen... menu item on the ActionMainMenu
ActionManager1.ActionBars.IterateClients(ActionManager1.ActionBars[0].Items,
FindReopenMenuItem);
// Find the Reopen... menu item on the ActionToolBar
ActionManager1.ActionBars.IterateClients(ActionManager1.ActionBars[1].Items,
FindOpenToolItem);
// Set the captions of the actions since they are used to open the
file
SetupItemCaptions(ReopenMenuItem);
SetupItemCaptions(OpenToolItem);
end;
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I have written the following C++ line to do the "IterateClients"
function calling the "callback" function "FindReopenMenuItem" which is
required to be a __closure in the parameter list:
ActionManager1->ActionBars->IterateClients
((TActionClientsCollection*)ActionManager1->ActionBars[0].Items->Collection,
FindReopenMenuItm);
The "callback" is declared as:
void __fastcall TForm1::FindReopenMenuItem(TActionClient *AClient);
I get the compile-time error message:
[C++ Error] Main.cpp(27): E2193 Too few parameters in call to '_fastcall
TCollection::GetItem(int)'
I have combed the Internet for use of "ActionProc" and read Tamas
Demjen's 2002 article on closures, but I'm a bit confused and I can`t
get the thing to work.
Anyone have any ideas? It seems so straightforward in Delphi!
Regards
Steve
XXXX@XXXXX.COM
 
 

Re:ActionManager & MRU Files List in BCB6/2006

"Stephen T. Smith" < XXXX@XXXXX.COM >wrote in message
Quote
My current problem is that I'm trying to render the following
Delphi code into BCB C++:
Here you go:
void __fastcall TForm1::FindReopenMenuItem(TActionClient *AClient)
{
// Find the Reopen item by looking at the item caption
TActionClientItem *Item = dynamic_cast<TActionClientItem*>(AClient);
if( (Item) && (Item->Caption.Pos("Reopen...") != 0) )
ReopenMenuItem = Item;
}
void __fastcall TForm1::FindOpenToolItem(TActionClient *AClient)
{
// Find the Open item by looking at the item caption
TActionClientItem *Item = dynamic_cast<TActionClientItem*>(AClient);
if( (Item) && (Item->Caption.Pos("Open") != 0) )
OpenToolItem = Item;
}
procedure SetupItemCaptions(TActionClientItem *AnItem)
{
if( AnItem )
{
for(int I = 0; I < AnItem->Items->Count; ++I)
static_cast<TCustomAction*>(ReopenActionList1->Actions[I])->Caption =
AnItem->Items[I]->Caption.SubString(5, MaxInt);
}
}
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
// ...
// Find the Reopen... menu item on the ActionMainMenu
ActionManager1->ActionBars->IterateClients(ActionManager1->ActionBars->Items
[0]->Items, FindReopenMenuItem);
// Find the Reopen... menu item on the ActionToolBar
ActionManager1->ActionBars->IterateClients(ActionManager1->ActionBars->Items
[1]->Items, FindOpenToolItem);
// Set the captions of the actions since they are used to open the
file
SetupItemCaptions(ReopenMenuItem);
SetupItemCaptions(OpenToolItem);
}
Gambit
 

Re:ActionManager & MRU Files List in BCB6/2006

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote

"Stephen T. Smith" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>My current problem is that I'm trying to render the following
>Delphi code into BCB C++:

Here you go:

void __fastcall TForm1::FindReopenMenuItem(TActionClient *AClient)
{
// Find the Reopen item by looking at the item caption
TActionClientItem *Item =
dynamic_cast<TActionClientItem*>(AClient);
if( (Item) && (Item->Caption.Pos("Reopen...") != 0) )
ReopenMenuItem = Item;
}

void __fastcall TForm1::FindOpenToolItem(TActionClient *AClient)
{
// Find the Open item by looking at the item caption
TActionClientItem *Item =
dynamic_cast<TActionClientItem*>(AClient);
if( (Item) && (Item->Caption.Pos("Open") != 0) )
OpenToolItem = Item;
}

procedure SetupItemCaptions(TActionClientItem *AnItem)
{
if( AnItem )
{
for(int I = 0; I < AnItem->Items->Count; ++I)

static_cast<TCustomAction*>(ReopenActionList1->Actions[I])->Caption =
AnItem->Items[I]->Caption.SubString(5, MaxInt);
}
}

__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
// ...

// Find the Reopen... menu item on the ActionMainMenu

ActionManager1->ActionBars->IterateClients(ActionManager1->ActionBars->Items
[0]->Items, FindReopenMenuItem);

// Find the Reopen... menu item on the ActionToolBar

ActionManager1->ActionBars->IterateClients(ActionManager1->ActionBars->Items
[1]->Items, FindOpenToolItem);

// Set the captions of the actions since they are used to open the
file
SetupItemCaptions(ReopenMenuItem);
SetupItemCaptions(OpenToolItem);
}


Gambit


Hi!
Thanks for translation. The thing with the dynamic_cast<>is good!
Unfortunately the code doesn't compile!
This is what I have in the project right now, annotated with the compiler
errors:
Quote
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
RichEdit1->Align = alClient;
// Find the Reopen... menu item on the ActionMainMenu
ActionManager1->ActionBars->IterateClients
(ActionManager1->ActionBars->Items[0]->Items ,FindReopenMenuItem);
^
|----E2316 'Items' is not a member of 'TCollectonItem'
// Find the Reopen... menu item on the ActionToolBar
ActionManager1->ActionBars->IterateClients
(ActionManager1->ActionBars->Items[1]->Items,FindOpenToolItem);
^
|----E2316 'Items' is not a member of 'TCollectonItem'
// Set the captions of the actions since they are used to open the file
SetupItemCaptions(ReopenMenuItem);
SetupItemCaptions(OpenToolItem);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FindReopenMenuItem(TActionClient *AClient)
{
// Find the Reopen item by looking at the item caption
TActionClientItem *Item = dynamic_cast<TActionClientItem*>(AClient);
if ((Item) && (Item->Caption.Pos("Reopen...") != 0))
ReopenMenuItem = Item;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FindOpenToolItem(TActionClient *AClient)
{
// Find the Open item by looking at the item caption
TActionClientItem *Item = dynamic_cast<TActionClientItem*>(AClient);
if( (Item) && (Item->Caption.Pos("Open") != 0 ))
OpenToolItem = Item;
}
void __fastcall TForm1::SetupItemCaptions(TActionClientItem *AnItem)
{
if(AnItem)
for(int I = 0; I < AnItem->Items->Count; ++I)
static_cast<TCustomAction*>(ReopenActionList1->Actions[I])->Caption =
AnItem->Items[I]->Caption.SubString(5, MaxInt);
^
|-------------- E2288 Pointer to structure
required on left side of ->or ->*
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Any further ideas?
Regards
Steve Smith
 

{smallsort}