C++ Builder XE2 - linking resource with component - embedded-resource

I have derived my own component based on class TCustomControl. I need to embedd into component bitmap resource stored in .png format. I added to project file resources.rc with this content:
AP_LOGO RCDATA .\AP_logo_RGB_transparent.png
Compilation was successfull. Component is statically linked to project. When I run the application it throws following error when trying to access embedded resource:
Project raised exception class EResNotFound with message 'Resource AP_LOGO not found'.
The following lines in source code access bitmap resource:
Graphics::TBitmap *bmp = new Graphics::TBitmap();
HINST handle = FindClassHInstance(__classid(TVctDiag2));
bmp->LoadFromResourceName(handle, L"AP_LOGO"); // <----- exception apppers there
When I open executable with resource editor there isnt any resource named 'AP_LOGO'. Why?

It does not work because the TBitmap::LoadFromResource...() methods look for BITMAP resources only, but you have defined an RCDATA resource instead. If you don't change your resource type then you will have to use TResourceStream instead, eg:
HINST handle = FindClassHInstance(__classid(TVctDiag2));
TResourceStream *strm = new TResourceStream(handle, L"AP_LOGO", RT_RCDATA);
Graphics::TBitmap *bmp = new Graphics::TBitmap();
bmp->LoadFromStream(strm);
delete strm;
With that saif, you cannot load a PNG resource into a TBitmap to begin with. If you must use a PNG resource then you have to use a PNG class instead, like TPngImage.

Related

fx:include when resources are in a different JAR

I created a framework which opens FXML in other jar files. I use the following to open them:
(fxml) is a string passed in from a DB query...
FXMLLoader loader = new FXMLLoader();
Parent node = loader.load(getClass().getClassLoader().getResource(fxml).openStream());
This works for all my FXML and I really don't want to change this.
I have one new window which will have a very similar implementation with another and I wanted to share the FXML between them with fx:include.
However this throws the error javafx.fxml.LoadException: Base location is undefined.
I found this link about linked files
Is there anyway around this - without changing my entire implementation? If not, likely will just duplicate the logic.
Thanks.
The problem is that if you provide an InputStream, the location (a URL) is undefined. Apparently your FXML is using the location somewhere (e.g. via location resolution) Try
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(fxml));
Parent node = loader.load();

Extracting data from owl file using java,gwt,eclipse

I have to display content from the owl file namely the class names.. onto my browser, I am using GWT,eclipse to do so, could some one tell me the following :-
1)how do I integrate the owl file with the eclipse project?
2)How do I run queries from my java project to extract class names from the owl file?
3)Where can I get the protege api to nclude into my project?!
You could just store your .owl file anywhere inside your project or on any other location on your harddrive. You just provide a path to it, when you load/store it (see code below).
Take a look at the OWLAPI, it allows you to load an existing ontology and retrieve all classes from it. Your code could look like this:
private static void loadAndPrintEntities() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI documentIRI = IRI.create("file:///C:/folder/", "your_rontology.owl");
try {
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(documentIRI);
//Prints all axioms, not just classes
ontology.axioms().forEach(a -> System.out.println(a));
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
}
Rather than trying to integrate the Protegé API into your project, I suggest you write a plugin for Protegé. There are some great examples that should get you started. Import this project into Eclipse, modify the content, build your plugin and drop it into Protegé. That's it, you're ready to go!

Generate code from Metamodel via XTend

I have an Ecore model in an existing EMF project and want to print the name of all containing classes into a text file via XTend. How do you achieve this? The XTend examples don't show how to use a model and get Information out of it.
If you only need the EClasses of your Meta-Model then you can get them from your Model Package:
YourEMFModelPackage.eINSTANCE.getEClassifiers() which returns a EList<EClassifier>. Since an EClass is an EClassifier you get all your EClass implementations org.eclipse.emf.ecore.impl.EClassImpl.
For type-safety concerns you probably check if this List only contains EClasses, since all your EDataTypes are also EClassifier.
So this should to the Trick:
EcoreUtil.getObjectsByType(YourEMFModelPackage.eINSTANCE.getEClassifiers(), EcorePackage.eINSTANCE.getEClass())
or:
List<EClass> allEClasses = YourEMFModelPackage.eINSTANCE.getEClassifiers().stream().filter(p -> EClass.class.isInstance(p)).map(m -> EClass.class.cast(m)).collect(Collectors.toList());
Update:
If you don't have your Model-Code generated you're still able to do this, you only need to load your Ecore into a Resource:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
new EcoreResourceFactoryImpl());
Resource resource = resourceSet.getResource(
URI.createFileURI(
"../path/to/your/Ecore.ecore"),
true);
EPackage model = (EPackage) resource.getContents().get(0);
If you have the EPackage then you get your EClass like mentioned above

Using resource files (CultureInfo) in C# class file

I need a help with using resource files in C# class files.
My code:
class errorMessages
{
private static ResourceManager LocRM = new ResourceManager("Project1.languageFile", typeof(errorMessages).Assembly);
public static void XMLParseError(String msg)
{
MessageBox.Show(LocRM.GetString("XMLParseError") + "\n" + msg, LocRM.GetString("error"),
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
+ created 2 .resx files named languageFile.en.resx and languageFile.pl-PL.resx in main Project1 folder
Now I want to use String from languageFile, in my class errorMessages, specified to localization which was set before. How can I do it?
I tried to add my Strings to WinForm .resx file, but that's clearing my data with any edit of WinForm.
I found answer for my question by myself, so I will write that solution, I hope it will help somebody.
Default resources file is located in [projectName]/Properties. I you want to add manually localizable resource files, you need to do that this way:
right click on Project in Solution Explorer -> Add new item -> resource file
Then set the name of file to Resources.[language].resx - in my case that are two files, Resources.pl-PL.resx and Resources.en.resx. After file is created, move it to Properties directory.
Now you can add your resources and use it this way:
MessageBox.Show(Project1.Properties.Resources.XMLParseError, Project1.Properties.Resources.information,
MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
Now chosen String will be in language setted in CultureInfo, or, if there is no that resource, default Resource file will be used.
source: MSDN - How to: Create a Localized Version of a Resource File

Can't save state in windows 8 [ Error The type or namespace name 'Common'

Can't save state in windows 8
{
Error The type or namespace name 'Common' ...does not exist in the namespace 'ProjectName' (are you missing an assembly reference?)
}
Everything below is the default code in my App.Xaml.cs file the only line I added was
ProjectNameSpace.Common.SuspensionManager.RegisterFrame(rootFrame, "appframe");
which is from the windows 8 tutorial here and I have followed part 1 before attempting this http://msdn.microsoft.com/en-us/library/windows/apps/hh986968.aspx. I have it working in another project that has the same references and using statements. There is only one namespace in the project and I even Rebuilt/Cleaned. Does anybody have any extra information?
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
ProjectNameSpace.Common.SuspensionManager.RegisterFrame(rootFrame, "appframe");
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
}
Window.Current.Content = rootFrame;
EDIT:
The problem was that I needed to add a basic page in my blank template. This auto generates some classes needed to do basic functionality. Below is a screenshot of the minimum items that the common folder needs to contain.
Do you have the Common folder present in your project? This folder is usually included in the Visual Studio 2012 App project templates (except the Blank App template) which contains a bunch of classes with boilerplate code for layout, styles and other functionality.
If you created your project with a Blank App template, you may not have this. To get it included, create a new Basic Page (Right-click on your Project > Add > New Item > (Visual C#)* > Basic Page), and Visual Studio will ask if you would like to create these files.
*I'm not sure what this is for VB .NET or WinJS, but I assume it would be the same structure.