哪位能帮我看看代码,有点麻烦。(100分)

  • 主题发起人 主题发起人 yname
  • 开始时间 开始时间
Y

yname

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个简单的MTS程序,然而客户端运行时发生错误,“Invalid variant operation”,
不知道问题出在哪里,代码如下:

server端:
===========================================================================
unit crm_scr;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComServ, ComObj, VCLCom, StdVcl, bdemts, DataBkr, DBClient,
MtsRdm, Mtx, crmmts_TLB, Provider, DB, ADODB;

type
Tcrm = class(TMtsDataModule, Icrm)
conn: TADOConnection;
crmrs: TADODataSet;
prov1: TDataSetProvider;
procedure MtsDataModuleCreate(Sender: TObject);
procedure MtsDataModuleDeactivate(Sender: TObject);
private
ferr_msg : string;
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
function Get_checklogin(const username, password: WideString): WordBool;
safecall;
function Get_err_msg: WideString; safecall;
public
{ Public declarations }
end;

var
crm: Tcrm;

implementation

{$R *.DFM}

class procedure Tcrm.UpdateRegistry(Register: Boolean; const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;

procedure Tcrm.MtsDataModuleCreate(Sender: TObject);
begin
conn.Connected:=true;
ferr_msg := '';
end;

procedure Tcrm.MtsDataModuleDeactivate(Sender: TObject);
begin
conn.Connected:=false;
end;

function Tcrm.Get_checklogin(const username,
password: WideString): WordBool;
begin
if crmrs.Active then crmrs.Close;
crmrs.Parameters[0].Value := username;
crmrs.Open;
if crmrs.Eof then
begin
ferr_msg := '用户名错误。';
crmrs.Close;
result := false;
exit;
end
else
begin
//if crmrs.Active then crmrs.Close;
if crmrs.Fields[2].AsString <> password then
begin
ferr_msg := '密码错误。';
crmrs.Close;
result := false;
exit;
end
else
begin
result := true;
end;
end;
end;

function Tcrm.Get_err_msg: WideString;
begin
result := ferr_msg;
end;

initialization
TComponentFactory.Create(ComServer, Tcrm,
Class_crm, ciMultiInstance, tmApartment);
end.


client端:
====================================================================

unit crm_client_scr;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
DCOMConnection1: TDCOMConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if DCOMConnection1.AppServer.checklogin(edit1.Text,edit2.Text) then
showmessage('登录成功')
else
showmessage(DCOMConnection1.AppServer.err_mag);
end;

end.

 
数据表内有三个字段:
1、int
2、varchr
3、varchr
表内有一条纪录
 
后退
顶部