with adoquery1 do
begin
close;
SQL.Clear;
str1:= 'insert into lt(name)
values('''+label3.Caption+'说:'+''')';
str2:= 'insert into lt(record)
values('''+combobox1.Text+''')';
adoquery1.SQL.Add(str1);
adoquery1.SQL.Add(str2);
ADOQuery1.ExecSQL;
end;
我想吧聊天纪录存放在lt库表里的字段里,运行时系统在这句话附近却提示:
project project1.exe raised exception class eoleexception with message
'[microsoft][odbc microsoft access driver]sql语句的结束位置缺少分号(;)。'.process stopped.use step or run to continue.想不通
begin
close;
SQL.Clear;
str1:= 'insert into lt(name)
values('''+label3.Caption+'说:'+''')';
str2:= 'insert into lt(record)
values('''+combobox1.Text+''')';
adoquery1.SQL.Add(str1);
adoquery1.SQL.Add(str2);
ADOQuery1.ExecSQL;
end;
我想吧聊天纪录存放在lt库表里的字段里,运行时系统在这句话附近却提示:
project project1.exe raised exception class eoleexception with message
'[microsoft][odbc microsoft access driver]sql语句的结束位置缺少分号(;)。'.process stopped.use step or run to continue.想不通
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, ScktComp, ImgList, ToolWin, Menus,
ShellAPI, DB, ADODB;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
N10: TMenuItem;
N11: TMenuItem;
N12: TMenuItem;
ToolBar1: TToolBar;
ImageList1: TImageList;
startbtn: TToolButton;
namebtn: TToolButton;
stopbtn: TToolButton;
aboutbtn: TToolButton;
quitbtn: TToolButton;
ServerSocket1: TServerSocket;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
RichEdit1: TRichEdit;
ListView1: TListView;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ComboBox1: TComboBox;
StatusBar1: TStatusBar;
ADOQuery1: TADOQuery;
ToolButton1: TToolButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ComboBox1Select(Sender: TObject);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure startbtnClick(Sender: TObject);
procedure namebtnClick(Sender: TObject);
procedure stopbtnClick(Sender: TObject);
procedure aboutbtnClick(Sender: TObject);
procedure quitbtnClick(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure N12Click(Sender: TObject);
procedure N10Click(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ToolButton1Click(Sender: TObject);
private
{ Private declarations }
sel_who:integer;
procedure display(msg:string);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tform1.display(msg:string);
begin
statusbar1.SimpleText:=msg;
end;
function getstring(s,mask:string;position:integer):string;
var
str:string;
i,len:integer;
begin
str:='';
for i:=0 to position-1 do
begin
if(pos(mask,s)<=0)then
begin
str:=s;
break;
end;
str:=copy(s,1,pos(mask,s)-1);
len:=length(str);
s:=copy(s,len+2,length(s)-len-1);
end;
result:=str;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
serversocket1.Active :=false;
serversocket1.Close;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
serversocket1.Active:=true;
richedit1.Lines.Add(datetostr(date)+''+timetostr(time)+'==>>'+
'yyd聊天服务器启动!');
end;
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
jj:integer;
ss:string;
str1:string;
str2:string;
begin
if (key=vk_return)and(combobox1.Text<>'')then
begin
combobox1.Items.Add(combobox1.Text);
ss:='交谈@#!^'+label3.Caption+'说:'+combobox1.Text+'^';
for jj:=0 to listview1.Items.Count-1 do
begin
serversocket1.Socket.Connections[jj].SendText(ss);//给所有客户端发送消息
end;
richedit1.Lines.Add(label3.Caption+'说:'+combobox1.Text);
combobox1.Text:='';
with adoquery1 do
begin
close;
SQL.Clear;
str1:= 'insert into lt(name) values('''+label3.Caption+'说:'+''')';
str2:= 'insert into lt(record) values('''+combobox1.Text+''')';
adoquery1.SQL.Add(str1);
adoquery1.SQL.Add(str2);
ADOQuery1.ExecSQL;
end;
end;
end;
procedure TForm1.ComboBox1Select(Sender: TObject);
var
str1:string;
str2:string;
begin
if combobox1.Text<>'' then
begin
combobox1.Items.Add(combobox1.Text);
serversocket1.Socket.Connections[sel_who].SendText('交谈@#!^'+
label3.Caption+'说:'+combobox1.Text+'^');
richedit1.Lines.Add(label3.Caption+'说:'+combobox1.Text);
combobox1.Text:='';
with adoquery1 do
begin
close;
SQL.Clear;
str1:= 'insert into lt(name) values('''+label3.Caption+'说:'+''')';
str2:= 'insert into lt(record) values('''+combobox1.Text+''')';
adoquery1.SQL.Add(str1);
adoquery1.SQL.Add(str2);
ADOQuery1.ExecSQL;
end;
end;
end;
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
if (listview1.Items.Count>0) and (listview1.SelCount>0)then
begin
sel_who:=listview1.Selected.Index;
caption:=inttostr(sel_who);
end;
end;
procedure TForm1.startbtnClick(Sender: TObject);
begin
serversocket1.Active:=true;
richedit1.Lines.Add(datetostr(date)+''+timetostr(time)+'==>>'+
'yyd聊天服务器启动!');
richedit1.Lines.Add(datetostr(date)+''+timetostr(time)+'==>>'+
'yyd聊天服务器昵称!'+label3.Caption);
end;
procedure TForm1.namebtnClick(Sender: TObject);
var
tmpstr:string;
begin
tmpstr:=inputbox('昵称输入','请输入用户昵称:','');
if tmpstr<>''then
begin
label3.Caption:=tmpstr;
richedit1.Lines.add(datetostr(date)+''+timetostr(time)+
'==>>'+'yyd聊天服务器昵称:'+label3.Caption);
end;
end;
begin
serversocket1.Active:=false;
richedit1.Lines.Add(datetostr(date)+''+timetostr(time)+'==>>'+
'yyd聊天服务器关闭!');
end;
procedure TForm1.aboutbtnClick(Sender: TObject);
begin
shellabout(handle,'yyd聊天工具',
#13+'yyd聊天工具1。0版'+
#13+'欢迎使用',0);
end;
procedure TForm1.quitbtnClick(Sender: TObject);
begin
close;
end;
procedure TForm1.N6Click(Sender: TObject);
begin
serversocket1.Active:=true;
richedit1.Lines.add(datetostr(date)+''+timetostr(time)+
'==>>'+'yyd聊天服务器启动:'+label3.Caption);
richedit1.Lines.add(datetostr(date)+''+timetostr(time)+
'==>>'+'yyd聊天服务器昵称:'+label3.Caption);
end;
procedure TForm1.N5Click(Sender: TObject);
begin
serversocket1.Active:=false;
richedit1.Lines.add(datetostr(date)+''+timetostr(time)+
'==>>'+'yyd聊天服务器关闭:'+label3.Caption);
end;
procedure TForm1.N4Click(Sender: TObject);
var
tmpstr:string;
begin
tmpstr:=inputbox('昵称输入','请输入用户昵称:','');
if tmpstr<>''then
begin
label3.Caption:=tmpstr;
richedit1.Lines.add(datetostr(date)+''+timetostr(time)+
'==>>'+'yyd聊天服务器昵称:'+label3.Caption);
end;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.N11Click(Sender: TObject);
begin
shellexecute(handle,nil,'帮助.txt',nil ,
nil,sw_normal);
end;
procedure TForm1.N12Click(Sender: TObject);
begin
shellabout(handle,'yyd聊天工具',#13+'yyd聊天工具1。0版'+#13
+'欢迎使用!',0);
end;
procedure TForm1.N10Click(Sender: TObject);
begin
shellexecute(handle,nil,'mailto:[email protected]',nil,
nil,sw_normal);
end;
procedure TForm1.N9Click(Sender: TObject);
begin
shellexecute(handle,nil,'http://my.mop.com/yydyyd33',nil,
nil,sw_normal);
end;
procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
var
newitem:tlistitem;
ii,jj:integer;
user,usercur:string;
begin
newitem:=listview1.Items.Insert(listview1.Items.Count);
newitem.Caption:='client:'+inttostr(listview1.Items.Count);
newitem.SubItems.add(socket.RemoteHost);
newitem.SubItems.Add(socket.RemoteAddress);
newitem.SubItems.Add(inttostr(socket.RemotePort));
listview1.AlphaSort();
listview1.Items.Item[listview1.Items.Count-1].Selected:=true;
display('连接到主机:'+socket.RemoteAddress+'成功');
ii:=listview1.Itemindex;
richedit1.Lines.Add(datetostr(date)+''+timetostr(time)+'==>>'
+listview1.Items[ii].Caption+'加入进来!');
//这个字符串相加,从下面的for循环中独立出来,不必每循环一次就加一次
user := listview1.Items[ii].Caption + '^' +
listview1.Items[ii].SubItems[0] + '^'
+ listview1.Items[ii].SubItems[1] + '^'
+ listview1.Items[ii].SubItems[2];
//通知所有聊天的人,有新的人进来
for jj := 0 to listview1.Items.Count - 1 do
begin
serversocket1.Socket.Connections[jj].SendText('增加用户@#!^' +
user + '^');
end;
//把已经在线的用户列表,通知给刚加入的用户
for jj := 0 to listview1.Items.Count - 2 do
begin
user := listview1.Items[jj].Caption + '^' +
listview1.Items[jj].SubItems[0] + '^'
+ listview1.Items[jj].SubItems[1] + '^'
+ listview1.Items[jj].SubItems[2];
serversocket1.Socket.Connections[ii].SendText('增加用户@#!^' +user + '^');
end;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
var
ii,jj:integer;
user:string;
begin
for ii:=0 to listview1.Items.Count-1 do
begin
if listview1.Items.Item[ii].SubItems.Strings[2]=
inttostr(socket.RemotePort)then
begin
for jj:=0 to listview1.Items.Count-1 do
begin
user:=listview1.Items[ii].Caption+'^'+
listview1.Items[ii].SubItems[0]+'^'
+listview1.Items[ii].SubItems[1]+'^'
+listview1.Items[ii].SubItems[2];
serversocket1.Socket.Connections[jj].SendText('删除用户@#!^'
+user+'^') ;
end;
richedit1.Lines.add(datetostr(date)+''+timetostr(time)+
'==>>'+listview1.Items[ii].Caption+'走了!');;
listview1.Items.Item[ii].Delete();
display(socket.RemoteHost+'走了');
end;
end;
if listview1.Items.Count=0 then
begin
display('获取信息......');
end;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
tmpstr,user:string;
ii,jj:integer;
listitem:tlistitem;
exist:bool;
begin
exist:=false;
tmpstr:=socket.ReceiveText;
if getstring(tmpstr,'^',1)='交谈@#!'then
begin
for jj:=0 to listview1.Items.Count-1 do
begin
user:=getstring(tmpstr,'^',2);
serversocket1.Socket.Connections[jj].SendText('交谈@#!^'+user+'^');
end;
richedit1.Lines.Add(getstring(tmpstr,'^',2));
end;
if getstring(tmpstr,'^',1)='昵称@#!'then
begin
for ii:=0 to listview1.Items.Count-1 do
begin
if socket.RemotePort=strtoint(listview1.Items[ii].SubItems[2])
then
begin
exist:=true;
if getstring(tmpstr,'^',2)<>listview1.Items[ii].Caption
then
begin
richedit1.Lines.Add(datetostr(date)+''+timetostr(time)+
'==>>'+listview1.Items[ii].Caption+'更名为'+
getstring(tmpstr,'^',2));
listview1.Items[ii].Caption:=getstring(tmpstr,'^',2);
for jj:=0 to listview1.Items.Count-1 do
begin
user:=listview1.Items[ii].Caption+'^'+
listview1.Items[ii].SubItems[0]+'^'
+listview1.Items[ii].SubItems[1]+'^'
+listview1.Items[ii].SubItems[2];
serversocket1.Socket.Connections[jj].SendText(
'昵称@#!^'+user+'^') ;
end;
end;
end;
end;
end;
end;
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
application.Terminate;
end;
end.
str1:= 'insert into lt(name) values('+QuotedStr(label3.Caption+'说:')+')';
str2:= 'insert into lt(record) values('+QuotedStr(combobox1.Text)+')';另外,你这是增加了两条记录.如果放在一条记录里,可以这样:
str:= 'insert into lt(name,record) values('+QuotedStr(label3.Caption+'说:')+','+QuotedStr(combobox1.Text)+')';
程序太长,没有看你在楼上两层发的代码
Shift: TShiftState);
这个方法,多了一个END , 你从该方法的最后删掉一个END试试.
str:= 'insert into lt'+#13#10+
'(name,record,date)'+#13#10+
' values('''+label3.Caption+'说:'+''','''+combobox1.Text+''','''+datetostr(date)+''')';
这么换行系统也报错???
project project1.exe raised exception class eoleexception with message
'[microsoft][odbc microsoft access driver]sql语句的结束位置缺少分号(;)。'.process stopped.use step or run to continue.想不通 ]问题已解决,现在问的是str:= 'insert into lt'+#13#10+
'(name,record,date)'+#13#10+
' values('''+label3.Caption+'说:'+''','''+combobox1.Text+''','''+datetostr(date)+''')';
这么换行系统也报错??? 嘿嘿
'(name,record,date)'+#13#10+
' values('+QuotedStr(label3.Caption+'说:')+','+QuotedStr(combobox1.Text)+','+QuotedStr(FormatDateTime('yyyy-mm-dd',date))+')';
adocommand1.CommandText :='INSERT INTO lt(name,record,date)VALUES(:name,:record,:date)';
adocommand1.Parameters.ParamByName('name').Value := '一个人';
adocommand1.Parameters.ParamByName('record').Value := '说了句话';
adocommand1.Parameters.ParamByName('date').Value := now());
adocommand1.Execute;按这种格式'yyyy-mm-dd'表示日期,可以不用格式化日期
begin
close;
SQL.Clear;
str1:= 'insert into lt(name)
values('''+label3.Caption+'说:'+''')' go;
str2:= 'insert into lt(record)
values('''+combobox1.Text+''')';
adoquery1.SQL.Add(str1);
adoquery1.SQL.Add(str2);
ADOQuery1.ExecSQL;
project project1.exe raised exception class eoleexception with message
'[microsoft][odbc microsoft access driver]sql语句的结束位置缺少分号(;)。'.process stopped.use step or run to continue.想不通 ]问题已解决,现在问的是str:= 'insert into lt'+#13#10+
'(name,record,date)'+#13#10+
' values('''+label3.Caption+'说:'+''','''+combobox1.Text+''','''+datetostr(date)+''')';
这么换行系统也报错??? 嘿嘿]我在楼上发的新帖子,对于由此给大家带来的不便我感到很抱歉