客户端如下:
procedure TForm1.Button1Click(Sender: TObject);
var
zxs: array[1..10] of string;
zxsOle:OleVariant;
tempPointer:Pointer;
begin
zxs[1]:='江苏';
zxs[2]:='浙江';
zxs[3]:='安徽';
zxs[4]:='河北';
zxs[5]:='山西';
zxs[6]:='内蒙';
zxs[7]:='辽林';
zxs[8]:='吉林';
zxs[9]:='黑龙江';
zxs[10]:='福建';
zxsOle := VarArrayCreate([0,sizeof(zxs)],varByte);
tempPointer := VarArrayLock(zxsOle);
Move(zxs,tempPointer^,sizeof(zxs));
VarArrayUnLock(zxsOle);
ecook.Method1('12345',zxsOle);
end;
服务端接收如下:
procedure Tinsertobj.Method1(const vdatas: WideString; Param2: OleVariant);
var
js: array[1..10] of string;
begin
js[1]:=param2[1];
js[2]:=param2[2];
with adoquery1 do
begin
sql.Clear;
sql.Add('insert into nj_xm (xmmc,dldw) values(');
sql.Add(''''+vdatas+''''+',');
sql.Add(''''+js[2]+''''+')');
adoquery1.ExecSQL;
showmessage('ok');
end;
end;
执行不报错,一切正常,也显示'ok'的提示消息,可是数据库就是没有插入记录.
procedure TForm1.Button1Click(Sender: TObject);
var
zxs: array[1..10] of string;
zxsOle:OleVariant;
tempPointer:Pointer;
begin
zxs[1]:='江苏';
zxs[2]:='浙江';
zxs[3]:='安徽';
zxs[4]:='河北';
zxs[5]:='山西';
zxs[6]:='内蒙';
zxs[7]:='辽林';
zxs[8]:='吉林';
zxs[9]:='黑龙江';
zxs[10]:='福建';
zxsOle := VarArrayCreate([0,sizeof(zxs)],varByte);
tempPointer := VarArrayLock(zxsOle);
Move(zxs,tempPointer^,sizeof(zxs));
VarArrayUnLock(zxsOle);
ecook.Method1('12345',zxsOle);
end;
服务端接收如下:
procedure Tinsertobj.Method1(const vdatas: WideString; Param2: OleVariant);
var
js: array[1..10] of string;
begin
js[1]:=param2[1];
js[2]:=param2[2];
with adoquery1 do
begin
sql.Clear;
sql.Add('insert into nj_xm (xmmc,dldw) values(');
sql.Add(''''+vdatas+''''+',');
sql.Add(''''+js[2]+''''+')');
adoquery1.ExecSQL;
showmessage('ok');
end;
end;
执行不报错,一切正常,也显示'ok'的提示消息,可是数据库就是没有插入记录.
解决方案 »
- File not found: 'IdExplicitTLSClientServerBase.dcu'
- fastreport 将null值显示为0的问题
- 关于ACCESS+DELPHI的数据库连接问题
- 求登录代码
- 我的机子是CII667 主板是intel810的我原来有一个128MB的内存,现在想加一个128MB或是256MB的,是应该尽应该买pc133还是pc100的?另外价格
- vcl 组件开发高级技术
- 这样的功能如何实现
- 非常感谢
- 哪里有一些数据库程序的例子可以下载?
- 天津的delphi的爱好者们来看一下!
- 从接触计算机到现在的几个难忘时刻~希望与大家共享美好程序人生!
- 怎么建一*.ini文件或文本文件
如果ecook为服务器端的COM服务器名的话,则应该还需要有个DCOMConnection或SocketConnection
则应改为
DCOMConnection1.ecook.Method1('12345',zxsOle);
或
SocketConnection1.ecook.Method1('12345',zxsOle);
如果ecook为DCOMConnection或SocketConnection的话,假设服务器端的COM服务器名为AppServer
则应改为
ecook.AppServer.Method1('12345',zxsOle);
ecook已经在active中申明
if not Assigned(eCook) then
eCook := Coinsertobj.Create;
实在不忍心看你徘徊在数组的困境中啦,如果你不担心XML的效率问题,下面给你一个封装的COM,用XML来传递数组吧,二维的。
unit unitArrayWithXML;{$WARN SYMBOL_PLATFORM OFF}interfaceuses
ComObj, ActiveX, ArrayWithXML_TLB, StdVcl,XMLDoc, XMLIntf,
xmldom, msxmldom, Classes;type
TArrayWithXML = class(TAutoObject, IArrayWithXML)
private
Owner:TComponent;
myxmldoc:Txmldocument;
myxmlNode:Ixmlnode;
insertnode:Ixmlnode;
protected
procedure Add(const fieldName, fieldValue: WideString); safecall;
procedure GetByIndex(index: Integer; out fieldName,
fieldValue: WideString); safecall;
function GetByFieldName(const fieldName: WideString): WideString; safecall;
procedure SetValue(const inData: WideString); safecall;
function GetValue: WideString; safecall;
function GetNodeCount: Integer; safecall;
procedure Clear; safecall;
{ Protected declarations }
public
procedure Initialize;override;
destructor Destroy;override;
end;implementationuses ComServ, SysUtils;procedure TArrayWithXML.Add(const fieldName, fieldValue: WideString);
begin
try
self.insertnode := self.myxmlNode.AddChild(LowerCase(fieldName));
self.insertnode.Text := LowerCase(fieldValue);
except
raise exception.Create('Error in Add to XML!向XML添加数据错误!');
end;
end;procedure TArrayWithXML.GetByIndex(index: Integer; out fieldName,
fieldValue: WideString);
begin
try
self.insertnode := self.myxmlNode.ChildNodes.Get(index);
fieldName := self.insertnode.NodeName;
fieldValue := self.insertnode.NodeValue;
except
raise exception.Create('Error in GetByIndex!从XML中读数据错误!');
end;
end;function TArrayWithXML.GetByFieldName(
const fieldName: WideString): WideString;
begin
result := self.myxmlNode.ChildNodes[LowerCase(fieldName)].Text;
end;procedure TArrayWithXML.SetValue(const inData: WideString);
begin
try
self.myxmldoc.Active := false;
self.myxmldoc.XML.Text := inData;
self.myxmldoc.Active := true;
myxmlnode := myxmldoc.DocumentElement;
except
raise exception.Create('Error in SetValue!给XML赋值错误!');
end;
end;function TArrayWithXML.GetValue: WideString;
begin
result := self.myxmldoc.XML.Text;
end;function TArrayWithXML.GetNodeCount: Integer;
begin
result := myxmlnode.ChildNodes.Count;
end;destructor TArrayWithXML.Destroy;
begin
Owner.Free;
inherited;
end;procedure TArrayWithXML.Initialize;
begin
inherited;
Owner := TComponent.Create(nil);
self.myxmldoc := Txmldocument.Create(self.Owner);
with myxmldoc.XML do
begin
add('<?xml version="1.0" encoding="gb2312"?>');
add('<VariantArray></VariantArray>');
end;
myxmldoc.Active := true;
myxmlnode := myxmldoc.DocumentElement;
end;procedure TArrayWithXML.Clear;
begin
self.myxmldoc.XML.Clear;
with myxmldoc.XML do
begin
add('<?xml version="1.0" encoding="gb2312"?>');
add('<VariantArray></VariantArray>');
end;
myxmldoc.Active := true;
myxmlnode := myxmldoc.DocumentElement;
end;initialization
TAutoObjectFactory.Create(ComServer, TArrayWithXML, Class_ArrayWithXML,
ciMultiInstance, tmApartment);
end.
var
test:WideString;
arrayWithXML:IArrayWithXml;
fieldName:Widestring;
fieldValue:WideString;
begin
arrayWithXML := CoArrayWithXml.Create;
arrayWithXML.Add('Team_ID','0001');
arrayWithXML.Add('Team_Name','第一组');
arrayWithXML.Add('Team_Desc','测试XML');
arrayWithXML.Add('num','3');
test := arraywithxml.GetValue;
showmessage(test);
arraywithxml.SetValue(test);
arraywithxml.GetByIndex(1,fieldName,fieldValue);
showmessage(fieldName + ' ' + fieldValue);
test := arraywithxml.GetByFieldName('tEam_nAme');
showmessage(test);
arrayWithXML.Clear;
showmessage('第二次使用');
arrayWithXML.Add('Team_ID','0001');
arrayWithXML.Add('Team_Name','第一组');
arrayWithXML.Add('Team_Desc','测试XML');
arrayWithXML.Add('num','3');
test := arraywithxml.GetValue;
showmessage(test);
arraywithxml.SetValue(test);
arraywithxml.GetByIndex(1,fieldName,fieldValue);
showmessage(fieldName + ' ' + fieldValue);
test := arraywithxml.GetByFieldName('tEam_nAme');
showmessage(test);
arraywithxml := nil;
end;关于用Move的方法,看这张帖子吧。
http://expert.csdn.net/Expert/topic/1358/1358091.xml?temp=.8021967