各位高手: 请教如何将这段VB代码用Delphi实现? (200分)

  • 主题发起人 主题发起人 sundayone
  • 开始时间 开始时间
S

sundayone

Unregistered / Unconfirmed
GUEST, unregistred user!
Public Sub Main()
Dim oPackage As DTS.Package
Dim oStep As DTS.Step
Dim oTask As DTS.Task
Dim oCustTask As DTS.ExecutePackageTask

Set oPackage = New DTS.Package

'Create step and task, link step to task.
Set oStep = oPackage.Steps.New
oStep.Name = "ExecPkgStep"
Set oTask = oPackage.Tasks.New("DTSExecutePackageTask")
[red]Set oCustTask = oTask.CustomTask[/red]
[blue] // 这行代码在delphi中我用
// oCustTask := ExecutePackageTask(oTask.CustomTask);
// 运行时在oPackage.Execute处出现内存非法访问错误!
// ExecutePackageTask 是DTSpkg.dll中定义的一接口类型
// 其他行代码转换都没问题,我该如何做? 请指教 谢谢! [/blue]
oCustTask.Name = "ExecPkgTask"
oStep.TaskName = oCustTask.Name
oPackage.Steps.Add oStep
Set oStep = Nothing

'Specify package to be run.
oCustTask.PackagePassword = "user"
oCustTask.FileName = "C:/DTS_UE/TestPkg/VarPubsFields.dts"

'Link task to package, run package.
oPackage.Tasks.Add oTask
Set oCustTask = Nothing
Set oTask = Nothing
[red]oPackage.Execute[/red]
Set oPackage = Nothing
End Sub

 
procedure TForm1.Button1Click(Sender: TObject);
var
opackage :Tpackage;
ostep :step;
otask :Task;
ocustTask:Executepackagetask;
begin
opackage :=Tpackage.Create(self);
ostep:=opackage.Steps.New;

ostep.Name :='Execpkgstep';
otask :=opackage.Tasks.New('DTSExecutePackageTask');
ocusttask:= otask.CustomTask as Executepackagetask;
ocusttask.Name :='ExecPkgTask';
ostep.TaskName :=ocusttask.Name ;
opackage.Steps.Add(ostep);
oStep:=nil;


ocusttask.FileName :='dts_a.dts';
opackage.Tasks.Add(otask);
ocusttask:=nil;
otask :=nil;
[red]opackage.Execute ;[/red]
[blue]
// 运行到这时出现内存访问错误!
[/blue]
opackage.Free;


end;

end.
 
我已经解决问题了![:)] 原来应该是这样
procedure TForm1.Button1Click(Sender: TObject);
var opackage: _package;
ostep :step;
otask :task;
ocusttask :executepackagetask;
begin
opackage:=CreateOleObject('DTS.Package') as _package;
ostep:=opackage.steps.new;
ostep.name:='execpkgstep';
otask:=opackage.tasks.new('dtsexecutepackagetask');
ocusttask:=otask.customtask as executepackagetask;
ocusttask.name:='execpkgtask';
ostep.taskname:=ocusttask.name;
opackage.steps.add(ostep);
ostep:=nil;
ocusttask.filename:='dts_a11.dts';
opackage.tasks.add(otask);
otask:=nil;
opackage.execute;
opackage.UnInitialize;
end;
 
接受答案了.
 
用Tpackage控件该怎么解决呢
 
晚了,原来已经解决。
 
to sundayone:
看在我们都姓sun的份上,发一份用delphi调用dts的例子给我吧,我已经为此苦恼了将近一年了
谢谢先
 
兄弟朋友,能否给一份Delphi调用dts的例子给,要此不胜感激,
小的急用,
shanluo@msc.com
 
To sundayone:
以直接调用_package来代替TDTSPackage,似乎是绕过问题,到底为什么会出现内存冲突,
是DTS类型库在Delphi中调用的内在缺陷吗?
但若用_package则无法取用在包执行过程中触发的事件(OnError/OnProgress......),挺遗憾的。
是否有兴趣继续研究这个问题?
 
兄弟们,也给一份DELPHI调用DTS的例子吧,谢谢
 
兄弟们,也给一份DELPHI调用DTS的例子吧,谢谢 ,Email: gyn1981@263.net
 
后退
顶部