如何动态的读取Delphi中的PopupMenu的Caption
展开全部
Procedure TForm1.FormCreate(Sender: TObject);
Procedure DoAddCaption(MenuItem: TMenuItem; List: TStrings);
Begin
If Not MenuItem.IsLine Then
Begin
List.Add(MenuItem.Caption);
End;
End;
Procedure GetChildItemCaption(MenuItem: TMenuItem; List: TStrings);
Var
I: Integer;
Begin
For I := 0 To MenuItem.Count - 1 Do
Begin
DoAddCaption(MenuItem[I], List);
If MenuItem[I].Count > 0 Then
Begin
GetChildItemCaption(MenuItem[I], List);
End;
End;
End;
Var
I: Integer;
alist: TStringList;
Begin
alist := TStringList.Create;
Try
With PopupMenu1 Do
Begin
For I := 0 To Items.Count - 1 Do
Begin
DoAddCaption(Items[I], alist);
If Items[I].Count > 0 Then
Begin
GetChildItemCaption(Items[I], alist);
End;
End;
End;
Memo1.Lines.Text := alist.Text;
//Application.MessageBox(PChar(alist.Text), 'msg', 64);
Finally
alist.Clear;
alist.Free;
End;
End;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询