DOORS DXL: insert OLE Object into any object attribute - ibm-doors

Is there a way to insert, with a DXL script, a word document as an OLE Object into any object attribute different from Object Text?
DXL function oleInsert allows to do it, but works only for attribute Object Text.
Thank you

Unfortunately there is no way I can see to do it directly but this is a good work around if your object text doesn't already have an OLE in it.
Object o = current
string filename = "PATH_TO_FILE"
oleInsert(o, filename, true)
string err = null
if (oleIsObject o){
if (oleCut o){
err = olePasteSpecial(o."OTHER_ATTRIBUTE_NAME", true)
if(!null err)
print err
} else {
print "Problem trying to cut object\n"
}
} else {
print "Does not contain an embedded object in its object text\n"
}
The true in oleInsert and olePasteSpecial are to insert the OLE as an icon. If you don't want it as an icon you can change them both to false.
Good Luck!

Just for completeness: With DOORS 9.5 the signature of oleInsert() changed:
bool oleInsert(Object o,[attrRef],string fileName,[bool insertAsIcon])
With the documentation
If the optional parameter attrRef is specified, then the OLE object is
embedded in the user-defined text attribute. If no parameter is
specified, then the OLE object is embedded in the system "Object Text"
attribute.
This makes it a bit easier.

Thanks #Twonky! That's too helpful to me.
Additionally I added a sample code from dxl reference manual.
/*
this code segment embeds an existing word document into the current formal
object
*/
string docName = "c:\\docs\\details.doc"
Object obj = current
if (oleInsert(obj, obj."my_text", docName)){
print "Successfully embedded document\n"
} else {
print "Problem trying to embed document\n"
}

Related

Format JSON string to iOS Dictionary string with =

First off, what do we call a dictionary with a format like this in iOS?
(
{
name = "Apple";
value = "fruit-1";
},
{
name = "Banana";
value = "fruit-2";
}
)
And for my main question. I somehow need to format a string of JSON, like this:
[{"name":"Apple","value":"fruit-1"},{"name":"Banana","value":"fruit-2"}]
into whatever that format is called (of the string above).
For context, the existing approach of my project uses CoreData where the Server response (which uses the mystery format above) gets saved locally as a String, and I want to follow that format.
EDIT: for more context, I really need to just get the first format into the database because a module of a project was built to read the data with that format (e.g. make use of NSString.propertyList()).
Using a library called ios hierarchy viewer, I can see the saved object in the device.
Original format, server json to db (core data) in Objective-C:
What I've been trying to do in Swift, server json to local using JSONSerialization:
First off, what do we call a dictionary with a format like this in iOS?
According to the documentation of NSString.propertyList(), that's a "text representation of a property list".
It's a wonky, non-standard pretty-printing obtained by calling NSArray.description or NSDictionary.description.
Here's an example that shows a round-trip of data:
// The opening `{` indentation is fucky, but that's how it's generated.
let inputPropertyList = """
(
{
name = "Apple";
value = "fruit-1";
},
{
name = "Banana";
value = "fruit-2";
}
)
"""
// The result is an `Any` because we don't know if the root structure
// of the property list is an array or a dictionary
let deserialized: Any = inputPropertyList.propertyList()
// If you want the description in the same format, you need to cast to
// Foundation.NSArray or Foundation.NSDictionary.
// Swift.Array and Swift.Dictionary have a different description format.
let nsDict = deserialized as! NSArray
let roundTrippedPropertyList = nsDict.description
print(roundTrippedPropertyList)
assert(roundTrippedPropertyList == inputPropertyList)
The second format you show is what you get when you display an object in the debug console. That's the output of the object's description property. It isn't a "JSON string", exactly.
If you want to convert your objets to a true JSON string, see below.
As Alexander pointed out, the first string in your question is the output from NSString's propertyList() function. The format looks quite similar to "pretty-printed" JSON, but it's different enough that it it won't work that way.
The `propertyList() function is a debugging-only function, and I don't know of an existing way to parse that back into objects. If that is the string that's being sent by your server, your server is broken. If that's what you see in core data when you log the contents of a field, it's probably a misunderstanding on your part.
To convert an object to pretty JSON, see this answer, where I created an extension to the Encodable format that implements a property "prettyJSON":
extension Encodable {
var prettyJSON: String {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
guard let data = try? encoder.encode(self),
let output = String(data: data, encoding: .utf8)
else { return "Error converting \(self) to JSON string" }
return output
}
}
That should work for any object that supports the Encodable protocol. (And your object should.)

Return object realm not accessible

I'm having problems with an object that returns me in Realm, the strange thing is that if I printo console the object if I start it well but however if I try to access its value it tells me that it is empty.
The structure of the object is as follows:
class Favourite : Object {
var character : Character!
}
I create an object and add it to the DB
let fav = Favourite()
fav.character = character
FavouriteDao.sharedInstance.addFavourite(characterFavourite: fav)
Get all objects of favorite type
func getAllFavourites() -> Results {
return realm.objects(Favourite.self)
}
When I get the item and do a print
Favourite {
character = Character {
name = Spider-Man;
descriptionC = Bitten by a radioactive spider, high school student Peter Parker gained the speed, strength and powers of a spider. Adopting the name Spider-Man, Peter hoped to start a career using his new abilities. Taught that with great power comes great responsibility, Spidey has vowed to use his powers to help people.;
thumbnail = Thumbnail {
id = 815D93D0-C116-4267-978C-9E47C0074D0D;
path = http://i.annihil.us/u/prod/marvel/i/mg/3/50/526548a343e4b;
extensionImage = jpg;
};
};
If I try to access the character element it tells me that it is nil
Somebody manages to understand because if I make a print of the favorite object it shows me that there is inside a character object but nevertheless if I try to accede to it it says that it does not exist?
What you do is totally wrong from the very beginning. You should read the realm docs first. https://realm.io/docs/swift/latest/#getting-started
For example.
class Favourite : Object {
var character : Character!
}
is not something you should do in Realm.
Assuming your Character is well-defined, the code should be dynamic var character : Character? = nil at least.

how to use InputBox in c++builder with multiple values

How can I use InputBox to make it take 3 Values. I can make it show just one value by using code:
String input[3];
input[0]= InputBox("paied check", "the value", "");
any help?
InputBox() does not support what you are asking for. It is designed for single-value input only.
InputQuery() supports multi-value input, but only in C++Builder XE2 and later, eg:
String prompt[3] = {"value 1:", "value2:", "value 3:"};
String input[3];
if( InputQuery("paied check", EXISTINGARRAY(prompt), EXISTINGARRAY(input)) )
{
//...
}
Or:
String input[3];
if( InputQuery("paied check", OPENARRAY(String, ("value 1:", "value2:", "value 3:")), EXISTINGARRAY(input)) )
{
//...
}
Notice the use of the OPENARRAY()/EXISTINGARRAY() macros (from sysopen.h). They are needed because InputQuery() only accepts Delphi-style Open Arrays, not C-style arrays. Open Arrays have an additional parameter (that is hidden in Delphi, but is explicit in C++) to specify the highest index (not the array count) of each array. The macros handle that extra value for you, but they only work for static arrays (which you are using).

Create PDF in Swift

I am following Apple's Docs to create a PDF file using Xcode6-Beta6 in Swift
var currentText:CFAttributedStringRef = CFAttributedStringCreate(nil, textView.text as NSString, nil)
if (currentText) { // <-- This is the line XCode is not happy
// More code here
}
Compiler throws Type 'CFAttributedStringRef' does not conform to protocol 'BooleanType' error
If I use if(currentText != nil) I get 'CFAttributedStringRef' is not convertible to 'UInt8'
From Apple's Docs for CFAttributedStringCreate
Return Value
An attributed string that contains the characters from str and the attributes specified by attributes. The result is NULL if there was a problem in creating the attributed string. Ownership follows the Create Rule.
Any idea how to resolve this? Thanks!
First you have to give it an explicit optional type (using the ?):
var currentText: CFAttributedStringRef? = ...
Then you can compare it to nil:
if currentText != nil {
// good to go
}
Your code compiles at the moment, because Apple hasn't yet "swiftified" CoreFoundation to return properly annotated types.
Be prepared that in the final release your code will not even compile, forcing you to use the optional type.

Object.ReferenceEquals returns incorrect results (in Silverlight 3 at least)

I just discovered a very strange behaviour. I have a class with a string property. In the setter of this property I compare the old value with the new value first and only change property if the values differ:
set
{
if ((object.ReferenceEquals(this.Identifier, value) != true))
{
this.Identifier = value;
this.RaisePropertyChanged("Identifier");
}
}
But this ReferenceEquals almost always returns false! Even if I call object.ReferenceEquals("test", "test") in Quick Watch I get false.
How is this possible?
That's because strings are immutable in C#:
The contents of a string object cannot
be changed after the object is
created, although the syntax makes it
appear as if you can do this.
Since you can't modify an existing string reference, there's no benefit in reusing them. The value passed to your property setter will always be a new string reference, except maybe if you do this.Identifier = this.Identifier;.
I'll try to clarify with an example:
string s = "Hello, "; // s contains a new string reference.
s += "world!"; // s now contains another string reference.

Resources