![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm currently writing my own smtp email function using Delphi 7. This function which is located in an external dll will be called by Sybase. I have an issue between Sybase and the Delphi function parameter type e.g. when Sybase send a field data type varchar or Long varchar, what Delphi data type should be used ? If someone has some experience and/or sample code... Thanks in advance. |
#3
| |||
| |||
|
|
I'm currently writing my own smtp email function using Delphi 7. This function which is located in an external dll will be called by Sybase. I have an issue between Sybase and the Delphi function parameter type e.g. when Sybase send a field data type varchar or Long varchar, what Delphi data type should be used ? If someone has some experience and/or sample code... Thanks in advance. |
#4
| |||
| |||
|
|
"Nick Elson" <no_spam_nicelson (AT) sybase (DOT) com> wrote in message news:3fd4ef9d$1 (AT) forums-1-dub (DOT) .. The facility is really targeted for DLLs developed in the C programming language. How you would or even if you can do that from an Objective Pascal dialect I cannot say. AFAIK Delphi supports ActiveX and VBX type components. This API is not component based at all. You need raw character buffers and a way to emulate the call conventions documented in this on-line documents: Adaptive Server Anywhere SQL User's Guide 17. Using Procedures, Triggers, and Batches Calling external libraries from procedures "External function prototypes" Short of working with a C/C++ compiler the answer to doing this from Delphi may be just be a "No". I don't think things are THAT bad. First of all, I've looked through extfnapi.h and haven't found anything that cannot be converted to Object Pascal. Second, there is an "old" API which is easier to use. Function to send E-Mail via SMTP is declared in Delphi DLL as follows: function SendMessage(sHost, sSubject, sTo, sFrom, sText, sAttachments: PChar): Word; StdCall; In ASA, declare it like this: ALTER FUNCTION "DBA"."SendMessage"(in sHost char(100),in sSubject char(100),in sTo char(100),in sFrom char(100),in sText char(1000),in sAttachments char(255)) returns integer external name 'SendMessage (AT) arctool (DOT) dll' Test script: % % % Sybase Central generated procedure test script % % % Ensure our test variables do not already exist SET OPTION On_error = 'continue'; DROP VARIABLE "sHost"; DROP VARIABLE "sSubject"; DROP VARIABLE "sTo"; DROP VARIABLE "sFrom"; DROP VARIABLE "sText"; DROP VARIABLE "sAttachments"; SET OPTION On_error = 'prompt'; % % % Create input/output variables CREATE VARIABLE "sHost" char ( 100 ); CREATE VARIABLE "sSubject" char ( 100 ); CREATE VARIABLE "sTo" char ( 100 ); CREATE VARIABLE "sFrom" char ( 100 ); CREATE VARIABLE "sText" char ( 1000 ); CREATE VARIABLE "sAttachments" char ( 1000 ); % % % Edit the following lines to set the input values SET "sHost" = '193.123.2.8'; SET "sSubject" = 'Test'; SET "sTo" = '***'; SET "sFrom" = '***'; SET "sText" = SET "sAttachments" = 'c:\Asa9\Readme.txt'; % % % Call the function SELECT "SendMessages"( "sHost", "sSubject", "sTo", "sFrom", "sText", "sAttachments" ) FROM DUMMY; Sends a pretty nice message with attachment .Tested on ASA9; works on 5.5, but character variables are limited to 255 bytes. Dmitri. |
#5
| |||
| |||
|
|
Yes Dimitri is correct about there being an older API. There is an OLD version 5.0/6.0 API that can be a lot simpler to use (if you have the ver. 6 docs ... it is no longer documented with the change in version 7) |
|
... BUT ... there are limitations. There is no support for any variable data types Anything bigger than a char(254) is also out. Be warned though! Dimitri's example shouldn't work in 9. ============= It may not be stable since it may be overwriting memory. The API is still there but [AFAIK] I don't think we ever intentionally relaxed the 254 byte limitation. So Dimitri could be coding to a bug there. |
|
"Dmitri" <NOdimSPAM (AT) mail15 (DOT) com> wrote in message news:3fd58d5f (AT) forums-1-dub (DOT) .. "Nick Elson" <no_spam_nicelson (AT) sybase (DOT) com> wrote in message news:3fd4ef9d$1 (AT) forums-1-dub (DOT) .. The facility is really targeted for DLLs developed in the C programming language. How you would or even if you can do that from an Objective Pascal dialect I cannot say. AFAIK Delphi supports ActiveX and VBX type components. This API is not component based at all. You need raw character buffers and a way to emulate the call conventions documented in this on-line documents: Adaptive Server Anywhere SQL User's Guide 17. Using Procedures, Triggers, and Batches Calling external libraries from procedures "External function prototypes" Short of working with a C/C++ compiler the answer to doing this from Delphi may be just be a "No". I don't think things are THAT bad. First of all, I've looked through extfnapi.h and haven't found anything that cannot be converted to Object Pascal. Second, there is an "old" API which is easier to use. Function to send E-Mail via SMTP is declared in Delphi DLL as follows: function SendMessage(sHost, sSubject, sTo, sFrom, sText, sAttachments: PChar): Word; StdCall; In ASA, declare it like this: ALTER FUNCTION "DBA"."SendMessage"(in sHost char(100),in sSubject char(100),in sTo char(100),in sFrom char(100),in sText char(1000),in sAttachments char(255)) returns integer external name 'SendMessage (AT) arctool (DOT) dll' Test script: % % % Sybase Central generated procedure test script % % % Ensure our test variables do not already exist SET OPTION On_error = 'continue'; DROP VARIABLE "sHost"; DROP VARIABLE "sSubject"; DROP VARIABLE "sTo"; DROP VARIABLE "sFrom"; DROP VARIABLE "sText"; DROP VARIABLE "sAttachments"; SET OPTION On_error = 'prompt'; % % % Create input/output variables CREATE VARIABLE "sHost" char ( 100 ); CREATE VARIABLE "sSubject" char ( 100 ); CREATE VARIABLE "sTo" char ( 100 ); CREATE VARIABLE "sFrom" char ( 100 ); CREATE VARIABLE "sText" char ( 1000 ); CREATE VARIABLE "sAttachments" char ( 1000 ); % % % Edit the following lines to set the input values SET "sHost" = '193.123.2.8'; SET "sSubject" = 'Test'; SET "sTo" = '***'; SET "sFrom" = '***'; SET "sText" = SET "sAttachments" = 'c:\Asa9\Readme.txt'; % % % Call the function SELECT "SendMessages"( "sHost", "sSubject", "sTo", "sFrom", "sText", "sAttachments" ) FROM DUMMY; Sends a pretty nice message with attachment .Tested on ASA9; works on 5.5, but character variables are limited to 255 bytes. Dmitri. |
#6
| |||
| |||
|
|
If it is an unintentional behaviour which may lead to overwriting some memory inside server, maybe it would make sense to put an intentional restriction here? |
|
Hi Nick, please see my comments inline: "Nick Elson" <no_spam_nicelson (AT) sybase (DOT) com> wrote in message news:3fd5fd3c (AT) forums-2-dub (DOT) .. Yes Dimitri is correct about there being an older API. There is an OLD version 5.0/6.0 API that can be a lot simpler to use (if you have the ver. 6 docs ... it is no longer documented with the change in version 7) I was a bit surprised when I haven't found old API description in ASA9 docs, but it was not a problem for me as I fortunately have 5.5 docs handy. ... BUT ... there are limitations. There is no support for any variable data types Anything bigger than a char(254) is also out. Be warned though! Dimitri's example shouldn't work in 9. ============= It may not be stable since it may be overwriting memory. The API is still there but [AFAIK] I don't think we ever intentionally relaxed the 254 byte limitation. So Dimitri could be coding to a bug there. Just for the record, it is NOT a production example. I use my DLL to send E-Mails via SMTP (and do some other stuff - not relevant here) from Powerbuilder applications. I wrote an ASA wrapper just to provide an example of Delphi-ASA interaction, and I haven't tested it rigorously. I've sent a couple of letters both from version 5.5 and 9 servers; version 5.5 has truncated char(1000) parameter to 254 chars, and version 9 has not. If it is an unintentional behaviour which may lead to overwriting some memory inside server, maybe it would make sense to put an intentional restriction here? Dmitri. "Dmitri" <NOdimSPAM (AT) mail15 (DOT) com> wrote in message news:3fd58d5f (AT) forums-1-dub (DOT) .. "Nick Elson" <no_spam_nicelson (AT) sybase (DOT) com> wrote in message news:3fd4ef9d$1 (AT) forums-1-dub (DOT) .. The facility is really targeted for DLLs developed in the C programming language. How you would or even if you can do that from an Objective Pascal dialect I cannot say. AFAIK Delphi supports ActiveX and VBX type components. This API is not component based at all. You need raw character buffers and a way to emulate the call conventions documented in this on-line documents: Adaptive Server Anywhere SQL User's Guide 17. Using Procedures, Triggers, and Batches Calling external libraries from procedures "External function prototypes" Short of working with a C/C++ compiler the answer to doing this from Delphi may be just be a "No". I don't think things are THAT bad. First of all, I've looked through extfnapi.h and haven't found anything that cannot be converted to Object Pascal. Second, there is an "old" API which is easier to use. Function to send E-Mail via SMTP is declared in Delphi DLL as follows: function SendMessage(sHost, sSubject, sTo, sFrom, sText, sAttachments: PChar): Word; StdCall; In ASA, declare it like this: ALTER FUNCTION "DBA"."SendMessage"(in sHost char(100),in sSubject char(100),in sTo char(100),in sFrom char(100),in sText char(1000),in sAttachments char(255)) returns integer external name 'SendMessage (AT) arctool (DOT) dll' Test script: % % % Sybase Central generated procedure test script % % % Ensure our test variables do not already exist SET OPTION On_error = 'continue'; DROP VARIABLE "sHost"; DROP VARIABLE "sSubject"; DROP VARIABLE "sTo"; DROP VARIABLE "sFrom"; DROP VARIABLE "sText"; DROP VARIABLE "sAttachments"; SET OPTION On_error = 'prompt'; % % % Create input/output variables CREATE VARIABLE "sHost" char ( 100 ); CREATE VARIABLE "sSubject" char ( 100 ); CREATE VARIABLE "sTo" char ( 100 ); CREATE VARIABLE "sFrom" char ( 100 ); CREATE VARIABLE "sText" char ( 1000 ); CREATE VARIABLE "sAttachments" char ( 1000 ); % % % Edit the following lines to set the input values SET "sHost" = '193.123.2.8'; SET "sSubject" = 'Test'; SET "sTo" = '***'; SET "sFrom" = '***'; SET "sText" = SET "sAttachments" = 'c:\Asa9\Readme.txt'; % % % Call the function SELECT "SendMessages"( "sHost", "sSubject", "sTo", "sFrom", "sText", "sAttachments" ) FROM DUMMY; Sends a pretty nice message with attachment .Tested on ASA9; works on 5.5, but character variables are limited to 255 bytes. Dmitri. |
![]() |
| Thread Tools | |
| Display Modes | |
| |