W
wlmmlw
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, StdCtrls, Grids, DBGrids,ComObj,ActiveX
,Provider,Midas, SConnect;
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)
DCOMConnection2: TDCOMConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
DCOMConnection1: TSocketConnection;
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);
var
thrd: TOpenThread;
begin
ClientDataSet1.CommandText := 'SELECT * FROM TObj';
ClientDataSet1.Active := true;
thrd := TOpenThread.Create(ClientDataSet1);
WaitForSingleObject(thrd.Handle, INFINITE);
Caption := 'Finish';
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, StdCtrls, Grids, DBGrids,ComObj,ActiveX
,Provider,Midas, SConnect;
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)
DCOMConnection2: TDCOMConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
DCOMConnection1: TSocketConnection;
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);
var
thrd: TOpenThread;
begin
ClientDataSet1.CommandText := 'SELECT * FROM TObj';
ClientDataSet1.Active := true;
thrd := TOpenThread.Create(ClientDataSet1);
WaitForSingleObject(thrd.Handle, INFINITE);
Caption := 'Finish';
end;
end.