R
rockythd
Unregistered / Unconfirmed
GUEST, unregistred user!
本人刚刚开始学习自动化编程,试着做了一个com的Dll 其
实现单元的简化代码如下:
unit server;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, serverprj_TLB, StdVcl,Classes,ADODB;
type
TMoreTest = class(TAutoObject, IMoreTest)
private
fFilterType:integer;
ChipID:integer;
fCount:integer;
fData:Widestring;
Chips:Tstrings;
fDBPath:WideString;
fADOQuery:TADOQuery;
protected
function Get_Data: WideString; safecall;
procedure Next; safecall;
procedure Set_Data(const Value: WideString); safecall;
function Get_Count: Integer; safecall;
public
constructor Create(Owner: TComponent);
destructor Destroy; override;
end;
implementation
uses ComServ,forms,SysUtils,dialogs;
function TMoreTest.Get_Data: WideString;
begin
Result:=fData;
end;
procedure TMoreTest.Next;
begin
showmessage('Sucess ?');
end;
procedure TMoreTest.Set_Data(const Value: WideString);
begin
fData:=Value;
end;
function TMoreTest.Get_Count: Integer;
begin
Result:=fCount;
end;
constructor TMoreTest.Create(Owner: TComponent);
begin
Chips:=TStringlist.Create;
fDBPath := ExtractFilePath(Application.ExeName) ;
fADOQuery:=TADOQuery.Create(nil);
showmessage('Create Sucess ?');
fCount:=-1; // 无法取得该值
chipId:=-1;
fFilterType :=12;
end;
程序可以运行,也有结果,单构造函数好像没有执行.无法进行私有变量的初始化,
知道为什么,希望精通COM的高手来帮忙。
实现单元的简化代码如下:
unit server;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, serverprj_TLB, StdVcl,Classes,ADODB;
type
TMoreTest = class(TAutoObject, IMoreTest)
private
fFilterType:integer;
ChipID:integer;
fCount:integer;
fData:Widestring;
Chips:Tstrings;
fDBPath:WideString;
fADOQuery:TADOQuery;
protected
function Get_Data: WideString; safecall;
procedure Next; safecall;
procedure Set_Data(const Value: WideString); safecall;
function Get_Count: Integer; safecall;
public
constructor Create(Owner: TComponent);
destructor Destroy; override;
end;
implementation
uses ComServ,forms,SysUtils,dialogs;
function TMoreTest.Get_Data: WideString;
begin
Result:=fData;
end;
procedure TMoreTest.Next;
begin
showmessage('Sucess ?');
end;
procedure TMoreTest.Set_Data(const Value: WideString);
begin
fData:=Value;
end;
function TMoreTest.Get_Count: Integer;
begin
Result:=fCount;
end;
constructor TMoreTest.Create(Owner: TComponent);
begin
Chips:=TStringlist.Create;
fDBPath := ExtractFilePath(Application.ExeName) ;
fADOQuery:=TADOQuery.Create(nil);
showmessage('Create Sucess ?');
fCount:=-1; // 无法取得该值
chipId:=-1;
fFilterType :=12;
end;
程序可以运行,也有结果,单构造函数好像没有执行.无法进行私有变量的初始化,
知道为什么,希望精通COM的高手来帮忙。