procedure TForm1.Init(P: string);
begin
case P of
'馆长' : begin
N2.Enabled := True;
N3.Enabled := True;
end;
'验收员':N3.Enabled := True;
end;
end;
[Error] : 'of' Ordinal type required
[Error] :
'馆长''验收员' Incompatible types: 'Integer' and 'String'
begin
case P of
'馆长' : begin
N2.Enabled := True;
N3.Enabled := True;
end;
'验收员':N3.Enabled := True;
end;
end;
[Error] : 'of' Ordinal type required
[Error] :
'馆长''验收员' Incompatible types: 'Integer' and 'String'
string和real类型不能用于case语句中
IF P=‘馆长' THEN P1:=1;
IF P='验收员' THEN P1:=2;
CASE P1 OF
DO SOMETHING
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[i] 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;
begin
N2.Enabled := True;
N3.Enabled := True;
end
else if p='验收员' then
N3.Enabled := True
else if ...
我目前没发现delphi有什么优点,和VB相比