H
hejiesi
Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个Automation Object 使得可以在html页面中用javascript创建这个对象然后由这个
对象遍历一个文件夹中的文件然后返回一个列表, 其中有下面的一个过程
procedure TFileList.ListFolderFile(const Dir: WideString;
out FileList: OleVariant);
var
slFileList: TStringList;
i: integer;
rgsabound: array[0..1] of SAFEARRAYBOUND;
psa: PSafeArray;
ele: OleVariant;
ix: LongInt;
begin
slFileList := TStringList.Create;
for i := 0 to 10 do
begin
slFileList.Add(Dir + inttostr(i));
end;
rgsabound[0].lLbound := 0;
rgsabound[0].cElements := slFileList.Count;
psa := SafeArrayCreate(VT_VARIANT, 1, rgsabound);
for i := 0 to slFileList.Count - 1 do
begin
ix := i;
ele := WideString(slFileList);
SafeArrayPutElement(psa, ix, ele);
end;
TVarData(FileList).VType := VT_VARIANT or VT_ARRAY or VT_BYREF;
TVarData(FileList).VArray := @psa;
slFileList.Free;
end;
这样写对不对,
然后我在一个程序中写了以下代码访问这个Com对象
procedure TForm1.Button1Click(Sender: TObject);
var
FServer: IFileList;
FileList: array[0..100] of string;
oleVar: OleVariant;
rgsabound: array[0..1] of SAFEARRAYBOUND;
psa: PSafeArray;
ele: OleVariant;
ix: LongInt;
pp: pointer;
v: OleVariant;
begin
rgsabound[0].lLbound := 0;
rgsabound[0].cElements := 100;
psa := SafeArrayCreate(VT_VARIANT, 1, rgsabound);
TVarData(oleVar).VType := VT_VARIANT or VT_ARRAY or VT_BYREF;
TVarData(oleVar).VArray := @psa;
//pp := VarArrayLock(oleVar);
FServer := CoFileList.Create;
FServer.ListFolderFile('e:/data', oleVar);
FServer := nil;
//VarArrayUnlock(oleVar);
//showmessage(FileList[1]);
end;
但是怎样写也出错应该怎样写?
对象遍历一个文件夹中的文件然后返回一个列表, 其中有下面的一个过程
procedure TFileList.ListFolderFile(const Dir: WideString;
out FileList: OleVariant);
var
slFileList: TStringList;
i: integer;
rgsabound: array[0..1] of SAFEARRAYBOUND;
psa: PSafeArray;
ele: OleVariant;
ix: LongInt;
begin
slFileList := TStringList.Create;
for i := 0 to 10 do
begin
slFileList.Add(Dir + inttostr(i));
end;
rgsabound[0].lLbound := 0;
rgsabound[0].cElements := slFileList.Count;
psa := SafeArrayCreate(VT_VARIANT, 1, rgsabound);
for i := 0 to slFileList.Count - 1 do
begin
ix := i;
ele := WideString(slFileList);
SafeArrayPutElement(psa, ix, ele);
end;
TVarData(FileList).VType := VT_VARIANT or VT_ARRAY or VT_BYREF;
TVarData(FileList).VArray := @psa;
slFileList.Free;
end;
这样写对不对,
然后我在一个程序中写了以下代码访问这个Com对象
procedure TForm1.Button1Click(Sender: TObject);
var
FServer: IFileList;
FileList: array[0..100] of string;
oleVar: OleVariant;
rgsabound: array[0..1] of SAFEARRAYBOUND;
psa: PSafeArray;
ele: OleVariant;
ix: LongInt;
pp: pointer;
v: OleVariant;
begin
rgsabound[0].lLbound := 0;
rgsabound[0].cElements := 100;
psa := SafeArrayCreate(VT_VARIANT, 1, rgsabound);
TVarData(oleVar).VType := VT_VARIANT or VT_ARRAY or VT_BYREF;
TVarData(oleVar).VArray := @psa;
//pp := VarArrayLock(oleVar);
FServer := CoFileList.Create;
FServer.ListFolderFile('e:/data', oleVar);
FServer := nil;
//VarArrayUnlock(oleVar);
//showmessage(FileList[1]);
end;
但是怎样写也出错应该怎样写?