Pre*_*ias 0 delphi if-statement case delphi-7
我正在使用动作管理器处理具有大量动作(超过50个)的delph 7应用程序.并跟踪我有的每一个动作..现在我还有其他如下代码..
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....
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我
如何使用'案例'之类的
case actions of
SQLQueryAction : //do somthing;
newsurveyaction : //do somthing;
//lots more actions to go..
end; //of case.
Run Code Online (Sandbox Code Playgroud)您不能在非序数类型上使用大小写.但是,每个操作都有一个包含整数的Tag属性.如果为每个操作分配一个映射到常量的标记,则可以执行以下操作:
case action.tag of
SQL_QUERY_TAG: //do something
NEW_SURVEY_TAG: //do something
//etc
end;
Run Code Online (Sandbox Code Playgroud)