请问一个很奇怪的问题,很奇怪!(50分)

  • 主题发起人 主题发起人 zhpwan
  • 开始时间 开始时间
Z

zhpwan

Unregistered / Unconfirmed
GUEST, unregistred user!
在一Procedure中声明一个类型为String变量
但在Case语句中对其赋值,但是编译时提示
Constant expression expected错误
请问为什么会发生此类错误?

源代码如下:
procedure TFrm_Stakelog.BB_ShwClick(Sender: TObject);
var
ls_title :string;
ls_log_sql : string;
.........
Begin
.........
case rg_log.ItemIndex of
0 :
ls_title := 'Prep';
{The Following statement is error :Constant expression expected}
ls_log_sql := 'select sum(cdrnum), sum(normcdrnum), sum(errcdrnum) from log_prep ';
li_series_count := 3;
1 :
ls_title := 'Charge';
{The Following statement is error :Constant expression expected}
ls_log_sql := 'select sum(cdrnum),sum(cr_cdrnum),'
+ 'sum(trashcdrnum),sum(errcdrnum) from log_rate';
li_series_count := 4;
2 :
ls_title := 'Settle';
{The Following statement is error :Constant expression expected}
ls_log_sql := 'select sum(cdrnum),sum(settcdrnum),sum(trashcdrnum),sum(errcdrnum) from log_settle';
li_series_count := 4;
end;

同样的操作ls_title 不会出现这类错误,而ls_log_sql 会出现。
为什么会这样?
 
//你所要写的是一个复合语句,可你没有加上“begin...end”

var
ls_title :string;
ls_log_sql : string;
// .........
Begin
// .........
case rg_log.ItemIndex of
0 :
begin
ls_title := 'Prep';
{The Following statement is error :Constant expression expected}
ls_log_sql := 'select sum(cdrnum), sum(normcdrnum), sum(errcdrnum) from log_prep ';
li_series_count := 3;
end;
1 :
begin
ls_title := 'Charge';
{The Following statement is error :Constant expression expected}
ls_log_sql := 'select sum(cdrnum),sum(cr_cdrnum),'
+ 'sum(trashcdrnum),sum(errcdrnum) from log_rate';
li_series_count := 4;
end;
2 :
begin
ls_title := 'Settle';
{The Following statement is error :Constant expression expected}
ls_log_sql := 'select sum(cdrnum),sum(settcdrnum),sum(trashcdrnum),sum(errcdrnum) from log_settle';
li_series_count := 4;
end;
end;
end;
 
注意:
A case statement has the form
case selectorExpression of
caseList1: statement1;
...
caseListn: statementn;
end
statement1...是一条语句,不是你那么多.这时要使用复合语句BEGIN..END;
 
case语句后还要加break;否则全部代码都执行的哦
 
看来根据编译器提示的错误很容易产生误导,就一个语法问题费了我太多的时间了。[8D]
 
->case语句后还要加break;否则全部代码都执行的哦
误人子弟!你以为是C
 
后退
顶部