if 2 case(15分)

  • 主题发起人 主题发起人 lordofbinladen
  • 开始时间 开始时间
L

lordofbinladen

Unregistered / Unconfirmed
GUEST, unregistred user!
if sState ='纳闽' then result:='Labuan';
if sState ='马六甲' then result:='Melaka';
if sState ='森美兰' then result:='Negeri Sembilan';
if sState ='吉隆坡' then result :='Kuala Lumpur';

可否将以上程序改成使用CASE, 若可, 该如何改?
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1358621
 
lichdr的方法很详细了,够你使用的了吧!
 
定义常量是最正确的方法
 
function CaseString (const s: string

const x: array of string): Integer

var i: Integer

begin
Result:= -1
// Default return parameter
for i:= Low (x) to High (x) do begin
if s = x then begin Result:= i
Exit
end

end

end


search:= 'delphi3000'

case CaseString (search, ['delphi3000',
'delphipages',
'Torry's']) of
0: s:= 'Excellent!'

1: s:= 'Good source'

2: s:= 'Not bad!'

end

/////////////////////////////////

const MatchingStrings = '*First*Second*Third*'

var sString: string

...

// sString has the data you want to test
case pos('*'+sString+'*',MatchingStrings) of
1: <do something> // This is the match for 'First'
7: <do something> // This is the match for 'Second'
14: <do something> // This is the match for 'Third'
else <do something> // In this case there were no matches
end;
摘自hubgo
 
后退
顶部