Acrobat C Struct to Delphi Record - delphi
I'm attempting to utilize Adobe Acrobat OLE to optimize and compress PDFs that we take in through various internal programs. Adobe uses C for all of their documentation, and I'm having trouble converting a structure to a record in Delphi.
Referencing the SDK here:
Adobe struct:
struct _t_PDFOptParams{
ASSize_t size;
ASPathName asPathDest;
ASFileSys fileSys;
ProgressMonitor progMon;
void* progMonClientData;
PDFOptPDFVersion enmAcrobatVersion;
PDFOptImageOptionsRec imageOptionsColor;
PDFOptImageOptionsRec imageOptionsGrayscale;
PDFOptImageOptionsRec imageOptionsMonochrome;
PDFont* arrPDFontsToUnembed;
ASInt32 cPDFontsToUnembed;
PDFOptFlattenTransparencyOptions pdfOptFlattenTransparencyOptions;
ASBool bRemoveFormActions;
ASBool bFlattenFormFields;
ASBool bRemoveJavascriptActions;
ASBool bRemoveAlternateImages;
ASBool bRemoveThumbnails;
ASBool bRemoveDocumentTags;
ASBool bSmoothenLines;
ASBool bMergeImageFragments;
ASBool bRemovePrintSettings;
ASBool bRemoveSrchIndex;
ASBool bRemoveBookmarks;
ASBool bRemoveCommentsAndWidgets;
ASBool bRemoveDocInfoAndMetadata;
ASBool bRemoveObjectData;
ASBool bRemoveFileAttachments;
ASBool bRemoveCrossRefs;
ASBool bRemovePrivateData;
ASBool bFlattenVisibleLayers;
PDFOptObjectCompression enmObjectCompression;
ASBool bUnencodedToFlate;
ASBool bLZWToFlate;
ASBool bRemoveInvalidBookmarks;
ASBool bRemoveInvalidLinks;
ASBool bRemoveUnreferencedNamedDests;
ASBool bLinearize;
}PDFOptParamsRec, *PDFOptParams;
My attempt in Delphi to create a record:
type PDFParams = record
size : byte;
asPathDest : string;
//fileSys : ;
//progMon : null
//progMonClientData : null
//enmAcrobatVersion : PDFOptPDFVersion;
//imageOptionsColor
//imageOptionsGrayscale
//imageOptionsMonochrome
//arrPDFontsToUnembed
cPDFontsToUnembed :Integer;
//pdfOptFlattenTransparencyOptions
bRemoveFormactions : bool;
bFlattenFormFields : bool;
bRemoveJavascriptActions : bool;
bRemoveAlternateImages : bool;
bRemoveThumbnails : bool;
bRemoveDocumentTags : bool;
bSmoothenLines : bool;
bMergeImageFragments : bool;
bRemovePrintSettings : bool;
bRemoveSrchIndex : bool;
bRemoveBookmarks : bool;
bRemoveCommentsAndWidgets: bool;
bRemoveDocInfoAndMetadata: bool;
bRemoveObjectData : bool;
bRemoveFileAttachments : bool;
bRemoveCrossRefs : bool;
bRemovePrivateData : bool;
bFlattenVisibleLayers : bool;
//enmObjectCompression : bool;
bUnencodedToFlate : bool;
bLZWToFlate : bool;
bRemoveInvalidBookmarks : bool;
bRemoveInvalidLinks : bool;
bRemoveUnreferencedNamedDests : bool;
bLinearize : bool;
end;
I'm not sure what I should be setting the commented out fields to?
What you have translated so far is not even close to being accurate. ASSize_t is not a single byte, ASPathName is not a string, ASBool is not a bool, etc.
The PDFOptParams struct has dependencies on a LOT of other types. Based on the PDF, the definitions of those types would look something like this:
type
{ define this manually only if your Delphi version does not already provide it }
size_t = NativeUInt;
ASSize_t = size_t;
ASInt32 = Int32;
ASUns16 = UInt16;
ASBool = ASUns16;
ASDuration = ASInt32;
ASFileMode = ASUns16;
ASMDFile = Pointer;
ASErrorCode = ASInt32;
{ the following types are not documented in the PDF, so you need
to track down what they are actually defined as in the SDK and
translate them as needed... }
_t_ASPathNameRec = record
...
end;
ASPathName = ^_t_ASPathNameRec;
_t_PDFont = record
...
end;
PDFont = ^_t_PDFont;
_t_ASTextRec = record
...
end;
ASText = ^_t_ASTextRec;
{ I'm not going to translate all of the following callback types,
I'll leave that as an exercise for you to do. I've done the 1st
two for you (note: the PDF doesn't describe calling conventions
used, so if 'cdecl' doesn't work, try 'stdcall' instead)... }
ASFileSysOpenProc = function(pathName: ASPathName; mode: ASFileMode; var fP: ASMDFile): ASErrorCode; cdecl;
ASFileSysCloseProc = function(f: ASMDFile): ASErrorCode; cdecl;
ASFileSysFlushProc = ...;
ASFileSysSetPosProc = ...;
ASFileSysGetPosProc = ...;
ASFileSysSetEofProc = ...;
ASFileSysGetEofProc = ...;
ASFileSysReadProc = ...;
ASFileSysWriteProc = ...;
ASFileSysRemoveProc = ...;
ASFileSysRenameProc = ...;
ASFileSysIsSameFileProc = ...;
ASFileSysGetNameProc = ...;
ASFileSysGetTempPathNameProc = ...;
ASFileSysCopyPathNameProc = ...;
ASFileSysDiPathFromPathProc = ...;
ASFileSysPathFromDIPathProc = ...;
ASFileSysDisposePathNameProc = ...;
ASFileSysGetFileSysNameProc = ...;
ASFileSysGetStorageFreeSpaceProc = ...;
ASFileSysFlushVolumeProc = ...;
ASFileSysGetFileFlags = ...;
ASFileSysAsyncReadProc = ...;
ASFileSysAsyncWriteProc = ...;
ASFileSysAsyncAbortProc = ...;
ASFileSysYieldProc = ...;
ASFileSysMReadRequestProc = ...;
ASFileSysGetStatusProc = ...;
ASFileSysCreatePathNameProc = ...;
ASFileSysAcquireFileSysPathProc = ...;
ASFileSysClearOutstandingMReadsProc = ...;
ASFileSysGetItemPropsProc = ...;
ASFileSysFirstFolderItemProc = ...;
ASFileSysNextFolderItemProc = ...;
ASFileSysDestroyFolderIteratorProc = ...;
ASFileSysSetModeProc = ...;
ASFileSysURLFromPathProc = ...;
ASFileSysGetParentProc = ...;
ASFileSysCreateFolderProc = ...;
ASFileSysRemoveFolderProc = ...;
ASFileSysDisplayStringFromPathProc = ...;
ASFileSysSetTypeAndCreatorProc = ...;
ASFileSysGetTypeAndCreatorProc = ...;
ASFileSysReopenProc = ...;
ASFileSysHardFlushProc = ...;
ASFileSysGetPlatformThingProc = ...;
ASFileSysGetItemPropsAsCabProc = ...;
ASFileSysCanPerformOpOnItemProc = ...;
ASFileSysPerformOpOnItemProc = ...;
ASFileSysAcquirePlatformPathProc = ...;
ASFileSysReleasePlatformPathProc = ...;
ASFileSysGetNameAsASTextProc = ...;
ASFileSysDisplayASTextFromPathProc = ...;
ASFileSysRangeArrivedProc = ...;
ASFileSysCanSetEofProc = ...;
ASFileSysDIPathFromPathExProc = ...;
ASFileSysPathFromDIPathExProc = ...;
ASFileSysGetFilePositionLimitProc = ...;
ASFileSysOpen64Proc = ...;
ASFileSysSetPos64Proc = ...;
ASFileSysGetPos64Proc = ...;
ASFileSysSetEof64Proc = ...;
ASFileSysGetEof64Proc = ...;
ASFileSysGetNameForDisplayProc = ...;
ASFileSysGetStorageFreeSpace64Proc = ...;
_t_ASFileSysRec = record
size: ASSize_t;
open: ASFileSysOpenProc;
close: ASFileSysCloseProc;
flush: ASFileSysFlushProc;
setpos: ASFileSysSetPosProc;
getpos: ASFileSysGetPosProc;
seteof: ASFileSysSetEofProc;
geteof: ASFileSysGetEofProc;
read: ASFileSysReadProc;
write: ASFileSysWriteProc;
remove: ASFileSysRemoveProc;
rename: ASFileSysRenameProc;
isSameFile: ASFileSysIsSameFileProc;
getName: ASFileSysGetNameProc;
getTempPathName: ASFileSysGetTempPathNameProc;
copyPathName: ASFileSysCopyPathNameProc;
diPathFromPath: ASFileSysDiPathFromPathProc;
pathFromDIPath: ASFileSysPathFromDIPathProc;
disposePathName: ASFileSysDisposePathNameProc;
getFileSysName: ASFileSysGetFileSysNameProc;
getStorageFreeSpace: ASFileSysGetStorageFreeSpaceProc;
flushVolume: ASFileSysFlushVolumeProc;
getFileFlags: ASFileSysGetFileFlags;
readAsync: ASFileSysAsyncReadProc;
writeAsync: ASFileSysAsyncWriteProc;
abortAsync: ASFileSysAsyncAbortProc;
yield: ASFileSysYieldProc;
mreadRequest: ASFileSysMReadRequestProc ;
getStatus: ASFileSysGetStatusProc;
createPathName: ASFileSysCreatePathNameProc;
acquireFileSysPath: ASFileSysAcquireFileSysPathProc;
clearOutstandingMReads: ASFileSysClearOutstandingMReadsProc;
getItemProps: ASFileSysGetItemPropsProc;
firstFolderItem: ASFileSysFirstFolderItemProc;
nextFolderItem: ASFileSysNextFolderItemProc;
destroyFolderIterator: ASFileSysDestroyFolderIteratorProc;
setFileMode: ASFileSysSetModeProc;
urlFromPath: ASFileSysURLFromPathProc;
getParent: ASFileSysGetParentProc;
createFolder: ASFileSysCreateFolderProc;
removeFolder: ASFileSysRemoveFolderProc;
displayStringFromPath: ASFileSysDisplayStringFromPathProc;
setTypeAndCreator: ASFileSysSetTypeAndCreatorProc;
getTypeAndCreator: ASFileSysGetTypeAndCreatorProc;
reopen: ASFileSysReopenProc;
hardFlush: ASFileSysHardFlushProc;
getPlatformThing: ASFileSysGetPlatformThingProc;
getItemPropsAsCab: ASFileSysGetItemPropsAsCabProc;
canPerformOpOnItem: ASFileSysCanPerformOpOnItemProc;
performOpOnItem: ASFileSysPerformOpOnItemProc;
acquirePlatformPath: ASFileSysAcquirePlatformPathProc;
releasePlatformPath: ASFileSysReleasePlatformPathProc;
getNameAsASText: ASFileSysGetNameAsASTextProc;
displayASTextFromPath: ASFileSysDisplayASTextFromPathProc;
rangeArrived: ASFileSysRangeArrivedProc;
canSetEof: ASFileSysCanSetEofProc;
diPathFromPathEx: ASFileSysDIPathFromPathExProc;
pathFromDIPathEx: ASFileSysPathFromDIPathExProc;
getfileposlimit: ASFileSysGetFilePositionLimitProc;
open64: ASFileSysOpen64Proc;
setpos64: ASFileSysSetPos64Proc;
getpos64: ASFileSysGetPos64Proc;
seteof64: ASFileSysSetEof64Proc;
geteof64: ASFileSysGetEof64Proc;
getNameForDisplay: ASFileSysGetNameForDisplayProc;
getStorageFreeSpace64: ASFileSysGetStorageFreeSpace64Proc;
end;
ASFileSysRec = _t_ASFileSysRec;
ASFileSys = ^_t_ASFileSysRec;
PMBeginOperationProc = procedure(clientData: Pointer); cdecl;
PMEndOperationProc = procedure(clientData: Pointer); cdecl;
PMSetDurationProc = procedure(duration: ASDuration; clientData: Pointer); cdecl;
PMSetCurrValueProc = procedure(currValue: ASDuration; clientData: Pointer); cdecl;
PMGetDurationProc = function(clientData: Pointer): ASDuration; cdecl;
PMGetCurrValueProc = function(clientData: Pointer): ASDuration;
PMSetTextProc = procedure(text: ASText; clientData: Pointer); cdecl;
_t_ProgressMonitor = record
size: ASSize_t;
beginOperation: PMBeginOperationProc;
endOperation: PMEndOperationProc;
setDuration: PMSetDurationProc;
setCurrValue: PMSetCurrValueProc;
getDuration: PMGetDurationProc;
getCurrValue: PMGetCurrValueProc;
setText: PMSetTextProc;
end;
ASProgressMonitorRec = _t_ProgressMonitor;
ASProgressMonitor = ^_t_ProgressMonitor;
ProgressMonitor = ASProgressMonitor;
PDFOptPDFVersion = (kPDFOptRetainVersion = 0, kPDFOptAcrobat4, kPDFOptAcrobat5, kPDFOptAcrobat6, kPDFOptAcrobat7, kPDFOptAcrobat8);
PDFOptDownsamplingAlgo = (kPDFOptNoDownsampling = 0, kPDFOptAverage, kPDFOptSubsampling, kPDFOptBicubic);
PDFOptCompressionAlgo = (kPDFOptNoRecompression = 0, kPDFOptJpeg2000, kPDFOptJpeg, kPDFOptFlate, kPDFOptJBIG2, kPDFOptCCITT3, kPDFOptCCITT4, kPDFOptRunLengh);
PDFOptCompressionQlty = (kPDFOptMinimumQlty = 0, kPDFOptLowQlty, kPDFOptMediumQlty, kPDFOptHighQlty, kPDFOptMaximumQlty, kPDFOptLossless);
_t_PDFOptImageOptions = record
size: ASSize_t;
enmDownsamplingAlgo: PDFOptDownsamplingAlgo;
ppiDownsampleTo: ASInt32;
ppiDownsampleAbove: ASInt32;
enmCompressionAlgo: PDFOptCompressionAlgo;
enmCompressionQlty: PDFOptCompressionQlty;
nTileSize: ASInt32;
end;
PDFOptImageOptionsRec = _t_PDFOptImageOptions;
PDFOptImageOptions = ^_t_PDFOptImageOptions;
_t_PDFOptFlattenTransparencyOptions = record
size: ASSize_t;
pctRasterVectorBalance,
ppiLineArtAndText,
ppiGradientAndMesh: ASInt32;
bConvertText,
bConvertStrokes,
bClipComplexRegions,
bPreserveOverprint: ASBool;
end;
PDFOptFlattenTransparencyOptionsRec = _t_PDFOptFlattenTransparencyOptions;
PDFOptFlattenTransparencyOptions = ^_t_PDFOptFlattenTransparencyOptions;
PDFOptObjectCompression = (kPDFOptUntouchedCompression = 0, kPDFOptFullCompression, kPDFOptPartialCompression, kPDFOptRemoveCompression);
_t_PDFOptParams = record
size: ASSize_t;
asPathDest: ASPathName;
fileSys: ASFileSys;
progMon: ProgressMonitor;
progMonClientData: Pointer;
enmAcrobatVersion: PDFOptPDFVersion;
imageOptionsColor,
imageOptionsGrayscale,
imageOptionsMonochrome: PDFOptImageOptionsRec;
arrPDFontsToUnembed: ^PDFont;
cPDFontsToUnembed: ASInt32;
pdfOptFlattenTransparencyOptions: PDFOptFlattenTransparencyOptions;
bRemoveFormActions,
bFlattenFormFields,
bRemoveJavascriptActions,
bRemoveAlternateImages,
bRemoveThumbnails,
bRemoveDocumentTags,
bSmoothenLines,
bMergeImageFragments,
bRemovePrintSettings,
bRemoveSrchIndex,
bRemoveBookmarks,
bRemoveCommentsAndWidgets,
bRemoveDocInfoAndMetadata,
bRemoveObjectData,
bRemoveFileAttachments,
bRemoveCrossRefs,
bRemovePrivateData,
bFlattenVisibleLayers: ASBool;
enmObjectCompression: PDFOptObjectCompression;
bUnencodedToFlate,
bLZWToFlate,
bRemoveInvalidBookmarks,
bRemoveInvalidLinks,
bRemoveUnreferencedNamedDests,
bLinearize: ASBool;
end;
PDFOptParamsRec = _t_PDFOptParams;
PDFOptParams = ^_t_PDFOptParams;
Related
How to declare a constant Tpoint?
Good morning, I am trying to declare constant TPoint in Delphi, how do you do that ? None of the following works // ... const POS_A : Tpoint = (3,3); const POS_B : Tpoint = Point(3,10); const POS_C : Tpoint = Tpoint(3,20); const POS_D : Tpoint = TPoint.create(3,30); // ... Any clue ?
According to the documentation on constants, specifically the part about records, you write const MyPoint: TPoint = (X: 3; Y: 7);
Automatically Slicing Large TIFF File with Photoshop and Save Slices into TIFF Files?
I have a TIFF file. I want to slice it automatically (specifying the number of slices in horizontal and vertical) and save them into TIFF files (I don't want to change the format to png or ...) I know that in photoshop you can choose the slice tool>>right click>>Divide Slice>>Save for web However, the "Save for web" doesn't offer saving in TIFF Format and also I don't think it can work for large file (which is the case here). Anything that can help (script, plugin) is welcome
With the help of some online codes, I created the script below which is capable of automatically slicing a big TIFF into smaller Tiff files: #target photoshop function main(){ if(!documents.length) return; var dlg= "dialog{text:'Script Interface',bounds:[100,100,380,290],"+ "panel0:Panel{bounds:[10,10,270,180] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+ "title:StaticText{bounds:[60,10,220,40] , text:'File Chop' ,properties:{scrolling:undefined,multiline:undefined}},"+ "panel1:Panel{bounds:[10,40,250,130] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+ "statictext1:StaticText{bounds:[10,10,111,30] , text:'Accross' ,properties:{scrolling:undefined,multiline:undefined}},"+ "statictext2:StaticText{bounds:[140,10,230,27] , text:'Down' ,properties:{scrolling:undefined,multiline:undefined}},"+ "across:DropDownList{bounds:[10,30,100,50]},"+ "down:DropDownList{bounds:[140,30,230,50]},"+ "saveFiles:Checkbox{bounds:[10,60,230,80] , text:'Save and Close new files?'}},"+ "button0:Button{bounds:[10,140,110,160] , text:'Ok' },"+ "button1:Button{bounds:[150,140,250,160] , text:'Cancel' }}};" var win = new Window(dlg,'File Chop'); if(version.substr(0,version.indexOf('.'))>9){ win.panel0.title.graphics.font = ScriptUI.newFont("Georgia","BOLD",20); g = win.graphics; var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [1.00, 1.00, 1.00, 1]); g.backgroundColor = myBrush; var myPen =g.newPen (g.PenType.SOLID_COLOR, [1.00, 0.00, 0.00, 1],lineWidth=1); } win.center(); for(var i=1;i<31;i++){ win.panel0.panel1.across.add ('item', i); win.panel0.panel1.down.add ('item', i); } win.panel0.panel1.across.selection=0; win.panel0.panel1.down.selection=0; var done = false; while (!done) { var x = win.show(); if (x == 0 || x == 2) { win.canceled = true; done = true; } else if (x == 1) { done = true; { if(!documents.length)return; var startRulerUnits = preferences.rulerUnits; preferences.rulerUnits = Units.PIXELS; doc = app.activeDocument; app.displayDialogs = DialogModes.NO; doc.flatten(); var tilesAcross = parseInt(win.panel0.panel1.across.selection.index)+1; var tilesDown =parseInt(win.panel0.panel1.down.selection.index)+1; var tileWidth = parseInt(doc.width/tilesAcross); var tileHeight = parseInt(doc.height/tilesDown); var SaveFiles = win.panel0.panel1.saveFiles.value; ProcessFiles(tilesDown,tilesAcross,tileWidth,tileHeight,SaveFiles); app.preferences.rulerUnits = startRulerUnits; } } } } main(); function ProcessFiles(Down,Across,offsetX,offsetY,SaveFiles){ try{ var newName = activeDocument.name.match(/(.*)\.[^\.]+$/)[1]; }catch(e){var newName="UntitledChop"} var Path=''; try{ Path = activeDocument.path; }catch(e){Path = "~/Desktop";} if(SaveFiles){ Path = Folder(decodeURI(Path) +"/FileChop"); if(!Path.exists) Path.create(); } TLX = 0; TLY = 0; TRX = offsetX; TRY = 0; BRX = offsetX; BRY = offsetY; BLX = 0; BLY = offsetY; for(var a = 0; a < Down; a++){ for(var i = 0;i <Across; i++){ var NewFileName = newName +"#"+a+"-"+i; app.activeDocument.duplicate (NewFileName, true); activeDocument.selection.select([[TLX,TLY],[TRX,TRY],[BRX,BRY],[BLX,BLY]], SelectionType.REPLACE, 0, false); executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO ); app.activeDocument.selection.deselect(); if(SaveFiles){ var saveFile = File(decodeURI(Path+"/"+NewFileName+".tiff")); SaveTIFF(saveFile); app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); } activeDocument = documents[0]; TLX = offsetX * (i+1) ; TRX = TLX + offsetX; BRX = TRX; BLX = TLX; } TLX = 0; TLY = offsetY * (a +1); TRX = offsetX; TRY = offsetY * (a +1); BRX = offsetX; BRY = TRY + offsetY; BLX = 0; BLY = (offsetY * (a +1)+offsetY); } if(SaveFiles){ Path.execute() } } function SaveTIFF(saveFile){ tiffSaveOptions = new TiffSaveOptions(); tiffSaveOptions.embedColorProfile = true; tiffSaveOptions.alphaChannels = true; tiffSaveOptions.layers = true; tiffSaveOptions.imageCompression = TIFFEncoding.NONE; activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE); }
Proper implementation of OpenPrinter2 with PRINTER_OPTION_NO_CACHE
I'm modifying some existing code which uses OpenPrinter to instead use OpenPrinter2. It contains one more parameter PPRINTER_OPTIONS which in Delphi is encapsulated as a TPrinterOptions, defined like so: _PRINTER_OPTIONSW = record cbSize: Cardinal; dwFlags: DWORD; end; I'm having trouble understanding how to use this struct to encapsulate the flag PRINTER_OPTION_NO_CACHE, and I can't even find that constant in any of the existing VCL/RTL. var PD: TPrinterDefaults; PO: TPrinterOptions; begin PO.dwFlags:= ??? if OpenPrinter2(ADevice, #FPrinterHandle, #PD, #PO) then begin ... I'm not having much luck searching for Delphi implementation of either OpenPrinter2 or TPrinterOptions. How do I make PRINTER_OPTION_NO_CACHE work? EDIT Is this correct? const PRINTER_OPTION_NO_CACHE = 0; PRINTER_OPTION_CACHE = 1; PRINTER_OPTION_CLIENT_CHANGE = 2; ... PO.dwFlags:= PRINTER_OPTION_NO_CACHE;
The MSDN docs say this: typedef enum tagPRINTER_OPTION_FLAGS { PRINTER_OPTION_NO_CACHE, PRINTER_OPTION_CACHE, PRINTER_OPTION_CLIENT_CHANGE } PRINTER_OPTION_FLAGS; A C enum, as declared here, is really just an int. The first enum value is 0, the next 1, and so on. But the header file tells a different story, contradicting the documentation. The header file says: typedef enum _PRINTER_OPTION_FLAGS { PRINTER_OPTION_NO_CACHE = 1 << 0, PRINTER_OPTION_CACHE = 1 << 1, PRINTER_OPTION_CLIENT_CHANGE = 1 << 2, PRINTER_OPTION_NO_CLIENT_DATA = 1 << 3, } PRINTER_OPTION_FLAGS; So translate to Pascal like this. const PRINTER_OPTION_NO_CACHE = 1; PRINTER_OPTION_CACHE = 2; PRINTER_OPTION_CLIENT_CHANGE = 4; PRINTER_OPTION_NO_CLIENT_DATA = 8; Populate the record like this: var Options: TPrinterOptions; .... Options.cbSize := SizeOf(Options); Options.dwFlags := PRINTER_OPTION_NO_CACHE;
First Try to SMPP Protocol (Bind Command)
i have a try to implement SMPP client , a first test is do bind after i have live socket connection. but server show HEX Error message when receive the stream. SMPP Unit interface uses Classes; Type // c octet strings TSystemID = string[16]; TPassword = string[9]; TSystemType = string[13]; TAddr = string[21]; TAddr_Range = string[41]; TSvc_Type = string[6]; TDate_time = string[17]; TMsgID = string[65]; pPDU_HDR = ^TPDU_HDR; TPDU_HDR = packed record command_len : LongWord ; command_id : LongWord ; command_status :LongWord ; command_number:LongWord ; end; pSMPP_BIND = ^TSMPP_BIND ; TSMPP_BIND = packed record SystemID : TSystemID ; Password : TPassword ; SystemType : TSystemType ; Ver : Byte; Addr_TON : Byte ; Addr_NPI : Byte ; Addr_Range : TAddr_Range ; end; const { max short message length } DCS7_MAX_LEN = 160; DCS8_MAX_LEN = 140; DCSUCS2_MAX_LEN = DCS8_MAX_LEN div 2; { command ids } cmdNull = $00000000; cmdBindReceiver = $00000001; cmdBindTransmitter = $00000002; cmdQuery = $00000003; cmdReplace = $00000007; cmdCancel = $00000008; cmdBindTransceiver = $00000009; cmdOutbind = $0000000B; cmdUnbind = $00000006; cmdSubmitSM = $00000004; cmdDeliverSM = $00000005; cmdEnquireLink = $00000015; cmdSubmitMultiply = $00000021; cmdAlertNotification = $00000102; cmdData = $00000103; cmdGenericNack = $80000000; cmdResponseBase = $80000000; cmdBindReceiverResponse = $80000001; cmdBindTransmitterResponse = $80000002; cmdQueryResponse = $80000003; cmdReplaceResponse = $80000007; cmdCancelResponse = $80000008; cmdBindTransceiverResponse = $80000009; cmdUnbindResponse = $80000006; cmdSubmitSMResponse = $80000004; cmdDeliverSMResponse = $80000005; cmdEnquireLinkResponse = $80000015; cmdSubmitMultiplyResponse = $80000021; cmdDataResponse = $80000103; { ESM_CLASS } ESM_CLASS_DELIVERY_RECEIPT = $04; ESM_CLASS_UDHI = $40; implementation end. ON My Form btnSendBindClick procedure TFrmMain.btnSendBindClick(Sender: TObject); var hdr : TPDU_HDR ; bind_pkt : TSMPP_BIND ; mm : TMemoryStream ; HdrPtr : pPDU_HDR ; BindPtr : pSMPP_BIND ; sysid : AnsiString ; pass : AnsiString ; systype : AnsiString ; add_rn : AnsiString ; begin sysid := 'sysid'; pass := 'pass'; systype := 'sys_type'; add_rn := ''; hdr.command_id := htonl(cmdBindTransceiver) ; hdr.command_status := htonl(cmdNull) ; hdr.command_number := htonl(cmdBindTransmitter) ; hdr.command_len := htonl(SizeOf(hdr)+SizeOf(bind_pkt)); bind_pkt.SystemID := pansiChar(sysid); bind_pkt.Password := pansiChar(pass); bind_pkt.SystemType := pansiChar(systype); bind_pkt.Ver := 0 ; bind_pkt.Addr_TON := 1 ; bind_pkt.Addr_NPI := 1 ; bind_pkt.Addr_Range := pansiChar(add_rn); HdrPtr := #HdrPtr ; BindPtr := #bind_pkt ; mm := TMemoryStream.Create ; mm.Write(HdrPtr^,SizeOf(hdr)); mm.Position := mm.Size; mm.Write(BindPtr^,SizeOf(bind_pkt)); mm.Position := 0 ; clnt.Socket.SendStream(mm); end; I think i need to encode data stream to something, but i am not sure .
I worked with SMPP in 1999/2000 last time, but at that time, specs. 3.4 said that fields like SystemID, Password etc..., i.e. declared as Var. Max nn, are of type C-OctetString. So if the spec did not change, you completelly missed it: you cannot use records and similiar data structures, but you have to create an octet stream containing sequence of ASCIIZ strings with no padding, e.g. (using Delphi syntax): ...'SystemId'#0'Password'#0'SystemType'#0.... And if I remember it correctly, you should change endians for integer fields as well.
delphi ole excel container, save file
what is the syntax for this c++ question in Delphi? After using an oleContainer, and trying to do SaveDocumentAs which didn't work. I thought this might be a good alternative. update: thank you for the translation, however the excel file goes curropted after the call var ExcelOle: TOleContainer; begin ExcelOLE.CreateObjectFromFile(FileName, False); ExcelOle.OleObject.application.workbooks[1].save; end;
Simply create an Ole Object: uses ComObj, Excel; var Excel: OleVariant; Excel := CreateOleObject('EXCEL.Application'); Excel.Application.Workbooks.Add; Excel.Application.Workbooks[1].SaveAs('c:\test.xlsx', xlWorkbookDefault); // or xlOpenXMLWorkbook (51) Excel.Application.Quit; Excel.pas unit Excel; interface uses Windows, Activex; // originally from Excel97.pas // XlFileFormat constants type XlFileFormat = TOleEnum; const xlAddIn = $00000012; xlCSV = $00000006; xlCSVMac = $00000016; xlCSVMSDOS = $00000018; xlCSVWindows = $00000017; xlDBF2 = $00000007; xlDBF3 = $00000008; xlDBF4 = $0000000B; xlDIF = $00000009; xlExcel2 = $00000010; xlExcel2FarEast = $0000001B; xlExcel3 = $0000001D; xlExcel4 = $00000021; xlExcel5 = $00000027; xlExcel7 = $00000027; xlExcel9795 = $0000002B; xlExcel4Workbook = $00000023; xlIntlAddIn = $0000001A; xlIntlMacro = $00000019; xlWorkbookNormal = $FFFFEFD1; xlSYLK = $00000002; xlTemplate = $00000011; xlCurrentPlatformText = $FFFFEFC2; xlTextMac = $00000013; xlTextMSDOS = $00000015; xlTextPrinter = $00000024; xlTextWindows = $00000014; xlWJ2WD1 = $0000000E; xlWK1 = $00000005; xlWK1ALL = $0000001F; xlWK1FMT = $0000001E; xlWK3 = $0000000F; xlWK4 = $00000026; xlWK3FM3 = $00000020; xlWKS = $00000004; xlWorks2FarEast = $0000001C; xlWQ1 = $00000022; xlWJ3 = $00000028; xlWJ3FJ3 = $00000029; xlExcel12 =50; xlExcel8 = 56; xlHtml = 44; xlOpenXMLAddIn = 55; xlOpenXMLTemplate = 54; xlOpenXMLTemplateMacroEnabled = 53; xlOpenXMLWorkbook = 51; xlOpenXMLWorkbookMacroEnabled = 52; xlTemplate8 = 17; xlUnicodeText = 42; xlWebArchive = 45; xlWorkbookDefault = 51; xlXMLSpreadsheet = 46; implementation end.