我有一个 TSpeedButton 类型的自定义组件,它定义了两个额外的属性:
CommentHeading: string;
CommentText: string;
我在设计时设置了 CommentHeading。
当按下速度按钮时,会显示一个备忘录,其下方有一个用于保存其内容的按钮。处理此问题的过程:
procedure CustomSpeedButton1Click(Sender: TObject);
begin
Receiver := CustomSpeedButton1.Name; // possibly used to save the memo text back to this speedbuttons property after comments are submitted
ViewComments(CustomSpeedButton1.CommentTitle,CustomSpeedButton1.CommentText);
end;
ViewComments 过程本身:
procedure ViewComments(comment_caption:string; comment_text:string);
begin
label15.Hide; // label showing editing in progress, hidden until user begins typing
Button1.Enabled := false; // the button for saving the memo text, hidden until user begins typing
CommentsBox.Visible := true; // pop up the comment box at the bottom of the form
CommentsBox.Caption := 'Comments: ' + comment_caption;
CommentsMemo.Text := comment_text; // if there are existing comments assign them to memo
end;
备忘录的内容需要分配给自定义 SpeedButton 的 CommentText 属性。
我最初的想法是,我可以在按下自定义 SpeedButton 时将组件名称传递给变量,然后在按下备忘录上的保存按钮时检索该名称,并使用它将备忘录文本分配给 speedbuttons CommentText 属性。但后来我意识到,要做到这一点,我必须使用某种 case..of 语句来检查每个可能的 speedbutton 名称,然后将 memo 值分配给它的属性,这看起来非常乏味。
有没有更简单的方法可以将备忘录文本分配给打开备忘录的快速按钮?