我正在处理 delph7 应用程序,该应用程序使用操作管理器有许多操作(超过50个)。为了跟踪我的每个动作…到目前为止,我有如果else,如以下代码..
procedure TMainForm.OnActionExecute(Sender: TObject);
var
Action : TBasicAction;
begin
Action := Sender as TBasicAction;
if (Action is TAction) and not TAction(Action).Enabled then exit;
if Action = SQLQueryAction then
begin
//do somthing
end
else if (Action = NewSurveyAction) then
begin
//do somthing
end
else if ...
..
..
//lots of actions with if else latr..
end;// of OnActionExecute....
谁能告诉我
如何使用"案例"和
case actions of SQLQueryAction : //do somthing; newsurveyaction : //do somthing; //lots more actions to go.. end; //of case.
不能在非序数类型上使用case。但是,每个操作都有一个保存整数的Tag属性。如果为每个操作分配一个映射到常量的Tag,可以这样做:
case action.tag of
SQL_QUERY_TAG: //do something
NEW_SURVEY_TAG: //do something
//etc
end;