delphi7 cosesoft打印源代码

时间:2013-12-08 18:16:40
【文件属性】:

文件名称:delphi7 cosesoft打印源代码

文件大小:7KB

文件格式:PAS

更新时间:2013-12-08 18:16:40

cosesoft打印源代码

unit CodeSoft; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, DdeMan, ComObj, stdctrls, IniFiles; type TDMCodeSoft = class(TDataModule) CSDdeClientConv: TDdeClientConv; procedure DataModuleCreate(Sender: TObject); procedure DataModuleDestroy(Sender: TObject); private M_sOldFileName : String; M_slCSParam : TStringList; function csFileName(psFileName: String): String; procedure csSet(psFieldName,psFieldValue: String); procedure listVar; procedure closeLink; procedure startLink; public procedure CSFullScreen; procedure CSLockScreen; function printToCodeSoft(psLabelFile:string; piLabelQty:integer; plsListBoxItem,plsListBoxData:TObject):Boolean; end; var DMCodeSoft: TDMCodeSoft; implementation {$R *.DFM} function TDMCodeSoft.printToCodeSoft(psLabelFile:string; piLabelQty:integer; plsListBoxItem, plsListBoxData:TObject):Boolean; var i : integer; begin if not FileExists(psLabelFile) then begin showmessage('error!-The Label file ' + psLabelFile+' can''t be found.'); Result := False; exit; end; Result := True; try if M_sOldFileName <> psLabelFile then begin if M_sOldFileName <> '' then begin while True do begin if not CSDdeClientConv.WaitStat then begin CSDdeClientConv.ExecuteMacro(PChar('[CloseLab('+csFileName(M_sOldFileName)+')]'),False); Break; end; end; end; while True do begin if not CSDdeClientConv.WaitStat then begin CSDdeClientConv.ExecuteMacro(PChar('[OpenLab('+csFileName(psLabelFile)+')]'),False); M_sOldFileName := psLabelFile; Break; end; end; end; listVar; for i := 1 to M_slCSParam.Count do begin if (plsListBoxItem as TListBox).Items.IndexOf(M_slCSParam[i-1]) <> -1 then begin csSet((plsListBoxItem as TListBox).Items[i-1],'"'+ (plsListBoxData as TListBox).Items[(plsListBoxItem as TListBox).Items.IndexOf(M_slCSParam[i-1])]+'"'); end; end; while True do begin if not CSDdeClientConv.WaitStat then begin CSDdeClientConv.ExecuteMacro(PChar('[PrintLabel('+IntToStr(piLabelQty)+')]'),False); Break; end; end; while True do begin if not CSDdeClientConv.WaitStat then begin CSDdeClientConv.ExecuteMacro(PChar('[FormFeed()]'),False); Break; end; end; except end; end; procedure TDMCodeSoft.CSFullScreen; begin while True do begin if not CSDdeClientConv.WaitStat then begin CSDdeClientConv.ExecuteMacro(PChar('[Display(F)]'),False); Break; end; Sleep(500); end; end; procedure TDMCodeSoft.CSLockScreen; begin while True do begin if not CSDdeClientConv.WaitStat then begin CSDdeClientConv.ExecuteMacro(PChar('[Display(K)]'),False); Break; end; Sleep(500); end; end; procedure TDMCodeSoft.closeLink; begin CSDdeClientConv.PokeData('Close','1'); CSDdeClientConv.CloseLink; end; function TDMCodeSoft.csFileName(psFileName: String): String; var sFileNameTemp: String; iCount: Integer; begin for iCount := 1 to Length(psFileName) do begin case psFileName[iCount] of '\': sFileNameTemp := sFileNameTemp + '\\'; '[': sFileNameTemp := sFileNameTemp + '\['; ']': sFileNameTemp := sFileNameTemp + '\]'; '"': sFileNameTemp := sFileNameTemp + '\"'; ',': sFileNameTemp := sFileNameTemp + '\,'; '(': sFileNameTemp := sFileNameTemp + '\('; ')': sFileNameTemp := sFileNameTemp + '\)'; else sFileNameTemp := sFileNameTemp + psFileName[iCount]; end; end; Result := sFileNameTemp; end; procedure TDMCodeSoft.csSet(psFieldName,psFieldValue: String); begin while True do if not CSDdeClientConv.WaitStat then begin CSDdeClientConv.ExecuteMacro(PChar('[Set('+psFieldName+','+psFieldValue+')]'),False); Break; end; end; procedure TDMCodeSoft.listVar; var sTextTemp, sText: String; iCount: Integer; begin sTextTemp := ''; sText := ''; M_slCSParam.Clear; while True do begin if not CSDdeClientConv.WaitStat then begin sTextTemp := StrPas(CSDdeClientConv.RequestData('VARLIST')); Break; end; end; for iCount := 1 to Length(sTextTemp) do begin if sTextTemp[iCount] = ';' then begin M_slCSParam.Add(sText); sText := ''; end else sText := sText + sTextTemp[iCount]; end; if sText <> '' then M_slCSParam.Add(sText); end; procedure TDMCodeSoft.startLink; var WinINI, CSINI: TIniFile; CSPath, CSEXE: String; begin WinINI := TIniFile.Create('Win.INI'); try CSPath := WinINI.ReadString('CS','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('CS4DMX','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('ELTPLUS','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('LSPRO','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('CSRUN','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('DMXRUN','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('ELTRUN','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('LSRUN','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('LWISE','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('LWRUN','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('IPAL','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('IPALRUN','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('IMPULS','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('IMPRUN','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('VITA','Path',''); if CSPath = '' then CSPath := WinINI.ReadString('VITARUN','Path',''); finally WinINI.Free; end; if CSPath = '' then begin MessageDLG('Please install Code soft!!',mtError,[mbOK],0); Application.Terminate; end; CSINI := TIniFile.Create(CSPath+'\CS.INI'); try CSEXE := CSINI.ReadString('General','ExeName',''); finally CSINI.Free; end; CSDdeClientConv.ServiceApplication := CSPath+'\'+CSEXE; CSDdeClientConv.SetLink('CS','CS'); while True do begin if CSDdeClientConv.OpenLink then Break; CSDdeClientConv.ServiceApplication := ''; sleep(500); end; end; procedure TDMCodeSoft.DataModuleCreate(Sender: TObject); begin startLink; CSLockScreen; M_slCSParam := TStringList.Create; end; procedure TDMCodeSoft.DataModuleDestroy(Sender: TObject); begin M_slCSParam.Free; closeLink; end; end.


网友评论

  • 代码没啥用