這在運行時增加了一個ActionClientItem從的StringList:如何獲得ActionClient ChildItem添加的指標和標題在運行時
var
ActionClient: TActionClient;
ChildItem: TActionClientItem;
if FileExists(ARecentFilesFilename) then
begin
ARecentFilesList.LoadFromFile(ARecentFilesFilename);
// remove any duplicates
RemoveDuplicates(ARecentFilesList);
for i := 0 to ARecentFilesList.Count - 1 do
begin
Ribbon1.AddRecentItem(ARecentFilesList.Strings[ i ]);
ActionClient := RibbonGroup1.ActionControls[ 1 ].ActionClient;
ChildItem := ActionClient.Items.Add;
ChildItem.Tag := i;
ChildItem.Action := ActionOpenFileFromButton1;
ChildItem.Caption := ARecentFilesList.Strings[ i ];
end;
end;
這試圖獲取選中ActionClientItem的文件名,但它失敗。
procedure TMainForm.ActionOpenFileFromButton1Execute(Sender: TObject);
var
ActionClient: TActionClient;
ChildItem: TActionClientItem;
AFilename: string;
AIndex: integer;
begin
ActionClient := RibbonGroup1.ActionControls[ 1 ].ActionClient;
AIndex := ActionClient.Index;
ChildItem := ActionClient.Items.ActionClients[ AIndex ];
AFilename := ChildItem.Caption;
OpenZipFileFromChildButton(AFilename);
end;
我在做什麼錯? 有沒有不同的方式做到這一點?
「它失敗」 是沒有問題的充分說明。它不會編譯?它會給你一個你沒有想到的結果嗎?它會崩潰嗎?它是否會讓您的打印機着火?如果是,請告訴我們錯誤信息或發送打印機照片。 – 2009-09-17 23:38:25
AIndex返回不正確的索引,因爲它總是返回「1」。我認爲它是返回ActionClient的索引,而不是TActionClientItem ....你如何獲得TActionClientItem的索引? – 2009-09-18 00:49:10
爲什麼*不會成爲ActionClient的索引?您通過閱讀「ActionClient.Index」來分配它。 – 2009-09-18 02:17:16