Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi VBScript in Delphi einbinden oder umwandeln (https://www.delphipraxis.net/104108-vbscript-delphi-einbinden-oder-umwandeln.html)

Stoned-6 27. Nov 2007 15:21


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

' Print
Private Sub btnPrint_Click()
DoPrint GetFilePath(), ""
End Sub

Private Sub Form_Load()
cbTemplate.ListIndex = 0 ' Head
End Sub

----------------


shmia 27. Nov 2007 15:56

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:
' VB-Script
Dim ObjDoc As Object
Set ObjDoc = CreateObject("BrssCom.Document")
...
ObjDoc.Export 2, strExport, 180 ' Export
und hier die Übersetzung
Delphi-Quellcode:
// Delphi
var
  ObjDoc : OleVariant;
begin
  ObjDoc := CreateOleObject('BrssCom.Document');
  ...
  ObjDoc.Export(2, strExport, 180); // Export

Stoned-6 27. Nov 2007 16:16

Re: VBScript in Delphi einbinden oder umwandeln
 
Vielen Dank, dann werd ich mal versuchen das ganze in Delphi zu konvertieren.

Stoned-6 23. Dez 2007 20:22

Re: VBScript in Delphi einbinden oder umwandeln
 
Zitat:

Zitat von Stoned-6
Vielen Dank, dann werd ich mal versuchen das ganze in Delphi zu konvertieren.

Funktioniert leider nicht hat jemand ein Lösung für mich???

ste_ett 23. Dez 2007 20:29

Re: VBScript in Delphi einbinden oder umwandeln
 
Zitat:

Zitat von Stoned-6
Zitat:

Zitat von Stoned-6
Vielen Dank, dann werd ich mal versuchen das ganze in Delphi zu konvertieren.

Funktioniert leider nicht hat jemand ein Lösung für mich???

Was funktioniert nicht?
Fehler beim Compilieren?

Wie sieht dein übersetzter Teil aus?

Stoned-6 23. Dez 2007 20:37

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 01:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz