If my customers delete CustomerLogo.png Xojo will not find it. Do I have to look for this file separately or how can I catch this error?
What do you mean by default CustomerLogo.png ? What does mean “will not start correctly” ? Seeing your code may help us figure out.
It’s way too complex. I simplified the question even further.
If you think/know they would then you can use SpecialFolder when your app is opening to check that all the files that your app needs are in place.
That’s what I thought.
If the icon is not displayed, that would be very bad.
So for each icon:
If TargetLinux Then f = GetFolderItem("../Icon1.png")
If TargetWindows Then f = GetFolderItem("./Icon1.png")
If f <> Nil Then
If f. Exists = false Then
That’s a lot of work.
Xojo can’t catch the error?
…
I placed the code in the open event but the App doesn’t start.
Do you get an error message ? Have you tried debugging the code in the Open Event, event step by step ?
Yes, that’s a lot of work.
I have seen some posts that instead of having the files in the Resource folder some people encode them and put them in constants in their programs, decoding the icons/images in the application.
Most likely the GetFolderItem will not work when you build your app, you should use SpecialFolder.
It does not work in any folder. The error raises before the open event.
If you can give more information about the error or share a sample project, we can try to find the problem.
The code is
g.DrawPicture(myPicture, 100, 120)
If the myPicture is missing, the error is:
The external item myPicture could not be found
If you get an error before the open event, it sounds as though you are saying that an icon which is supposed to be in the resources folder, is not there.
There are two reasons why that can happen.
One is that the customer has deleted it (why would they?)
The other is that your installer has not installed it.
Your code says
g.DrawPicture(myPicture, 100, 120)
So your app is expecting to find a picture called myPicture in the resources folder
You shouldnt have to use GetFolderItem to load it, if it is visible in your project when debugging.
If on the other hand, you show a different logo per customer, then you have a few options.
The easiest is to drag the pictures into your project at design time.
Customer1.png
Customer2.png and so on
At runtime, assuming you have installed the app correctly, there will be images of those names in the resource folder.
But your code only needs to do this:
if cuscode = "CUS1" then g.DrawPicture(Customer1, 100, 120)
if cuscode = "CUS1" then g.DrawPicture(Customer2, 100, 120)
Thank you Jeff.
Then i will explain the problem, again, from the beginning.
I deleted this because I didn’t think it would be useful.
My software is delivered to customers with a machine. Each customer can integrate their company logo into the software so that they appear on the printouts and in the software. It only does this once during commissioning.
The default logo named CompanyLogo.png is edited by the customer and replaced with their logo.
The name stays the same. That works perfectly.
However, if the customer makes a mistake and moves CompanyLogo.png or writes Companylogo.png, Xojo cannot find the file and triggers an error that I cannot correct at the moment
Then you need to make an interface for adding a logo. Give them a default logo and the something like “Upload your logo”. You need to handle all errors.
This interface is only used once in the lifetime of the product (20 years). Maybe I’ll look into that when I have time.
I found that the IDE does not start with the said error message.
The compiled exe does. But I can’t generate an error message.
If the CompanyLogo.png is missing, NO error message appears, but the space remains empty. I can live with that.
Thank you all
When your app starts, check whether the file exists.
(Peters example is correct for that…)
If TargetLinux Then f = GetFolderItem("../Icon1.png")
If TargetWindows Then f = GetFolderItem("./Icon1.png")
If f <> Nil Then
If f. Exists Then
myPicture = f.openaspicture //or similar.. syntax has changed over the years
else
myPicture = name_of_unbranded_icon_embedded_in_app
end if
end if
As already described, this does not work because the IDE generates the error BEFORE the open event.
g.DrawPicture(myPicture, 100, 120)
…cannot occur before the Open event.
So if you have an error before the open event, your project already has the picture embedded at design time.
Having the customer change the image inside of the resources folder is a bad plan.
Customers should not be messing about in resources,( it is read-only in Windows anyway.)
Change your code so that it uses a variable for the picture.
In the open event, populate that image by looking for it on disc.
You should be keeping the logo picture in
specialfolder.applicationdata.child(“yourapp”) folder
Changing the customer picture is changing the file you keep there, not the one in resources.
Load it from appdata, and use a fall back which is embedded in your app, if it is missing.
Thats a good idea!
Thanks!