![]() |
VBScript in Delphi einbinden oder umwandeln
Hallo,
bin nicht so bewandert in der Programierung deshalb brauch ich mal Eure Hilfe. Kann mir einer sahen wie ich folgenden VBScript in Delhi einbinde oder umwandeln kann das er in Delphi funktioniert. Der Code soll die P-touch SDK zum Labelprinter ansprechen leider gibt es kein Delphi Beispiel und von VB hab ich keine Ahnung. Vielen Dank - Frank ---- ' Data Folder Const sDataFolder = "C:\Program Files\Brother bPAC SDK\Templates\" '************************************************* ******* ' Get file path from the list '************************************************* ******* Public Function GetFilePath() As String Dim strPath As String Dim nIndex As Integer nIndex = cbTemplate.ListIndex If (nIndex = 0) Then strPath = "NamePlate1.LBL" Else strPath = "NamePlate2.LBL" End If GetFilePath = sDataFolder & strPath End Function '************************************************* ******* ' Open and Print(Export) a spcified file. '************************************************* ******* Public Sub DoPrint(strPath As String, strExport As String) 'Dim ObjDoc As BrssCom.Document Dim ObjDoc As Object Set ObjDoc = CreateObject("BrssCom.Document") If (ObjDoc.Open(strPath) <> False) Then Dim nIndex As Integer nIndex = ObjDoc.GetTextIndex("Company") ObjDoc.SetText nIndex, edPosition.Text nIndex = ObjDoc.GetTextIndex("Name") ObjDoc.SetText nIndex, edName.Text If (strExport = "") Then ObjDoc.DoPrint 0, "0" ' Print Else ObjDoc.Export 2, strExport, 180 ' Export End If End If Set ObjDoc = Nothing End Sub ' Exit Private Sub btnExit_Click() Unload Me End Sub Private Sub btnPrint_Click() DoPrint GetFilePath(), "" End Sub Private Sub Form_Load() cbTemplate.ListIndex = 0 ' Head End Sub ---------------- |
Re: VBScript in Delphi einbinden oder umwandeln
Das ist eigentlich nicht schwer.
In VB-Script verwendet man doppelte Anführungszeichen; in Delphi nur einfache Hochkomma. Zuweisung in Delphi geht mit := ; in VB-Script nur ein einfaches =-Zeichen. Das kann man ganz mechanisch übersetzen. Hier ein Teilauschnitt
Code:
und hier die Übersetzung
' VB-Script
Dim ObjDoc As Object Set ObjDoc = CreateObject("BrssCom.Document") ... ObjDoc.Export 2, strExport, 180 ' Export
Delphi-Quellcode:
// Delphi
var ObjDoc : OleVariant; begin ObjDoc := CreateOleObject('BrssCom.Document'); ... ObjDoc.Export(2, strExport, 180); // Export |
Re: VBScript in Delphi einbinden oder umwandeln
Vielen Dank, dann werd ich mal versuchen das ganze in Delphi zu konvertieren.
|
Re: VBScript in Delphi einbinden oder umwandeln
Zitat:
|
Re: VBScript in Delphi einbinden oder umwandeln
Zitat:
Fehler beim Compilieren? Wie sieht dein übersetzter Teil aus? |
Re: VBScript in Delphi einbinden oder umwandeln
Da ich nicht der crack bin hab ich das erstmal soweit auskommentiert, das der compiler mir das ganze überhaupt übersetzt. funktioniert mit dem compileren aber das programm dank meiner unwissenheit nicht.
hab mal wieder zu viel weggelassen. :( ich hoffe du kannst mir helfen. ---cut----- unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComObj; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; Const sDataFolder = 'D:\apps\Brother bPAC SDK\Templates\'; implementation {$R *.dfm} { '************************************************* ******* ' Get file path from the list '************************************************* ******* Public Function GetFilePath() As String Dim strPath As String Dim nIndex As Integer nIndex = cbTemplate.ListIndex If (nIndex = 0) Then strPath = 'NamePlate1.LBL' Else strPath = 'NamePlate2.LBL' End If GetFilePath = sDataFolder & strPath End Function } //'************************************************* ******* //' Open and Print(Export) a spcified file. //'************************************************* ******* procedure TForm1.Button1Click(Sender: TObject); var strPath, strExport :string; ObjDoc : OleVariant; nindex : integer; begin strExport := 'BcdItem.lbl'; // Dim ObjDoc As BrssCom.Document ObjDoc := CreateOleObject('BrssCom.Document'); nIndex := ObjDoc.GetTextIndex('Company'); // ObjDoc.SetText nIndex, edPosition.Text; nIndex := ObjDoc.GetTextIndex('Name'); // ObjDoc.SetText nIndex, edName.Text; ObjDoc.Export(2, strExport, 180); // Export // cbTemplate.ListIndex := 0; end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:08 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz