如何进行变量的初始化(50分)

  • 主题发起人 主题发起人 rockythd
  • 开始时间 开始时间
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的高手来帮忙。
 
我的问题是这么解决的,可是我在delphi的讲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;
var
myexam:TMoreTest ;
implementation
uses ComServ,forms,SysUtils,dialogs;
function TMoreTest.Get_Data: WideString;
begin
Result:=myexam.fData;
end;

procedure TMoreTest.Next;
begin
showmessage('Sucess ?');
end;

procedure TMoreTest.Set_Data(const Value: WideString);
begin
fData:=myexam.Value;
end;

function TMoreTest.Get_Count: Integer;
begin
Result:=myexam.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;
initialization
myexam:=myexam.create(nil);
finalization
myexam.free;
end.
 
大家帮忙灌水!
上面的代码可以满足我得程序了 ,但是
从技术上说只能是单线程的,而且原理
也还不清楚,各位com高手指点指点啊,
 
向斑竹求救!!!
 
我已经有答案了,请求斑竹结帖
 
后退
顶部