关于线程取数据的问题?(50分)

  • 主题发起人 主题发起人 jxhdy2001
  • 开始时间 开始时间
J

jxhdy2001

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个程序,按下查询时,创建一个线程来取数据,这样程序看起来就不会像死掉了一样
但当程序执行ClientDataSet1.open;出错提示是:Variant is not and array
接着又出现:Error Reading from Socket的错误?
请各位帮忙解决!
 
Variant is not and array
-an
是不是应该用数组?
 
ClientDataSet多线程取数据是要Marshal接口的
 
to shiningplus:
能不能说详细点,或给个例子,谢谢
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, StdCtrls, Grids, DBGrids,ComObj,ActiveX
,Provider,Midas;
type
TOpenThread = class(TThread)
private
FCDS: TClientDataSet;
FStream: Pointer;
FNewData:OleVariant;
protected
procedure Execute;
override;
procedure UpdateCDS;
public
constructor Create(CDS: TClientDataSet);
end;

TForm1 = class(TForm)
DCOMConnection1: TDCOMConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
{ TOpenThread }

constructor TOpenThread.Create(CDS: TClientDataSet);
begin
FreeOnTerminate := True;
FCDS := CDS;
OleCheck(CoMarshalInterThreadInterfaceInStream(
IID_IAppServer,
FCDS.AppServer,
IStream(FStream)));
inherited Create(False);
end;

procedure TOpenThread.Execute;
var
OwnerData: OleVariant;
RecsOut: Integer;
Params:OleVariant;
Appserver:IAppserver;
begin
OleCheck(CoInitialize(nil));
try
OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IID_IAppServer,
Appserver));
FNewData :=
AppServer.AS_GetRecords (FCDS.ProviderName,
-1,RecsOut,MetaDataOption,'',Params,OwnerData);
Synchronize(UpdateCDS);
finally
CoUninitialize;
end;
end;

procedure TOpenThread.UpdateCDS;
begin
FCDS.AppendData(FNewData,True);
Form1.DataSource1.DataSet:=FCDS;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
TOpenThread.Create(ClientDataSet1);
end;

end.

delphi7下成功运行,delphi5下把uses中的Variants去掉
 
谢谢ShiningPlus!
问题解决了,但有些代码看帮助有些吃力,如果你有空的话,可不可以给我解释一下,谢谢!
下面这句是什么意思?
OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IID_IAppServer,Appserver));
 
谢谢参与
 
OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IID_IAppServer,Appserver));

是容错的处理..
 
后退
顶部