谁能帮我看看哪里错了,编译不出来,这里是部分代码
function IconNum(strExt: String): Integer;
begin
if (strExt = '.mp3') or (strExt = '.wav') or (strExt = '.ogg') or (strExt = '.midi') then Result := 4
else if (strExt = '.avi') or (strExt = '.mpg') or (strExt = '.asf') or (strExt = '.wmv') or (strExt = '.mov') then Result:= 8
else if (strExt = '.jpg') or (strExt = '.bmp') or (strExt = '.gif') or (strExt = '.png') or (strExt = '.pdf') then Result:= 5
else if (strExt = '.dll') or (strExt = '.sys') or (strExt = '.vxd') or (strExt = '.cpl') then Result := 6
else if (strExt = '.ini') or (strExt = '.txt') or (strExt = '.doc') then Result := 7
else if (strExt = '.html') or (strExt = '.htm') or (strExt = '.php') then Result := 9
else if (strExt = '.exe') or (strExt = '.com') or (strExt = '.bat') or (strExt = '.scr') then Result := 3
else Result := 2;
end;
//============
//收到数据时
//============
procedure TForm1.srvrscktAClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var strData: String; strDataParse: TStringList; I: Integer; lstFileAdd: TListItem; strTemp: String;
begin
strData := Socket.ReceiveText; //读取数据
if strData[Length(strData)] = Chr(3) then begin //如果长度等于3
strData := tmpString + Copy(strData, 1, Length(strData) - 1);
tmpString := '';
end else begin //如果长度不等于3
tmpString := tmpString + strData;
Exit;
end;
if Length(strData) > 3 then begin strDataParse := TStringList.Create; Split(Copy(strData,5,Length(strData) -4),#1,strDataParse); end; //如果大于3则分割到字符串strDataParse中
case StrToIntDef(Copy(strData,1,3),0) of //如前三位为001
1: begin
lvFiles.Items.Clear;
if Length(edt1.Text) > 3 Then
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := 0;
lstFileAdd.Caption := '<..>'
end;
for I := 0 to strDataParse.Count - 1 do
begin
if strDataParse[I][1] = Chr(2) then
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := 1;
lstFileAdd.Caption := Copy(strDataParse[I],2,Length(strDataParse[I]) - 1)
end
else
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := IconNum(LowerCase(ExtractFileExt(strDataParse[I])));
lstFileAdd.Caption := strDataParse[I]
end;
end;
if lvFiles.Items[0].Caption = '<..>' then lbl1.Text := 'Status: Files Found: ' + IntToStr
(lstFiles.Items.Count - 1)
else lbl1.Text := 'Status: Files Found: ' + IntToStr(lvFiles.Items.Count);
end;
2: begin //如前三位为001
cbb1.Items.Clear;
for I := 0 to strDataParse.Count - 1 do
begin
case StrToInt(strDataParse[I][4]) of
0: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Unknown Disk');
2: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Removable Disk');
3: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Hard Disk');
4: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Network Disk');
5: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Compact Disk');
6: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - RAM Disk');
end;
end;
cbb1.Enabled := True;
end;
3,7,8,9,12,16: ShowMessage(StringReplace(Copy(strData,5,Length(strData) - 4), #1, #13#10, [rfReplaceAll, rfIgnoreCase]));
4,5: begin
I := 0;
repeat begin
inc(I, 2);
end; until strDataParse.Count = I;
end;
6: begin //如前三位为006
lvFiles.Items.Clear;
for I := 0 to strDataParse.Count - 1 do
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := IconNum(LowerCase(ExtractFileExt(strDataParse[I])));
lstFileAdd.Caption := strDataParse[I]
end;
lbl1.Text := 'Status: Files Found: ' + IntToStr(lstFiles.Items.Count);
end;
10: begin //如前三位为010,接收文件数据
srvrscktB.Active := True;
if Length(strData) > 3 then no1 := StrToInt(strDataParse[0]);
end;
11: begin
for I := 0 to strDataParse.Count - 1 do begin
end;
end;
15: begin
if Length(strCurrentKey) <> 0 Then
begin
end;
for I := 0 to strDataParse.Count - 1 do
begin
strTemp := Copy(strDataParse[I],2,Length(strDataParse[I]) - 1);
if strTemp = '' then Break;
end;
end;
end;
end;
lstFileAdd.Caption := strDataParse[I] 这里报错错误提示:
[Error] Unit1.pas(335): Undeclared identifier: 'Text'
[Error] Unit1.pas(335): Undeclared identifier: 'lstFiles'
[Error] Unit1.pas(335): Missing operator or semicolon
[Error] Unit1.pas(338): Undeclared identifier: '2'
[Error] Unit1.pas(353): Statement expected, but expression of type 'Integer' found
[Error] Unit1.pas(354): ';' expected but 'BEGIN' found
[Error] Unit1.pas(355): Undeclared identifier: 'I'
[Error] Unit1.pas(358): Undeclared identifier: 'strDataParse'
[Error] Unit1.pas(358): Missing operator or semicolon
[Error] Unit1.pas(359): '.' expected but ';' found
[Error] Unit1.pas(360): Identifier redeclared: 'Finalization'
[Error] Unit1.pas(361): Undeclared identifier: 'lvFiles'
[Error] Unit1.pas(361): Missing operator or semicolon
[Error] Unit1.pas(362): 'DO' expected but identifier 'Count' found
[Error] Unit1.pas(364): Undeclared identifier: 'lstFileAdd'
[Error] Unit1.pas(364): Missing operator or semicolon
[Error] Unit1.pas(365): Missing operator or semicolon
[Error] Unit1.pas(366): Missing operator or semicolon
[Error] Unit1.pas(368): Undeclared identifier: 'lbl1'
[Error] Unit1.pas(368): Missing operator or semicolon
[Error] Unit1.pas(368): Undeclared identifier: 'lstFiles'
[Error] Unit1.pas(368): Missing operator or semicolon
[Warning] Unit1.pas(369): Text after final 'END.' - ignored by compiler
[Hint] Unit1.pas(59): Private symbol 'FStream' declared but never used
[Hint] Unit1.pas(61): Private symbol 'strCurrentKey' declared but never used
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
function IconNum(strExt: String): Integer;
begin
if (strExt = '.mp3') or (strExt = '.wav') or (strExt = '.ogg') or (strExt = '.midi') then Result := 4
else if (strExt = '.avi') or (strExt = '.mpg') or (strExt = '.asf') or (strExt = '.wmv') or (strExt = '.mov') then Result:= 8
else if (strExt = '.jpg') or (strExt = '.bmp') or (strExt = '.gif') or (strExt = '.png') or (strExt = '.pdf') then Result:= 5
else if (strExt = '.dll') or (strExt = '.sys') or (strExt = '.vxd') or (strExt = '.cpl') then Result := 6
else if (strExt = '.ini') or (strExt = '.txt') or (strExt = '.doc') then Result := 7
else if (strExt = '.html') or (strExt = '.htm') or (strExt = '.php') then Result := 9
else if (strExt = '.exe') or (strExt = '.com') or (strExt = '.bat') or (strExt = '.scr') then Result := 3
else Result := 2;
end;
//============
//收到数据时
//============
procedure TForm1.srvrscktAClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var strData: String; strDataParse: TStringList; I: Integer; lstFileAdd: TListItem; strTemp: String;
begin
strData := Socket.ReceiveText; //读取数据
if strData[Length(strData)] = Chr(3) then begin //如果长度等于3
strData := tmpString + Copy(strData, 1, Length(strData) - 1);
tmpString := '';
end else begin //如果长度不等于3
tmpString := tmpString + strData;
Exit;
end;
if Length(strData) > 3 then begin strDataParse := TStringList.Create; Split(Copy(strData,5,Length(strData) -4),#1,strDataParse); end; //如果大于3则分割到字符串strDataParse中
case StrToIntDef(Copy(strData,1,3),0) of //如前三位为001
1: begin
lvFiles.Items.Clear;
if Length(edt1.Text) > 3 Then
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := 0;
lstFileAdd.Caption := '<..>'
end;
for I := 0 to strDataParse.Count - 1 do
begin
if strDataParse[I][1] = Chr(2) then
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := 1;
lstFileAdd.Caption := Copy(strDataParse[I],2,Length(strDataParse[I]) - 1)
end
else
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := IconNum(LowerCase(ExtractFileExt(strDataParse[I])));
lstFileAdd.Caption := strDataParse[I]
end;
end;
if lvFiles.Items[0].Caption = '<..>' then lbl1.Text := 'Status: Files Found: ' + IntToStr
(lstFiles.Items.Count - 1)
else lbl1.Text := 'Status: Files Found: ' + IntToStr(lvFiles.Items.Count);
end;
2: begin //如前三位为001
cbb1.Items.Clear;
for I := 0 to strDataParse.Count - 1 do
begin
case StrToInt(strDataParse[I][4]) of
0: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Unknown Disk');
2: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Removable Disk');
3: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Hard Disk');
4: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Network Disk');
5: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - Compact Disk');
6: cbb1.Items.Add(UpperCase(Copy(strDataParse[I],1,3)) + ' - RAM Disk');
end;
end;
cbb1.Enabled := True;
end;
3,7,8,9,12,16: ShowMessage(StringReplace(Copy(strData,5,Length(strData) - 4), #1, #13#10, [rfReplaceAll, rfIgnoreCase]));
4,5: begin
I := 0;
repeat begin
inc(I, 2);
end; until strDataParse.Count = I;
end;
6: begin //如前三位为006
lvFiles.Items.Clear;
for I := 0 to strDataParse.Count - 1 do
begin
lstFileAdd := lvFiles.Items.Add;
lstFileAdd.ImageIndex := IconNum(LowerCase(ExtractFileExt(strDataParse[I])));
lstFileAdd.Caption := strDataParse[I]
end;
lbl1.Text := 'Status: Files Found: ' + IntToStr(lstFiles.Items.Count);
end;
10: begin //如前三位为010,接收文件数据
srvrscktB.Active := True;
if Length(strData) > 3 then no1 := StrToInt(strDataParse[0]);
end;
11: begin
for I := 0 to strDataParse.Count - 1 do begin
end;
end;
15: begin
if Length(strCurrentKey) <> 0 Then
begin
end;
for I := 0 to strDataParse.Count - 1 do
begin
strTemp := Copy(strDataParse[I],2,Length(strDataParse[I]) - 1);
if strTemp = '' then Break;
end;
end;
end;
end;
lstFileAdd.Caption := strDataParse[I] 这里报错错误提示:
[Error] Unit1.pas(335): Undeclared identifier: 'Text'
[Error] Unit1.pas(335): Undeclared identifier: 'lstFiles'
[Error] Unit1.pas(335): Missing operator or semicolon
[Error] Unit1.pas(338): Undeclared identifier: '2'
[Error] Unit1.pas(353): Statement expected, but expression of type 'Integer' found
[Error] Unit1.pas(354): ';' expected but 'BEGIN' found
[Error] Unit1.pas(355): Undeclared identifier: 'I'
[Error] Unit1.pas(358): Undeclared identifier: 'strDataParse'
[Error] Unit1.pas(358): Missing operator or semicolon
[Error] Unit1.pas(359): '.' expected but ';' found
[Error] Unit1.pas(360): Identifier redeclared: 'Finalization'
[Error] Unit1.pas(361): Undeclared identifier: 'lvFiles'
[Error] Unit1.pas(361): Missing operator or semicolon
[Error] Unit1.pas(362): 'DO' expected but identifier 'Count' found
[Error] Unit1.pas(364): Undeclared identifier: 'lstFileAdd'
[Error] Unit1.pas(364): Missing operator or semicolon
[Error] Unit1.pas(365): Missing operator or semicolon
[Error] Unit1.pas(366): Missing operator or semicolon
[Error] Unit1.pas(368): Undeclared identifier: 'lbl1'
[Error] Unit1.pas(368): Missing operator or semicolon
[Error] Unit1.pas(368): Undeclared identifier: 'lstFiles'
[Error] Unit1.pas(368): Missing operator or semicolon
[Warning] Unit1.pas(369): Text after final 'END.' - ignored by compiler
[Hint] Unit1.pas(59): Private symbol 'FStream' declared but never used
[Hint] Unit1.pas(61): Private symbol 'strCurrentKey' declared but never used
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
先把示声明的变量都加上,然后再从头检查一下语法等错误,编译-查找错误-编译-查询错误 反复多次问题就没有了呵呵