Returning strings from OLE2 Word object (Forms 4.5)
Below is an example of how to return string and numeric values from OLE2 objects. In this example the OLE2 object is a MS Word document, and I want to fetch all the bookmarks in the Document into a Forms 4.5 Varchar2. To do this I first need to get the count of bookmarks.
Getting a string property from an OLE2 object is a common OLE2 requirement but is poorly documented. This is the ONLY way it can be done, as OLE2.INVOKE_CHAR returns a single character not a string. Use OLE2.INVOKE_OBJ, then OLE2.GET_CHAR_PROPERTY which does return a string, as shown below, to return a string from an OLE object (or OLE property).
Also note how you can only get the child object from its parent, not the grandchild (etc) object, so multiple (cascading) GET_OBJ_PROPERTY calls are required.
/* by: Marcus Anderson (Anderson Digital) (MarcusAnderson.info) */
/* name: Get_Bookmarks */
/* desc: Returns a double quoted CSV string containing the document*/
/* bookmarks. CSV string will always contain a trailing comma*/
/* EG: "Bookmark1","Bookmark2",Bookmark3",Bookmark4", */
/* NB: This requires that Bookmarks cannot contain " chr */
PROCEDURE Get_Bookmarks (pout_text OUT VARCHAR2)
IS
v_text VARCHAR2(80);
v_num NUMBER(3);
v_arglist OLE2.LIST_TYPE;
v_Application OLE2.OBJ_TYPE;
v_ActiveDoc OLE2.OBJ_TYPE;
v_Bookmarks OLE2.OBJ_TYPE;
v_Item OLE2.OBJ_TYPE;
v_i NUMBER(3);
BEGIN
v_Application := LDWord.MyApplication; -- Word doc opened elsewhere
/* Set v_num = ActiveDocument.Bookmarks.Count */
v_ActiveDoc := OLE2.GET_OBJ_PROPERTY (v_Application, 'ActiveDocument');
v_Bookmarks := OLE2.GET_OBJ_PROPERTY (v_ActiveDoc , 'Bookmarks');
v_num := OLE2.GET_NUM_PROPERTY (v_Bookmarks, 'Count'); -- NB: Returns numeric property
/* Build the output string, pout_text. */
FOR v_i in 1..v_num LOOP
/* Set v_item = ActiveDocument.Bookmarks.Item(v_i) */
v_arglist := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (v_arglist, v_i);
v_Item := OLE2.INVOKE_OBJ (v_Bookmarks, 'Item', v_arglist); -- NB: returns parent object (array element)
OLE2.DESTROY_ARGLIST (v_arglist);
/* Set v_text = ActiveDocument.Bookmarks.Item(v_i).Name */
v_text := OLE2.GET_CHAR_PROPERTY (v_Item, 'Name'); -- NB: Returns string/varchar2 property
pout_text := pout_text || '"' || v_text || '",' ;
END LOOP;
END;
Please repost in the Forms discussion forum.
- OTN
Similar Messages
-
Return data from Java servlet in form of JSON encoded parameters in Javascr
How to return data from Java servlet in form of JSON encoded parameters in Javascript handler function call?
The same is implemented in php as the following
echo "sT.handleAjaxResponse(";
echo json_encode($response);
echo ");";
How to do the same in Java servlet?
Thanks.With the rising popularity of JSON (especially with Ajax), support for it has started to appear in the Java community. I am not aware of any standardized approach yet, but expect it is likely we'll see that eventually. For now, you probably want to look at a third-party library such as the [JSON in Java Library|http://www.json.org/java/], Jettison, or [Java Tools for the JSON Format|http://jsontools.berlios.de/].
-
Returning strings from Java- C JNI calls
<newbie to JNI>
I have an application written in Java that accesses a .DLL written in C. The .DLL does low-level communication to a hardware device. I've got it all working except for one little problem:
For all of the functions I need to return an integer return code and for some of them I also need to return a string, such as a serial number, version string, or whatever.
Try as I might, I can't find any information on how to return two values from a function call (pretty sure I can't in Java).
SO, I tried to find out how to stuff the version string into a string object variable in the class object the DLL API is defined in. I can't figure out how to do that either...
e.g. the following Java code:
class LLDev {
/* --- Load the .DLL -------------------- */
static { System.loadLibrary("LLDev"); }
/* --- Error Codes ---------------------- */
public static final int LLDOk = 0;
public static final int LLDInitErr = -1;
/* --- Public Variables ----------------- */
public static String DLLVersion;
/* --- Public Methods ------------------- */
public native int InitLLDev();
When I invoke LLDev.InitLLDev() from Java I want the C .DLL function Java_LLDev_InitLLDev to put the DLL Version string in the LLDev object's DLLVersion field and return an error code as the function result.
Is this possible???? Is this the right way to do this?? I tried to define the API with methods that return strings instead of integer return codes but the customer using the class wants all of the methods to return a return code in case of some error (e.g. reading the serial number from the device could fail...)1. In general, the java way to deal with errors is by throwing exceptions, not using return codes. But OK, you are stuck with the user requirement.
2. I suggest you have the native method take as an argument a java object which will accept a string as input. In other words, it has a string "setter".
3. So in your native method, if the function succeeds, it writes your string result to that object, and you can futrther process it when the native method returns a "success" code.
4. There are JNI methods for
o looking up the class of a java object.
o looking up the method of a java class.
o invoking the method. -
Trouble returning String from JNI method
I'm a JNI newbie who is going through the SUN online book on JNI and have put together the 2nd program example (right after "helloworld"), but it is not working right. It is supposed to prompt you for a string, then returns the string that you type in. Right now it compiles without error, but it returns only the first word that I type, not the whole sentence. What am I doing wrong?
Here's the code:
Prompt.java
package petes.JNI;
public class Prompt
private native String getLine(String prompt);
static
System.loadLibrary("petes_JNI_Prompt");
public static void main(String[] args)
Prompt p = new Prompt();
String input = p.getLine("Type a line: ");
System.out.println("User typed: " + input);
}petes_JNI_Prompt.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class petes_JNI_Prompt */
#ifndef _Included_petes_JNI_Prompt
#define _Included_petes_JNI_Prompt
#ifdef __cplusplus
extern "C" {
#endif
* Class: petes_JNI_Prompt
* Method: getLine
* Signature: (Ljava/lang/String;)Ljava/lang/String;
JNIEXPORT jstring JNICALL Java_petes_JNI_Prompt_getLine
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
#endif
#endifpetes_JNI_Prompt.c
#include <jni.h>
#include <stdio.h>
#include "petes_JNI_Prompt.h"
JNIEXPORT jstring JNICALL Java_petes_JNI_Prompt_getLine
(JNIEnv *env, jobject this, jstring prompt)
char buf[128];
const jbyte *str;
str = (*env)->GetStringUTFChars(env, prompt, NULL);
if (str == NULL)
return NULL; /* OutOfMemoryError already thrown */
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
// assume here that user will ty pe in 127 or less characters
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);
}Thanks in advance!
/PeteOK, I have something that works now by substituting fgets for scanf. I have two other questions:
1) Do I need to free the memory created in buf? Will it allocate memory every time the method is run? Or will it allocate only once on creation, and so is no big deal?
2) A minor question: When I run this program in eclipse, the prompt string is displayed in the console only after the input string is entered and displayed. It works fine when I run it from the command line however. I have a feeling that this is a problem with how Eclipse deals with native methods and perhaps nothing I can fix. Any thoughts?
Thanks
Pete
Addendum, the updated code:
#include <jni.h>
#include <stdio.h>
#include "petes_JNI_Prompt.h"
JNIEXPORT jstring JNICALL Java_petes_JNI_Prompt_getLine
(JNIEnv *env, jobject this, jstring prompt)
char buf[128];
const jbyte *str;
str = (*env)->GetStringUTFChars(env, prompt, NULL);
if (str == NULL)
return NULL; /* OutOfMemoryError already thrown */
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
//scanf("%s", buf);
fgets(buf, 128, stdin);
return (*env)->NewStringUTF(env, buf);
}Message was edited by:
petes1234 -
Why returning string from java stored function failed ? HELP ME, PLEASE
Hi everybody,
I created java stored function: it's doing http post, parsing xml from http reply, and returning string result.
Sometimes, it doesn't return any value. What can be a reason ?
The high level procedure, has following form:
class SBE {
public static String call(String arg0) {
SBE sbe=new SBE("d:\\oracle\\ora81\\network\\log\\SBE.log");
String result=SBEParser.go(sbe.sendRequest(arg0, ""), sbe.logger);
sbe.logger.log(result);
sbe.logger.log("Finish SBE intetraction");
return result;
PLSQL wrapper has a simple form:
create or replace package PG_SBE as
function CALL(arg0 in varchar2) return varchar2;
end;
create or replace package body PG_SBE as
function CALL(arg0 varchar2) return varchar2 as language java name 'SBE.call(java.lang.String) return java.lang.String';
end;
In log file ("d:\\oracle\\ora81\\network\\log\\SBE.log"), I can find message :
"Finish SBE intetraction"
but query:
select pg_sbe.call("any argument") from dual;
doesn't finish.
What can be a reason ? What can I do to trace stage of convertion java string to varchar ?
Please help me...
Best regards
Marek<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Stefan Fdgersten ([email protected]):
Maybe your call is wrong... Shouldn't there be a "?" instead of "1"?
Your code:
String myquery = "begin :1 := jspTest; end;";
I provide my (working) call from java as an example. Maybe it is of any help... :)
import java.sql.*;
import oracle.jdbc.driver.*;
public Vector getAllHosts() throws SQLException {
//return getHosts(false, -1);
Connection conn = null;
CallableStatement cs = null;
Vector hostV = new Vector();
try {
conn = getConnection();
String query = "{ ? = call curTestPkg.curTestFunc}";
cs = conn.prepareCall(query);
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.execute();
ResultSet rs = ((OracleCallableStatement)cs).getCursor(1);
while (rs.next()) {
Host host = new Host(
rs.getInt("hostid")
, rs.getString("name")
, rs.getString("descr")
, rs.getString("os"));
hostV.add(host);
cs.close();
return hostV;
} finally {
close(conn, cs);
<HR></BLOCKQUOTE>
hi Stefan thanx.....even after changing the call statement i get the same error. i changed query string as...
String myquery = "{ ? = call jspTest}";
CallableStatement cst = con.prepareCall(myquery);
Can u please check out my call sepc that i have written in pl/sql and plz let me know it there is any error in that.
PS : THIS IS THE FIRST TIME I AM WORKING WITH PL/SQL AND IT IS URGENT -
Why returning string from java stored function failed ?
I created java stored function: it's doing http post, parsing xml from http reply, and returning string result.
Sometimes, it doesn't return any value. What can be a reason ?
The high level procedure, has following form:
class SBE {
public static String call(String arg0) {
SBE sbe=new SBE("d:\\oracle\\ora81\\network\\log\\SBE.log");
String result=SBEParser.go(sbe.sendRequest(arg0, ""), sbe.logger);
sbe.logger.log(result);
sbe.logger.log("Finish SBE intetraction");
return result;
PLSQL wrapper has a simple form:
create or replace package PG_SBE as
function CALL(arg0 in varchar2) return varchar2;
end;
create or replace package body PG_SBE as
function CALL(arg0 varchar2) return varchar2 as language java name 'SBE.call(java.lang.String) return java.lang.String';
end;
In log file ("d:\\oracle\\ora81\\network\\log\\SBE.log"), I can find message :
"Finish SBE intetraction"
but query:
select pg_sbe.call("any argument") from dual;
doesn't finish.
What can be a reason ? What can I do to trace stage of convertion java string to varchar ?
Please help me...
MarekThis comes up periodically. It just isn't possible using that type of approach. Probably the best you could do is the create an ADT (containing collections) and use that to pass a 'batch' of information.
Hopefully this will get addressed in the next release of the database. -
How to create XML string from BPM Business Object?
Hello,
I have a business object in my BPM project and I need to transform it in a XML string:
From:
Business Object: Customer
Properties: Name, Age
To:
"<Customer><Name>Robert</Name><Age>17</Age></Customer>"
How can I do this?
Thanks.Hello,
I have a business object in my BPM project and I need to transform it in a XML string:
From:
Business Object: Customer
Properties: Name, Age
To:
"<Customer><Name>Robert</Name><Age>17</Age></Customer>"
How can I do this?
Thanks. -
Returning String[] from C program
How can I return a string[] from a cprogram to a java program?
private native String[] readRFIDData();
JNIEXPORT jobjectArray JNICALL Java_RfidDM_readRFIDData
(JNIEnv *, jobject);
Above is the definition of a jni method .
I have gone through the sample code, but they explain how to return arrays from C++.
Can someone please suggest? I am not good at C.
Much thanks,
AnnThanks Scott.
This code works fine for me...
jclass sclass = (*env)->FindClass(env, "java/lang/String");
jobjectArray ret = (*env)->NewObjectArray(env, length, sclass, NULL);
for(i=0;i<37;i++){
(*env)->SetObjectArrayElement(
env,ret,i,(*env)->NewStringUTF(env,&buf));
printf(&buf[i]); -
Need to return String from C Program to Java
I need to execute a C Program, which returns a string, from my java application. I was thinking of using RMI to execute this C program. Any idea ?
There are lots of ways to do this. The simplist is probably for the C program to write it's output to a temporary file, and then have the java program read that file. Or, you could open a socket and pass the string that way (say, have your java program listen on a port and have the C program open a connection to the java program and write it's string).
Hope that gives you a starter -
Capturing information from the Resource Object forms
Hello,
I'd like to capture information (dburl, dbdriver,username and password) from my resource objects to use in a class i'm developing through the API.
However, I failed to find any methods in API to get this information... does anyone know how to retrieve this?
Thanks in advance,
TomicHi,
I am not very clear about your question.The information below is usually store in IT Resource.If these information is store in IT Resource you can use tcITResourceInstanceOperationsIntf.
What is your business drive for getting this information from resource object form.Can you explain me so that I can have better answer.
Regards
Nitesh -
How to retreive String from the Connection object
hi all,
I am using HttpConnection to Connect to the server.I want to retreive string from the Connection.
As like Connection.openInputStream() is there any method to get the String from the connection.In the server side also i want to send the String not the stream .
Thanks in advance
lakshmanJust read the string from the stream.
-
Return String from Oracle stored proc using Excel 2003 VBA
Hi to everyone,
I've got a problem that remains unsolved for many days. I am trying to return a value of an oracle stored procedure using Excel VBA. It might seem trivial, however it's not for someone, who has never done it before...
OS: Win XP SP3
Excel 2003
Ora Client: 11g
By trying different things I have noticed, that I could have troubles with the ODBC-connection. Maybe I am not using the right one. To store data returned from select statements I have an ODBC-Connection (Driver: Oracle in XE), which works perfectly, e.g.:
Sub Extract_Data()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim db_name, UserName, Password As String
cn.Open db_name, USerName, Password
sql_statement = "SELECT some_text FROM some_table"
Set rs = cn.Execute(sql_statement)
rs.MoveFirst 'jump to the first entry in the data list
Row = 2
While Not rs.EOF
'save the data to a worksheet
ip.Cells(Row, 2) = rs(0).Value
Row = Row + 1
rs.MoveNext
Wend
End Sub
Now I need to execute a stored procedure to return a semi-colon delimited string.
I have tried the following:
Public Sub obj_class()
Dim cn As New ADODB.Connection
Dim strSQL, cn As String
Dim adoCMD As ADODB.Command
Dim adoRS As ADODB.Recordset
Set wb = Excel.ActiveWorkbook
Set ih = wb.Sheets("InfoSheet")
cn.Open db_name, UserName, Password
Set adoCMD = New ADODB.Command
With adoCMD
.ActiveConnection = cn
.CommandText = "S#mdb$stg_da_extr_util.get_all_classes_of_classif"
.CommandType = adCmdStoredProc
.Parameters.Refresh
'------ and here comes the error saying:
'------ could not find the object in the collection corresponding to the name or ordinal reference requested by the application
.Parameters("i_caller").Value = "'STG_DATA_REQUEST'"
.Parameters("i_obj_classif_id").Value = 120
Set adoRS = .Execute()
End With
End Sub
I did asked on the forum:
http://www.access-programmers.co.uk/forums/showthread.php?p=1241667#post1241667
but unfortunately without success.
Could it be, that my ODBC-connection is wrong? When debugging the connection string, I find the Provider=MSDASQL5.1.
I have moderate knowledge in VBA, but absolutely a newbie with Oracle DB. Is there any source of information that can help solving this issue? Looking forward to hearing from you, as I am almost giving up... ;(My VBA is super rusty. Does that error come after Parameters.Refresh, or after .Parameters("i_caller").Value = "'STG_DATA_REQUEST'"?
If it's the second one, you'll need the definition of the stored procedure so you can see what parameters it's expecting. That'd mean you're getting something wrong with the names. -
Sub string from a word to another word
I want to find word "cat" from the sentence: My cat is missing.
Please provide a generic solution which works for ant set of statements for finding a word.Since "cat" can be found inside of other words it is better to use Regex to extract hole words like in the code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication21
class Program
static void Main(string[] args)
string input = "My cat is missing";
string pattern = @"^(\w+\s?)+$";
Regex expr = new Regex(pattern);
Match match = expr.Match(input);
Group group = match.Groups[1];
foreach (Capture capture in group.Captures)
Console.WriteLine("Word : {0}", capture.ToString());
jdweng
I'd like to suggest a couple of changes to build on Joel Engineer's answer.
Firstly, that's a rather restrictive pattern. The period at the end of the sentence will confound it (which I notice was removed from the example), and so would a word like "isn't". I'd use \b to make this pattern:
\bcat\b
\b matches a word boundary, and is specifically designed for performing whole-word matching like this.
Also, a case-insensitive matching option would be good here.
Then you can get the index of the match using Regex.Matches, which seems more useful than just knowing whether "cat" is in there somewhere or not, and seems more in the spirit of actually
finding the match.
static void Main( string[] args )
string input = @"My cat is missing.";
string pattern = @"\bcat\b";
MatchCollection matches = Regex.Matches( input, pattern, RegexOptions.IgnoreCase );
if( matches.Count > 0 ) {
// found
Console.WriteLine( "Found at index {0}", matches[0].Index );
} else {
Console.WriteLine( "Not found" ); -
How to return string from Applet back to the broser textbox
Hi everybody , i m new to java applet .
I have an applet running on the browser along with a text box. the applet connects to the database and in the end a string should be copied back to the textbox on the browser. I have no idea how do i do it
if anybody can help me.
my applet is working well. its just integration with the browser giving me hard time.
thanks alll in advance
reubenWith "text box", do you mean a text field on a HTML page? If yes, you could use the JSObject class from netscape to issue a Javascript call to the page similar to window.document.form[0].textfieldname and provide the string. The Applet tag must contain the MAYSCRIPT=true argument to allow the Applet to issue Javascript commands.
Frankl -
Can we Return values from Java Bean to Form
Hi All,
I have a Bean area defined on a Form. The Bean Area consists of a Text field which gets populated by path of a file selected using Browse button.
Can I return this path as a parameter from the Java Bean to the form? Is there any function for this?
Regards,
Prathima.If you designed your bean to offer the ability to exact info/data from it, then yes you can get a value from the bean into the form (pl/sql) - using Get_Custom_Property
Refer to the following which is a good example of how to build a bean. Specifically look at page 12 where is shows how to use Get_Custom_Property.
This is NOT an Oracle supported or provided document or web site, but it is a very good example.
http://forms.pjc.bean.over-blog.com/ext/http://sheikyerbouti.developpez.com/forms-pjc-bean/first-bean/first_bean.pdf
Maybe you are looking for
-
How I can displsy the results in a nice readable format
I have this query in a cursor I is displaying the data like this Major/Minor RestrictionEnglish English and Theater Envir St-English How I can make it to display something like this Must be enrolled in one of the following Majors: English, English an
-
Unable to create PDF/A with PDF from InDesign
Hello, I'm trying to create PDF/A document from InDesign CS4 with Adobe Acrobat 9. I create my PDF from InDesign (I create a tagged PDF). For each document create from InDesign, I receive this message from the Preeflight "Convert to PDF/A (sRGB)" of
-
I thought this one had gone away, but... I noticed recently that some images had a strangely squashed appearance. Checking them further reveals that they are an image with the wrong thumbnail attached. Simple recreating it fixed the problem. It's the
-
Is Time Machine Acting Strange ? Or ...
Hello, Every time i plug in my external, and click the time machine icon in the top left bar, it ALWAYS says "Encrypting Back Up Disk" and its always only at 1% .. The thing is that it will give me this message BEFORE it actually starts backing up th
-
Does anyone use a pen tablet? if so, which one do you use and what do you think are the advantages and disadvantages?