How to Pass FolderItem

How to make a folderitem global?
The customer will be browsing to a pic, then hitting print
which will place that pic in position on a sheet to be printed.

I’ve done this before with a tsv:

[code]Dim f As FolderItem = GetOpenFolderItem(tsv)

If f <> Nil Then
CountFile.Text = f.NativePath[/code]

And then this to access the found file:

Dim f As FolderItem = GetFolderItem(CountFile.Text , 3)

What is a better way?

Thanks

[quote=158302:@Joel Godin]How to make a folderitem global?
The customer will be browsing to a pic, then hitting print
which will place that pic in position on a sheet to be printed.

I’ve done this before with a tsv:

[code]Dim f As FolderItem = GetOpenFolderItem(tsv)

If f <> Nil Then
CountFile.Text = f.NativePath[/code]

And then this to access the found file:

Dim f As FolderItem = GetFolderItem(CountFile.Text , 3)

What is a better way?

Thanks[/quote]

Add a f FolderItem property to a module, make it global, and instead of dim, go

[code] [code]f = GetOpenFolderItem(tsv)

If f <> Nil Then
CountFile.Text = f.NativePath[/code][/code]

Be careful not to reuse the same f property without making sure it is not needed anymore elsewhere. That is the big problem with global variables, bugs can be created by modifying variables you expect somewhere else to have another value.

Sweet. That worked.
Just learning, so for each global item I want, I have to create a module?
Thanks.

[quote=158313:@Joel Godin]Sweet. That worked.
Just learning, so for each global item I want, I have to create a module?
Thanks.[/quote]
No, you can put your globals into one module.

[quote=158313:@Joel Godin]Sweet. That worked.
Just learning, so for each global item I want, I have to create a module?[/quote]

No need to use several modules. A module can hold as many properties as you want, as well as methods that can be made global as well.

I see, thanks Markus and Michel.

Just think about wether they really should be global or maybe should be window properties :wink:

Ah yes, I think that is what I want. Just needs to be seen by the window.

[quote=158313:@Joel Godin]Sweet. That worked.
Just learning, so for each global item I want, I have to create a module?
Thanks.[/quote]

Hello,

No, you can store as many properties and methods as you want in a module. But that’s not always ideal.

For example, in large projects people tend to use different modules to organize things within the project.

Also, if you are going to reuse part of your code in another application it is easier to streep it out if you have the code for a certain task sepparated from the rest.

Julen

I see Julen. So for example if I had a long list of labels, I could put those in a module.
(separate question I know, but I have a project with about 160 labels.)

[quote=158321:@Joel Godin] So for example if I had a long list of labels, I could put those in a module.
(separate question I know, but I have a project with about 160 labels.)[/quote]

In that case use an array of labels or a dictionary depending on your needs. I try to avoid declaring globals in modules and follow OOP encapsulation paradigm of self contained and independent/reusable classes. Shared Properties or Getters/Setters (computed properties) are very useful, specially when dealing with large projects.

Just remember, when the window goes out of scope, so do all of its contents

Thanks Amando, I will bone up on array of labels and dictionaries then. More used to C, so getting used to OOP and it’s paradigms.
Thanks Dave on the window scope.
Thanks to all for your answers, very helpful.

Now you know how to do it, learn to do it better:

Use a real, meaningful name to the Property istead of f.

When you will read this code later, you will know what this FolderItem Property is for… just reading its name. You will never know if you keep f.

Isn’t Xojo nice ?