F
fyxr
Unregistered / Unconfirmed
GUEST, unregistred user!
请大侠看下我的函数为什么出“ 函数 might be undefined ”报警,
去掉注释任一处都将报警,因为有提前返回,没办法写成完整的if嵌套,
请问如何修改,谢谢!
function gufGetNextSerialNumber(aSerialNumber:string;aSeparatorBeforeNotCompute:Boolean=True;aFixLength:Boolean=True;aLetterNotCompute:Boolean=True):string;
var
SerialNumber:string;
SeparatorBeforeNotCompute:Boolean;
FixLength:Boolean;
LetterNotCompute:Boolean;
SerialNumberLength:Integer;
I:Integer;
BreakI:Integer;
HeadNumberIndex:Integer;
LastNumberIndex:Integer;
NumberBeforeStr:string;
NumberBehindStr:string;
SeparatorIndex:Integer;
ComputeStr:string;
NotComputeIndex:Integer;
NotComputeStr:string;
FormatComputeStr:string;
begin
SerialNumber:=aSerialNumber;
SeparatorBeforeNotCompute:=aSeparatorBeforeNotCompute;
FixLength:=aFixLength;
LetterNotCompute:=aLetterNotCompute;
HeadNumberIndex:=-1;
LastNumberIndex:=-1;
SeparatorIndex:=-1;
NotComputeIndex:=-1;
BreakI:=-1;
SerialNumberLength:=Length(SerialNumber);
if SerialNumberLength<1 then begin Result:='';Exit;end;
for I:=SerialNumberLength downto 1 do
begin
if (HeadNumberIndex=-1) and (SerialNumber in ['0'..'9']) then HeadNumberIndex:=I
else if (HeadNumberIndex<>-1) and (not (SerialNumber in ['0'..'9'])) then begin LastNumberIndex:=I+1;Break;end;
end;
for I:=SerialNumberLength downto 1 do if not (SerialNumber in ['0'..'9','a'..'z','A'..'Z']) then begin SeparatorIndex:=I;Break;end;
if ((SeparatorBeforeNotCompute) and (FixLength) and (LetterNotCompute)) then
begin
//(*
if (HeadNumberIndex=-1) or (LastNumberIndex=-1) then begin Result:='';Exit;end;
if SeparatorIndex>LastNumberIndex then begin Result:='';Exit;end;
NumberBeforeStr:=Copy(SerialNumber,1,LastNumberIndex-1);
NumberBehindStr:=Copy(SerialNumber),1,SerialNumberLength-HeadNumberIndex);
ComputeStr:=Copy(SerialNumber,SerialNumberLength-HeadNumberIndex+1,HeadNumberIndex-LastNumberIndex+1));
if ComputeStr='' then begin Result:='';Exit;end;
if Length(IntToStr(StrToInt(ComputeStr)+1))>Length(ComputeStr) then begin Result:='';Exit;end
else
begin
FormatComputeStr:=IntToStr(StrToInt(ComputeStr)+1);
FormatComputeStr:=StringOfChar('0',Length(ComputeStr)-Length(FormatComputeStr))+FormatComputeStr;
Result:=NumberBeforeStr+FormatComputeStr+NumberBehindStr;
Exit;
end;
//*)
end;
if ((SeparatorBeforeNotCompute) and (FixLength) and (not LetterNotCompute)) then
begin
//(*
for I:=SerialNumberLength downto 1 do
begin
if not (SerialNumber in ['0'..'9','a'..'z','A'..'Z']) then begin Result:='';Exit;end
else
begin
if SerialNumber in ['0'..'9'] then
begin
if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='0';
end;
if SerialNumber in ['a'..'z'] then
begin
if (SerialNumber<'z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='a';
end;
if SerialNumber in ['A'..'Z'] then
begin
if (SerialNumber<'Z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='A';
end;
end;
end;
//*)
end;
if (SeparatorBeforeNotCompute) and (not FixLength) and (LetterNotCompute) then
begin
//(*
if (HeadNumberIndex=-1) or (LastNumberIndex=-1) then begin Result:='';Exit;end;
if SeparatorIndex>LastNumberIndex then begin Result:='';Exit;end;
NumberBeforeStr:=Copy(SerialNumber,1,LastNumberIndex-1);
NumberBehindStr:=Copy(SerialNumber,1,SerialNumberLength-HeadNumberIndex);
ComputeStr:=Copy(SerialNumber,SerialNumberLength-HeadNumberIndex+1,HeadNumberIndex-LastNumberIndex+1));
if (ComputeStr='') then begin Result:='';Exit;end;
FormatComputeStr:=IntToStr(StrToInt(ComputeStr)+1);
FormatComputeStr:=StringOfChar('0',Length(ComputeStr)-Length(FormatComputeStr))+FormatComputeStr;
Result:=NumberBeforeStr+FormatComputeStr+NumberBehindStr;
Exit;
//*)
end;
if (SeparatorBeforeNotCompute) and (not FixLength) and (not LetterNotCompute) then
begin
//(*
for I:=SerialNumberLength downto 1 do if not (SerialNumber in ['0'..'9','a'..'z','A'..'Z']) then begin NotComputeIndex:=SerialNumberLength-I;Break;end;
ComputeStr:=Copy(SerialNumber,1,NotComputeIndex);
NotComputeStr:=Copy(SerialNumber,1,SerialNumberLength-NotComputeIndex);
for I:=Length(ComputeStr) downto 1 do
begin
if ComputeStr in ['0'..'9'] then
begin
if (ComputeStr<'9') then begin ComputeStr:=Chr(Ord(ComputeStr)+1);Result:=NotComputeStr+ComputeStr;Exit;end
else ComputeStr:='0';
end;
if ComputeStr in ['a'..'z'] then
begin
if (ComputeStr<'z') then begin ComputeStr:=Chr(Ord(ComputeStr)+1);Result:=NotComputeStr+ComputeStr;Exit;end
else ComputeStr:='a';
end;
if ComputeStr in ['A'..'Z'] then
begin
if (ComputeStr<'Z') then begin ComputeStr:=Chr(Ord(ComputeStr)+1);Result:=NotComputeStr+ComputeStr;Exit;end
else ComputeStr:='A';
end;
BreakI:=I;
end;
if (BreakI=0) and (ComputeStr[1] in ['0'..'9']) then begin Result:=NotComputeStr+'1'+ComputeStr;Exit;end;
if (BreakI=0) and (ComputeStr[1] in ['a'..'z']) then begin Result:=NotComputeStr+'a'+ComputeStr;Exit;end;
if (BreakI=0) and (ComputeStr[1] in ['A'..'Z']) then begin Result:=NotComputeStr+'A'+ComputeStr;Exit;end;
//*)
end;
if (not SeparatorBeforeNotCompute) and (FixLength) and (LetterNotCompute) then
begin
//(*
for I:=SerialNumberLength downto 1 do
begin
if SerialNumber in ['0'..'9'] then
begin
if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='0';
end;
BreakI:=I;
end;
if (BreakI=0) then begin Result:='';Exit;end;
//*)
end;
if (not SeparatorBeforeNotCompute) and (FixLength) and (not LetterNotCompute) then
begin
//(*
for I:=SerialNumberLength downto 1 do
begin
if SerialNumber in ['0'..'9'] then
begin
if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='0';
end;
if SerialNumber in ['a'..'z'] then
begin
if (SerialNumber<'z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='a';
end;
if SerialNumber in ['A'..'Z'] then
begin
if (SerialNumber<'Z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='A';
end;
BreakI:=I;
end;
if (BreakI=0) then begin Result:='';Exit;end;
//*)
end;
if (not SeparatorBeforeNotCompute) and (not FixLength) and (LetterNotCompute) then
begin
//(*
if (HeadNumberIndex=-1) or (LastNumberIndex=-1) then begin Result:='';Exit;end;
NumberBeforeStr:=Copy(SerialNumber,1,LastNumberIndex-1);
NumberBehindStr:=Copy(SerialNumber,1,SerialNumberLength-HeadNumberIndex);
ComputeStr:=Copy(SerialNumber,SerialNumberLength-HeadNumberIndex+1,HeadNumberIndex-LastNumberIndex+1));
//if (ComputeStr='') then begin Result:='';Exit;end;
FormatComputeStr:=IntToStr(StrToInt(ComputeStr)+1);
//FormatComputeStr:=StringOfChar('0',Length(ComputeStr)-Length(FormatComputeStr))+FormatComputeStr;//这一行比较奇怪,没有Result也出警告
Result:=NumberBeforeStr+FormatComputeStr+NumberBehindStr;
Exit;
//*)
end;
if (not SeparatorBeforeNotCompute) and (not FixLength) and (not LetterNotCompute) then
begin
//(*
//for I:=Length(SerialNumber) downto 1 do
begin
//if SerialNumber in ['0'..'9'] then
begin
//if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=NotComputeStr+SerialNumber;Exit;end
//else SerialNumber:='0';
end;
//if SerialNumber in ['a'..'z'] then
begin
//if (SerialNumber<'z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=NotComputeStr+SerialNumber;Exit;end
//else SerialNumber:='a';
end;
//if SerialNumber in ['A'..'Z'] then
begin
//if (SerialNumber<'Z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=NotComputeStr+SerialNumber;Exit;end
//else SerialNumber:='A';
end;
end;
//for I:=1 to SerialNumberLength do
begin
//if (SerialNumber in ['0'..'9']) then begin Result:=Copy(SerialNumber,1,I-1)+'1'+Copy(SerialNumber,I,SerialNumberLength-I+1);Exit;end;
//if (SerialNumber in ['a'..'z']) then begin Result:=Copy(SerialNumber,1,I-1)+'a'+Copy(SerialNumber,I,SerialNumberLength-I+1);Exit;end;
//if (SerialNumber in ['A'..'Z']) then begin Result:=Copy(SerialNumber,1,I-1)+'A'+Copy(SerialNumber,I,SerialNumberLength-I+1);Exit;end;
end;
//*)
end;
end;
去掉注释任一处都将报警,因为有提前返回,没办法写成完整的if嵌套,
请问如何修改,谢谢!
function gufGetNextSerialNumber(aSerialNumber:string;aSeparatorBeforeNotCompute:Boolean=True;aFixLength:Boolean=True;aLetterNotCompute:Boolean=True):string;
var
SerialNumber:string;
SeparatorBeforeNotCompute:Boolean;
FixLength:Boolean;
LetterNotCompute:Boolean;
SerialNumberLength:Integer;
I:Integer;
BreakI:Integer;
HeadNumberIndex:Integer;
LastNumberIndex:Integer;
NumberBeforeStr:string;
NumberBehindStr:string;
SeparatorIndex:Integer;
ComputeStr:string;
NotComputeIndex:Integer;
NotComputeStr:string;
FormatComputeStr:string;
begin
SerialNumber:=aSerialNumber;
SeparatorBeforeNotCompute:=aSeparatorBeforeNotCompute;
FixLength:=aFixLength;
LetterNotCompute:=aLetterNotCompute;
HeadNumberIndex:=-1;
LastNumberIndex:=-1;
SeparatorIndex:=-1;
NotComputeIndex:=-1;
BreakI:=-1;
SerialNumberLength:=Length(SerialNumber);
if SerialNumberLength<1 then begin Result:='';Exit;end;
for I:=SerialNumberLength downto 1 do
begin
if (HeadNumberIndex=-1) and (SerialNumber in ['0'..'9']) then HeadNumberIndex:=I
else if (HeadNumberIndex<>-1) and (not (SerialNumber in ['0'..'9'])) then begin LastNumberIndex:=I+1;Break;end;
end;
for I:=SerialNumberLength downto 1 do if not (SerialNumber in ['0'..'9','a'..'z','A'..'Z']) then begin SeparatorIndex:=I;Break;end;
if ((SeparatorBeforeNotCompute) and (FixLength) and (LetterNotCompute)) then
begin
//(*
if (HeadNumberIndex=-1) or (LastNumberIndex=-1) then begin Result:='';Exit;end;
if SeparatorIndex>LastNumberIndex then begin Result:='';Exit;end;
NumberBeforeStr:=Copy(SerialNumber,1,LastNumberIndex-1);
NumberBehindStr:=Copy(SerialNumber),1,SerialNumberLength-HeadNumberIndex);
ComputeStr:=Copy(SerialNumber,SerialNumberLength-HeadNumberIndex+1,HeadNumberIndex-LastNumberIndex+1));
if ComputeStr='' then begin Result:='';Exit;end;
if Length(IntToStr(StrToInt(ComputeStr)+1))>Length(ComputeStr) then begin Result:='';Exit;end
else
begin
FormatComputeStr:=IntToStr(StrToInt(ComputeStr)+1);
FormatComputeStr:=StringOfChar('0',Length(ComputeStr)-Length(FormatComputeStr))+FormatComputeStr;
Result:=NumberBeforeStr+FormatComputeStr+NumberBehindStr;
Exit;
end;
//*)
end;
if ((SeparatorBeforeNotCompute) and (FixLength) and (not LetterNotCompute)) then
begin
//(*
for I:=SerialNumberLength downto 1 do
begin
if not (SerialNumber in ['0'..'9','a'..'z','A'..'Z']) then begin Result:='';Exit;end
else
begin
if SerialNumber in ['0'..'9'] then
begin
if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='0';
end;
if SerialNumber in ['a'..'z'] then
begin
if (SerialNumber<'z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='a';
end;
if SerialNumber in ['A'..'Z'] then
begin
if (SerialNumber<'Z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='A';
end;
end;
end;
//*)
end;
if (SeparatorBeforeNotCompute) and (not FixLength) and (LetterNotCompute) then
begin
//(*
if (HeadNumberIndex=-1) or (LastNumberIndex=-1) then begin Result:='';Exit;end;
if SeparatorIndex>LastNumberIndex then begin Result:='';Exit;end;
NumberBeforeStr:=Copy(SerialNumber,1,LastNumberIndex-1);
NumberBehindStr:=Copy(SerialNumber,1,SerialNumberLength-HeadNumberIndex);
ComputeStr:=Copy(SerialNumber,SerialNumberLength-HeadNumberIndex+1,HeadNumberIndex-LastNumberIndex+1));
if (ComputeStr='') then begin Result:='';Exit;end;
FormatComputeStr:=IntToStr(StrToInt(ComputeStr)+1);
FormatComputeStr:=StringOfChar('0',Length(ComputeStr)-Length(FormatComputeStr))+FormatComputeStr;
Result:=NumberBeforeStr+FormatComputeStr+NumberBehindStr;
Exit;
//*)
end;
if (SeparatorBeforeNotCompute) and (not FixLength) and (not LetterNotCompute) then
begin
//(*
for I:=SerialNumberLength downto 1 do if not (SerialNumber in ['0'..'9','a'..'z','A'..'Z']) then begin NotComputeIndex:=SerialNumberLength-I;Break;end;
ComputeStr:=Copy(SerialNumber,1,NotComputeIndex);
NotComputeStr:=Copy(SerialNumber,1,SerialNumberLength-NotComputeIndex);
for I:=Length(ComputeStr) downto 1 do
begin
if ComputeStr in ['0'..'9'] then
begin
if (ComputeStr<'9') then begin ComputeStr:=Chr(Ord(ComputeStr)+1);Result:=NotComputeStr+ComputeStr;Exit;end
else ComputeStr:='0';
end;
if ComputeStr in ['a'..'z'] then
begin
if (ComputeStr<'z') then begin ComputeStr:=Chr(Ord(ComputeStr)+1);Result:=NotComputeStr+ComputeStr;Exit;end
else ComputeStr:='a';
end;
if ComputeStr in ['A'..'Z'] then
begin
if (ComputeStr<'Z') then begin ComputeStr:=Chr(Ord(ComputeStr)+1);Result:=NotComputeStr+ComputeStr;Exit;end
else ComputeStr:='A';
end;
BreakI:=I;
end;
if (BreakI=0) and (ComputeStr[1] in ['0'..'9']) then begin Result:=NotComputeStr+'1'+ComputeStr;Exit;end;
if (BreakI=0) and (ComputeStr[1] in ['a'..'z']) then begin Result:=NotComputeStr+'a'+ComputeStr;Exit;end;
if (BreakI=0) and (ComputeStr[1] in ['A'..'Z']) then begin Result:=NotComputeStr+'A'+ComputeStr;Exit;end;
//*)
end;
if (not SeparatorBeforeNotCompute) and (FixLength) and (LetterNotCompute) then
begin
//(*
for I:=SerialNumberLength downto 1 do
begin
if SerialNumber in ['0'..'9'] then
begin
if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='0';
end;
BreakI:=I;
end;
if (BreakI=0) then begin Result:='';Exit;end;
//*)
end;
if (not SeparatorBeforeNotCompute) and (FixLength) and (not LetterNotCompute) then
begin
//(*
for I:=SerialNumberLength downto 1 do
begin
if SerialNumber in ['0'..'9'] then
begin
if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='0';
end;
if SerialNumber in ['a'..'z'] then
begin
if (SerialNumber<'z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='a';
end;
if SerialNumber in ['A'..'Z'] then
begin
if (SerialNumber<'Z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=SerialNumber;Exit;end
else SerialNumber:='A';
end;
BreakI:=I;
end;
if (BreakI=0) then begin Result:='';Exit;end;
//*)
end;
if (not SeparatorBeforeNotCompute) and (not FixLength) and (LetterNotCompute) then
begin
//(*
if (HeadNumberIndex=-1) or (LastNumberIndex=-1) then begin Result:='';Exit;end;
NumberBeforeStr:=Copy(SerialNumber,1,LastNumberIndex-1);
NumberBehindStr:=Copy(SerialNumber,1,SerialNumberLength-HeadNumberIndex);
ComputeStr:=Copy(SerialNumber,SerialNumberLength-HeadNumberIndex+1,HeadNumberIndex-LastNumberIndex+1));
//if (ComputeStr='') then begin Result:='';Exit;end;
FormatComputeStr:=IntToStr(StrToInt(ComputeStr)+1);
//FormatComputeStr:=StringOfChar('0',Length(ComputeStr)-Length(FormatComputeStr))+FormatComputeStr;//这一行比较奇怪,没有Result也出警告
Result:=NumberBeforeStr+FormatComputeStr+NumberBehindStr;
Exit;
//*)
end;
if (not SeparatorBeforeNotCompute) and (not FixLength) and (not LetterNotCompute) then
begin
//(*
//for I:=Length(SerialNumber) downto 1 do
begin
//if SerialNumber in ['0'..'9'] then
begin
//if (SerialNumber<'9') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=NotComputeStr+SerialNumber;Exit;end
//else SerialNumber:='0';
end;
//if SerialNumber in ['a'..'z'] then
begin
//if (SerialNumber<'z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=NotComputeStr+SerialNumber;Exit;end
//else SerialNumber:='a';
end;
//if SerialNumber in ['A'..'Z'] then
begin
//if (SerialNumber<'Z') then begin SerialNumber:=Chr(Ord(SerialNumber)+1);Result:=NotComputeStr+SerialNumber;Exit;end
//else SerialNumber:='A';
end;
end;
//for I:=1 to SerialNumberLength do
begin
//if (SerialNumber in ['0'..'9']) then begin Result:=Copy(SerialNumber,1,I-1)+'1'+Copy(SerialNumber,I,SerialNumberLength-I+1);Exit;end;
//if (SerialNumber in ['a'..'z']) then begin Result:=Copy(SerialNumber,1,I-1)+'a'+Copy(SerialNumber,I,SerialNumberLength-I+1);Exit;end;
//if (SerialNumber in ['A'..'Z']) then begin Result:=Copy(SerialNumber,1,I-1)+'A'+Copy(SerialNumber,I,SerialNumberLength-I+1);Exit;end;
end;
//*)
end;
end;