兄弟遇到一个比较郁闷的问题,我的一个控件在VB中能够正常使用,但在DELPHI中就出问题,在VB中可以正常打开并打印文件,但在DELPHI中就不行。具体代码如下:
VB:
Dim tc As New soFrmTemplateConnectionPrivate Sub Command1_Click()
Dim printerx As PrinterSet printerx = Printers(0)
SuperForm1.PrintOutPages printerx.hDC, 1, 1, "", 3End SubPrivate Sub Form_Load()
tc.DatabaseType = scfdAccess
tc.Database = "c:\sample.mdb"
If tc.IsExist Then
SuperForm1.TemplateConnection = tc
SuperForm1.TemplateConnection.OpenConnection
Dim formName As soFrmStrings
Set formName = SuperForm1.TemplateConnection.FormNames
SuperForm1.OpenForm formName.Items(1)
SuperForm1.ViewActualSize
Set formName = Nothing
End If
End SubPrivate Sub Form_Unload(Cancel As Integer)
Set tc = Nothing
End SubDELPHI:var
Form1: TForm1; tc: soFrmTemplateConnection;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var strname:string;
begin
tc:=cosoFrmTemplateConnection.Create;
tc.DatabaseType := scfdAccess;
tc.Database :='c:\sample.mdb';
SuperForm1.TemplateConnection := tc;
SuperForm1.TemplateConnection.OpenConnection;
strname:=superform1.TemplateConnection.FormNames.Items[1];
superform1.OpenForm(strname);
superform1.Refresh;
tc:=nil;end;
procedure TForm1.Button2Click(Sender: TObject);
var
print:tprinter;begin
try
print:=tprinter.Create;
print.PrinterIndex :=0;
superform1.PrintOutPages(print.Handle,1,1,'',3);
print:=nil;
except
print:=nil;
end;end;end.
VB:
Dim tc As New soFrmTemplateConnectionPrivate Sub Command1_Click()
Dim printerx As PrinterSet printerx = Printers(0)
SuperForm1.PrintOutPages printerx.hDC, 1, 1, "", 3End SubPrivate Sub Form_Load()
tc.DatabaseType = scfdAccess
tc.Database = "c:\sample.mdb"
If tc.IsExist Then
SuperForm1.TemplateConnection = tc
SuperForm1.TemplateConnection.OpenConnection
Dim formName As soFrmStrings
Set formName = SuperForm1.TemplateConnection.FormNames
SuperForm1.OpenForm formName.Items(1)
SuperForm1.ViewActualSize
Set formName = Nothing
End If
End SubPrivate Sub Form_Unload(Cancel As Integer)
Set tc = Nothing
End SubDELPHI:var
Form1: TForm1; tc: soFrmTemplateConnection;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var strname:string;
begin
tc:=cosoFrmTemplateConnection.Create;
tc.DatabaseType := scfdAccess;
tc.Database :='c:\sample.mdb';
SuperForm1.TemplateConnection := tc;
SuperForm1.TemplateConnection.OpenConnection;
strname:=superform1.TemplateConnection.FormNames.Items[1];
superform1.OpenForm(strname);
superform1.Refresh;
tc:=nil;end;
procedure TForm1.Button2Click(Sender: TObject);
var
print:tprinter;begin
try
print:=tprinter.Create;
print.PrinterIndex :=0;
superform1.PrintOutPages(print.Handle,1,1,'',3);
print:=nil;
except
print:=nil;
end;end;end.
解决方案 »
- ★★★VCL 支持Unicode 假如你是Delphi工程师★★★
- TWebBrowse加载一个网页之后, 希望用户在点击网页中某一链接时, 就打开一个from, 这个不知如何实现?
- 小问题一个,在线等待,马上结帐!!!!!
- 使用query添加sql语句插入非字符数据使用动态参数出现类型不匹配
- DBedit的关键值怎么处理?
- 如何把Query,Table,Adoconnection的密码提示去掉
- 1stclass 3000控件安装好了,怎么设置才能实现那种Outlook的效果?
- 用Delphi播放Flash的问题...
- 如何检测网络中某台机器是关机状态?
- 这么简单的SQL为何会出现error creating cursor handle?
- 一个网络的问题(新手咋到)
- 关于在对串口编程的问题
或者将Print.handle换成Print.Canvas.Handle试试在不行的话,将控件所有方法和属性的前面加上ControlInterface,例如:
SuperForm1.TemplateConnection 换成 SuperForm1.ControlInterface.TemplateConnection
var strname:string;
begin
tc:=cosoFrmTemplateConnection.Create;
tc.DatabaseType := scfdAccess;
tc.Database :='c:\sample.mdb';
SuperForm1.TemplateConnection := tc;
SuperForm1.TemplateConnection.OpenConnection;
strname:=superform1.TemplateConnection.FormNames.Items[1];
superform1.OpenForm(strname);
superform1.Refresh;
// tc:=nil;end;
procedure TForm1.Button2Click(Sender: TObject);
var
print:tprinter;begin
try
print:=tprinter.Create;
print.PrinterIndex :=0;
superform1.PrintOutPages(print.Handle,1,1,'',3);
//print:=nil;
except
print:=nil;
end;end;end.