local/global variables?
-
=f.Name; x += 1; } } ------------------------------------------------------------- if ( sExt == "zip") { OpenZip(sFull); ShowImage(num); } How can I access the zip instance from the ShowImage() function? :-O Thx for the help.:)
you could try using the singleton pattern. Have an external singleton class hold the instance of open zip file, access the instance from both functions.
class ZipHolder { private ZipHolder() { } private ZipArchive zip = null; public ZipHolder Instance = new ZipHolder(); public void Open(string name) { zip = new ZipArchive(name); .... } public ZipArchive Zip { get { return zip; } } }
you can then access the Open thus: ZipHolder.Instance.Open("myzip.zip"); and the open zip file by ZipHolder.Instance.Zip. Gary
-
you could try using the singleton pattern. Have an external singleton class hold the instance of open zip file, access the instance from both functions.
class ZipHolder { private ZipHolder() { } private ZipArchive zip = null; public ZipHolder Instance = new ZipHolder(); public void Open(string name) { zip = new ZipArchive(name); .... } public ZipArchive Zip { get { return zip; } } }
you can then access the Open thus: ZipHolder.Instance.Open("myzip.zip"); and the open zip file by ZipHolder.Instance.Zip. Gary
Thanks for the help :D However...when I try using the code I get this error: 'mrmanga.ZipHolder.ZipHolder()' is inaccessible due to its protection level Any idea? --- edit --- Also, when i try making ZipHolder() public, I get this: An unhandled exception of type 'System.StackOverflowException' occurred in mrmanga.exe
-
Thanks for the help :D However...when I try using the code I get this error: 'mrmanga.ZipHolder.ZipHolder()' is inaccessible due to its protection level Any idea? --- edit --- Also, when i try making ZipHolder() public, I get this: An unhandled exception of type 'System.StackOverflowException' occurred in mrmanga.exe
Hi, Sorry I wasn't clear, and I think it lost some of the information I added in a tag. Ok. To open the zip file ZipHolder.Instance.Open("zipfile.zip"); To access the instance of ZipArchive (held inside the ZipHolder)
public void ShowImage(int theNum) { AbstractFile imageFile = ZipHolder.Instance.Zip.GetFile(zipFiles[num]); if (imageFile.Exists) { using( Stream stImage = imageFile.OpenRead() ) { pbMain.Image = Image.FromStream(stImage); } } }
etc.. Gary
-
Hi, Sorry I wasn't clear, and I think it lost some of the information I added in a tag. Ok. To open the zip file ZipHolder.Instance.Open("zipfile.zip"); To access the instance of ZipArchive (held inside the ZipHolder)
public void ShowImage(int theNum) { AbstractFile imageFile = ZipHolder.Instance.Zip.GetFile(zipFiles[num]); if (imageFile.Exists) { using( Stream stImage = imageFile.OpenRead() ) { pbMain.Image = Image.FromStream(stImage); } } }
etc.. Gary
-
:D! Ahh worked like a charm! Took me a little modding (had to throw in a static, and change string to abstractfile) but sure enough, it works :) I can't thank you enough. Thanks ^^