三层结构中间层添加方法后,此方法的代码在哪里写?(50分)

  • 主题发起人 主题发起人 一成
  • 开始时间 开始时间

一成

Unregistered / Unconfirmed
GUEST, unregistred user!
我是按照李维的系统应用篇做的,第50页的那个加方法getalltables没做起来,点了菜单
Type library后,在里面加了个方法,现在要为此方法写代码,写在什么地方?
 
老大,我不是问的用什么快捷键,我想知道具体写在什么地方,就如同我问全局变量写在哪里
一样,你回答个F12,对是对,可对我来说等于没说啊
 
实现接口的类中!
 
写在远程模块中的*.pas中,系统自动对其注册申明了。
比如,有一个远程模块叫cltdata,你点了菜单Type library后,打开cltdata.pas,在其中写就可了。
 
谁能举例说明一下,比如写一个getalltable方法,写在下面代码的哪里,怎么写?

unit goodserver_TLB;
// ************************************************************************ //
// WARNING
// -------
// The types declared in this file were generated from data read from a
// Type Library. If this type library is explicitly or indirectly (via
// another type library referring to this type library) re-imported, or the
// 'Refresh' command of the Type Library Editor activated while editing the
// Type Library, the contents of this file will be regenerated and all
// manual modifications will be lost.
// ************************************************************************ //
// PASTLWTR : $Revision: 1.130 $
// File generated on 1998-1-2 3:00:57 from Type Library described below.
// ************************************************************************ //
// Type Lib: C:/Documents and Settings/zl1/Mydo
cuments/serverclient/goodserver.tlb (1)
// LIBID: {6D16BD9D-8558-4E71-851F-C7FC5C313235}
// LCID: 0
// Helpfile:
// DepndLst:
// (1) v1.0 Midas, (C:/WINNT/System32/midas.dll)
// (2) v2.0 stdole, (C:/WINNT/System32/stdole2.tlb)
// (3) v4.0 StdVCL, (C:/WINNT/System32/stdvcl40.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
interface
uses ActiveX, Classes, Graphics, Midas, StdVCL, Variants, Windows;


// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLASS_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
// TypeLibrary Major and minor versions
goodserverMajorVersion = 1;
goodserverMinorVersion = 0;
LIBID_goodserver: TGUID = '{6D16BD9D-8558-4E71-851F-C7FC5C313235}';
IID_Imyserver: TGUID = '{634B2B85-E939-4C81-8C7F-62EC9B0D5475}';
CLASS_myserver: TGUID = '{0A3784EF-BD90-4B8A-9BF5-428160B6FC36}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
Imyserver = interface;
ImyserverDisp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
myserver = Imyserver;

// *********************************************************************//
// Interface: Imyserver
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {634B2B85-E939-4C81-8C7F-62EC9B0D5475}
// *********************************************************************//
Imyserver = interface(IAppServer)
['{634B2B85-E939-4C81-8C7F-62EC9B0D5475}']
procedure getalltables(var vtables: OleVariant);
safecall;
end;

// *********************************************************************//
// DispIntf: ImyserverDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {634B2B85-E939-4C81-8C7F-62EC9B0D5475}
// *********************************************************************//
ImyserverDisp = dispinterface
['{634B2B85-E939-4C81-8C7F-62EC9B0D5475}']
procedure getalltables(var vtables: OleVariant);
dispid 1;
function AS_ApplyUpdates(const ProviderName: WideString;
Delta: OleVariant;
MaxErrors: Integer;
out ErrorCount: Integer;
var OwnerData: OleVariant): OleVariant;
dispid 20000000;
function AS_GetRecords(const ProviderName: WideString;
Count: Integer;
out RecsOut: Integer;
Options: Integer;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant): OleVariant;
dispid 20000001;
function AS_DataRequest(const ProviderName: WideString;
Data: OleVariant): OleVariant;
dispid 20000002;
function AS_GetProviderNames: OleVariant;
dispid 20000003;
function AS_GetParams(const ProviderName: WideString;
var OwnerData: OleVariant): OleVariant;
dispid 20000004;
function AS_RowRequest(const ProviderName: WideString;
Row: OleVariant;
RequestType: Integer;
var OwnerData: OleVariant): OleVariant;
dispid 20000005;
procedure AS_Execute(const ProviderName: WideString;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant);
dispid 20000006;
end;

// *********************************************************************//
// The Class Comyserver provides a Create and CreateRemote method to
// create instances of the default interface Imyserver exposed by
// the CoClass myserver. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
Comyserver = class
class function Create: Imyserver;
class function CreateRemote(const MachineName: string): Imyserver;
end;

implementation
uses ComObj;
class function Comyserver.Create: Imyserver;
begin
Result := CreateComObject(CLASS_myserver) as Imyserver;
end;

class function Comyserver.CreateRemote(const MachineName: string): Imyserver;
begin
Result := CreateRemoteComObject(MachineName, CLASS_myserver) as Imyserver;
end;

end.
 
实现代码不是写在类型库里
它写在此接口的实现类里面
skywin说的那样
如果你建立了一个远程数据模块
方法的实现就写在远程数据模块单元里面
 
据我所知,定义一个方法以后,不是自动生成吗?
 
应该写在数据模块的代码窗口中,只要你保存了,它会自动出来的。
 
我是在type library中定义的方法,可打开源码并没有看到自动生成的方法代码,应该在哪个表
单里面出现,比如我新建的远程数据模块为myserver,那这代码是自动在myserver表单中出现吗?
如果手动添加的话是不是加在myserver表单中,是不是跟定义过程一样,在public 中定义
procedure viewalltable;
请高手指点
 
上次,我不是说的很清楚吗?
1、在type library中定义的方法后,要按refresh Imp...更新,然后最就再MYserver.pas中找到方式的系统定义,在相应的位置输入代码就OK。
2、还不行,请见代码。
unit srvdata;//srvdata.pas
interface
uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, srvwh9_TLB,forms, StdVcl, DBTables, Db,IniFileS, Provider;
type
Tclssrv = class(TRemoteDataModule, Iclssrv)
whdb: TDatabase;
Ses1: TSession;
Qpub: TQuery;
Qent_kind: TQuery;
Qgoodslist: TQuery;
Qmater: TQuery;
Qkcolor: TQuery;
Qunit: TQuery;
Qpurch: TQuery;
spget_goods_list: TStoredProc;
Qgdgd: TQuery;
Qmat_dbd: TQuery;
Qmat_dbds: TQuery;
Qgoods_dg: TQuery;
Qord_b: TQuery;
Qmat_dord: TQuery;
spgoods_in: TStoredProc;
Qdg_mat: TQuery;
Qgdgd_odr: TQuery;
Qmat_issize: TQuery;
Qclass: TQuery;
QPgetmat: TQuery;
Qstock: TQuery;
spcorder_std: TStoredProc;
QPrenew: TQuery;
Qtotal_mat: TQuery;
spstock_out: TStoredProc;
Qfill_mat: TQuery;
QBmat_k: TQuery;
QBmat_lk: TQuery;
Qgoods_v: TQuery;
Qccheck_stock_n_v: TQuery;
spysrkd1: TStoredProc;
spcjudge_check: TStoredProc;
spccheck_stock: TStoredProc;
spcheck_cancel: TStoredProc;
spcday_mat_outin: TStoredProc;
Qstock_mat: TQuery;
spmat_inoutlist: TStoredProc;
spcstock_list: TStoredProc;
spcorder_mat: TStoredProc;
spcprim_mat: TStoredProc;
spstock_min_mat: TStoredProc;
spcexc_mat: TStoredProc;
sppurch_exit: TStoredProc;
spcxhpdzb: TStoredProc;
spcdepartcount: TStoredProc;
spcdeplete_in_out: TStoredProc;
spcheck_pay: TStoredProc;
spcdeplete_count: TStoredProc;
Qoutbill: TQuery;
Qdg_outord: TQuery;
Qdg_cmat: TQuery;
Qoutbill_v: TQuery;
Qgoods_list_vw: TQuery;
Qorder_stock: TQuery;
QCorder_stock: TQuery;
spother_stock: TStoredProc;
Qdg_stcok_vw: TQuery;
Qchldmat: TQuery;
spprud_check: TStoredProc;
spmat_check_ent: TStoredProc;
Qissysobjects: TQuery;
Qmat_order: TQuery;
spdelmat_order: TStoredProc;
Qpurch_mat: TQuery;
Qgoods: TQuery;
Qdg_ord: TQuery;
spcstock_in: TStoredProc;
spcheck_list: TStoredProc;
Qstocksum: TQuery;
Qout_dg: TQuery;
Qdg_mmat: TQuery;
spbillmat_stock: TStoredProc;
Ppub: TDataSetProvider;
Pkuser: TDataSetProvider;
Pmat_dbds: TDataSetProvider;
Pdg_cmat: TDataSetProvider;
qkuserlst: TQuery;
Qkoprec: TQuery;
Qkoprecautoid: TAutoIncField;
Qkoprecrq: TDateTimeField;
Qkoprecxq: TStringField;
Qkoprecuser_name: TStringField;
Qkoprecenter: TDateTimeField;
Qkoprecoperation: TStringField;
Qkoprecquit: TDateTimeField;
Qkuser: TQuery;
Qart_size: TQuery;
Qout_kind: TQuery;
Qstk_min: TQuery;
Part_size: TDataSetProvider;
pkuserlst: TDataSetProvider;
Pkoprec: TDataSetProvider;
pout_kind: TDataSetProvider;
pent_kind: TDataSetProvider;
pstk_min: TDataSetProvider;
poutbill: TDataSetProvider;
ppurch: TDataSetProvider;
pgoodslist: TDataSetProvider;
Pmat_dbd: TDataSetProvider;
Pcalss: TDataSetProvider;
Pstock: TDataSetProvider;
PBmat_k: TDataSetProvider;
Pord_b: TDataSetProvider;
Pstock_mat: TDataSetProvider;
pissysobjects: TDataSetProvider;
Pgoods: TDataSetProvider;
pday_mat_outin: TDataSetProvider;
Pmat_inoutlist: TDataSetProvider;
Pdepartcount: TDataSetProvider;
Pxhpdzb: TDataSetProvider;
pheck_pay: TDataSetProvider;
Pstock_list: TDataSetProvider;
Pcorder_stock: TDataSetProvider;
Pother_stock: TDataSetProvider;
pdg_stcok_vw: TDataSetProvider;
Pcexc_mat: TDataSetProvider;
Pstock_min_mat: TDataSetProvider;
Ppurch_exit: TDataSetProvider;
Pcdeplete_count: TDataSetProvider;
Pchldmat: TDataSetProvider;
Pdg_mat: TDataSetProvider;
Pdg_ord: TDataSetProvider;
Pdg_outord: TDataSetProvider;
Pfill_mat: TDataSetProvider;
Pgdgd_odr: TDataSetProvider;
Pgoods_list_vw: TDataSetProvider;
Pkcolor: TDataSetProvider;
Pmat_dord: TDataSetProvider;
Pmat_issize: TDataSetProvider;
Pmat_order: TDataSetProvider;
Pmater: TDataSetProvider;
Porder_stock: TDataSetProvider;
Pout_dg: TDataSetProvider;
Poutbill_v: TDataSetProvider;
PPrenew: TDataSetProvider;
Ppurch_mat: TDataSetProvider;
Pstocksum: TDataSetProvider;
Ptotal_mat: TDataSetProvider;
Punit: TDataSetProvider;
Ppbillmat_stock: TDataSetProvider;
Ppccheck_stock: TDataSetProvider;
Ppcdeplete_count: TDataSetProvider;
Ppcdeplete_in_out: TDataSetProvider;
Pgdgd: TDataSetProvider;
Ppcheck_cancel: TDataSetProvider;
Ppcjudge_check: TDataSetProvider;
Ppcheck_list: TDataSetProvider;
Ppcorder_mat: TDataSetProvider;
Ppcorder_std: TDataSetProvider;
Ppcprim_mat: TDataSetProvider;
Ppcstock_in: TDataSetProvider;
Ppdelmat_order: TDataSetProvider;
Ppget_goods_list: TDataSetProvider;
Ppgoods_in: TDataSetProvider;
Ppmat_check_ent: TDataSetProvider;
Ppstock_min_mat: TDataSetProvider;
Ppprud_check: TDataSetProvider;
Ppstock_out: TDataSetProvider;
Ppysrkd1: TDataSetProvider;
Pdg_mmat: TDataSetProvider;
Qmatermatcolor_no: TStringField;
Qmatermat_no: TStringField;
Qmatermat_nm: TStringField;
Qmateremat_nm: TStringField;
Qmaterrules: TStringField;
Qmatererules: TStringField;
Qmatercolor_no: TStringField;
Qmaterpur_unit: TStringField;
Qmaterunit: TStringField;
Qmaterprice: TFloatField;
Qmaterstk_min: TFloatField;
Qmaterl_kind: TStringField;
Qmaters_kind: TStringField;
Qmaterunit_rate: TFloatField;
Qmaterdays: TIntegerField;
Qmaterstk_no: TStringField;
Qmaterposin: TStringField;
Qmaterissize: TBooleanField;
Qmaterisfty: TBooleanField;
Qmaterisparent: TBooleanField;
Qmaterisinrate: TBooleanField;
Qmatersize: TStringField;
Qmaterunitage: TFloatField;
Pgetmat: TDataSetProvider;
Udg_cmat: TUpdateSQL;
Uchldmat: TUpdateSQL;
Ugdgd: TUpdateSQL;
Umat_order: TUpdateSQL;
Pgoods_v: TDataSetProvider;
Pccheck_stock_n_v: TDataSetProvider;
Upspurch_mat: TUpdateSQL;
Qsys_menu: TQuery;
Psys_menu: TDataSetProvider;
Qsysloguser: TQuery;
Psysloguser: TDataSetProvider;
procedure clssrvCreate(Sender: TObject);
procedure clssrvDestroy(Sender: TObject);
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
[red] procedure update(const sqlstr: WideString);
safecall;//这是我定义的两个方式,update,select,更新后,系统自动生成
procedure select(const SQLStr: WideString;
out Data: OleVariant);
safecall;
public[/red] { Public declarations }
end;

implementation
{$R *.DFM}
class procedure Tclssrv.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;

[red]procedure Tclssrv.update(const sqlstr: WideString);
begin
Qpub.Close;
Qpub.SQL.Clear;
Qpub.SQL.Add(SQLStr);
Qpub.ExecSQL;
end;
[/red]
procedure Tclssrv.clssrvCreate(Sender: TObject);
var srvini: TIniFile;
srvstrs: TStrings;
exepath:String;
begin

exepath:=ExtractFilePath(Application.ExeName);
srvini := TIniFile.Create(Pchar(exepath+'config.ini'));
srvstrs := TStringList.Create ;
srvini.ReadSectionValues('Server Config',srvstrs);
If trim(srvstrs.Values['SERVER NAME']) <> '' then
begin
If whdb.Connected =True then
whdb.Connected:=false;
whdb.Params.Values['SERVER NAME'] := srvstrs.Values['Server Name'] ;
whdb.Params.Values['DATABASE NAME'] := srvstrs.Values['DATABASE NAME'] ;
end;

SrvIni.Free;
srvstrs.Free ;
end;

[red]procedure Tclssrv.select(const SQLStr: WideString;
out Data: OleVariant);
begin
Qpub.SQL.Text := SQLStr;
Data :=ppub.Data;
end;
[/red]
procedure Tclssrv.clssrvDestroy(Sender: TObject);
begin
whdb.Connected:=False;
end;

initialization
TComponentFactory.Create(ComServer, Tclssrv,
Class_clssrv, ciMultiInstance, tmApartment);
end.

明白了吧。
 
不好意思,有几个别字,方法而不是方式。应该都明白吧。远程模块中的代码中。你刚学吧,还会VF吧。。。
 
接受答案了.
 
后退
顶部