服务器代码:(作用:返回并更新最大的单号)
unit _CMUpdate_;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComServ, ComObj, VCLCom, StdVcl, bdemts, DataBkr, DBClient,
MtsRdm, Mtx, CMCommenPrj_TLB, DB, ADODB, _GLAppCommon_, Provider;
type
TCMUpdate = class(TMtsDataModule, ICMUpdate)
ADOConnection1: TADOConnection;
Query: TADOQuery;
procedure MtsDataModuleCreate(Sender: TObject);
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
procedure GetNewVoucherNo(Type_: OleVariant;
out No_: OleVariant);
safecall;
public
{ Public declarations }
end;
var
CMUpdate: TCMUpdate;
implementation
{$R *.DFM}
class procedure TCMUpdate.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 TCMUpdate.GetNewVoucherNo(Type_: OleVariant;
out No_: OleVariant);
var
S_Type: string;
begin
Query.SQL.Text := 'select S_Type, S_Last_No from Last_No where S_Type = ''' + string(Type_) +
''' ';
Query.Open;
S_Type := Query.FieldByName('S_Type').AsString;
No_ := Query.FieldByName('S_Last_No').AsInteger;
No_ := No_ + 1;
Query.Close;
if S_Type = '' then
begin
No_ := 1;
Query.SQL.Text :=
' insert into Last_No ' +
' ( S_Type, S_Last_No ) ' +
' values ( ''' + string(Type_) + ''' , 1 ) ';
Query.ExecSQL;
end
else
begin
Query.SQL.Text :=
' update Last_No ' +
' set S_Last_No = S_Last_No + 1 ' +
' where S_Type = ''' + string(Type_) + '''';
Query.ExecSQL;
end;
SetComplete;
end;
procedure TCMUpdate.MtsDataModuleCreate(Sender: TObject);
begin
Set_ADOConnection(ADOConnection1);
//这行只是设置数据库
end;
initialization
TComponentFactory.Create(ComServer, TCMUpdate,
Class_CMUpdate, ciMultiInstance, tmApartment);
end.
------------------------
客户端代码:(UpdateSocket指向上一组件)
function TdmCommon.GetNewVoucherNo(Type_: string): Integer;
var
No_: OleVariant;
begin
UpdateSocket.AppServer.GetNewVoucherNo(OleVariant(Type_), No_);
//当过了COM+设定的事务处理时间时出错
Result := Integer(No_);
end;