兄弟遇到一个比较郁闷的问题,我的一个控件在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.

解决方案 »

  1.   

    SuperForm1.ViewActualSize可以用superform1.Refresh代替吗
    或者将Print.handle换成Print.Canvas.Handle试试在不行的话,将控件所有方法和属性的前面加上ControlInterface,例如:
    SuperForm1.TemplateConnection 换成 SuperForm1.ControlInterface.TemplateConnection
      

  2.   

    ViewActualSize和Refresh是可以替换的!你说的方法我试一下
      

  3.   

    我试了一下,和以前一样!不知道VC编写的控件为什么在VB和DELPHI中使用有什么区别。
      

  4.   

    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.
      

  5.   

    我遇到过这样的问题,是VB下用的好好的PINg.ocx,在DELPHI装入后,不会显示的控件面板上