dbTalk Databases Forums  

Delphi function parameter data type and asa char, varchar & long varchar

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Delphi function parameter data type and asa char, varchar & long varchar in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Franz Griesser
 
Posts: n/a

Default Delphi function parameter data type and asa char, varchar & long varchar - 12-05-2003 , 04:18 AM






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.

Reply With Quote
  #2  
Old   
A.Iwan
 
Posts: n/a

Default Re: Delphi function parameter data type and asa char, varchar & long varchar - 12-06-2003 , 11:00 AM







See and tanslate to Delphi pascal "extfnapi.h".

To provide values for INOUT or OUT parameters, use the set_value API
function.
To read IN and INOUT parameters, use the get_value API function.

A. Iwan

Użytkownik <Franz Griesser> napisał w wiadomości
news:3fd05d0d.6d09.846930886 (AT) sybase (DOT) com...
Quote:
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.



Reply With Quote
  #3  
Old   
Nick Elson
 
Posts: n/a

Default Re: Delphi function parameter data type and asa char, varchar & long varchar - 12-08-2003 , 03:39 PM



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".


<Franz Griesser> wrote

Quote:
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.



Reply With Quote
  #4  
Old   
Nick Elson
 
Posts: n/a

Default Re: Delphi function parameter data type and asa char, varchar & long varchar - 12-09-2003 , 10:42 AM



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

Quote:
"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.



Reply With Quote
  #5  
Old   
Dmitri
 
Posts: n/a

Default Re: Delphi function parameter data type and asa char, varchar & long varchar - 12-10-2003 , 02:56 AM



Hi Nick,

please see my comments inline:

"Nick Elson" <no_spam_nicelson (AT) sybase (DOT) com> wrote

Quote:
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.

Quote:
... 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.

Quote:
"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.


Reply With Quote
  #6  
Old   
Nick Elson
 
Posts: n/a

Default Re: Delphi function parameter data type and asa char, varchar & long varchar - 12-10-2003 , 11:58 AM



I only *needed* to point this out since other readers may fall into a trap
here if they just blindly followed your earlier suggestion.


Quote:
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?

Note: I am mostly concerned with stability here! I will start an internal
discussion
about this aspect of the question..

For now just assume that

- since it was never supposed to work this way (even when it was
documented)

- since version 5 or 6 would have failed the first time you tried to use
it

and

- it is only part of product for *** backward compatibility *** reasons


It shouldn't be expected to be needed to work for new development. Nor
can you expect ongoing support for such extended usage in a future product.



"Dmitri" <NOdimSPAM (AT) mail15 (DOT) com> wrote

Quote:
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.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.