Forum > General
New wrapper for 7zip
rvk:
I can't put my finger on it but I think somehow it has to do with the interfaces you use.
(using interfaces needs a whole other way of thinking, especially that it's not the same as instances of classes)
For example, if you move the FHandle I7zInArchive to the Extract() itself... it works.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TSevenUnpack.Extract(Str: TStream);begin FHandle := CreateInArchive(CLSID_CFormat7z); FHandle.SetPasswordCallback(@Self, @PasswordCallback); FHandle.OpenStream(T7zStream.Create(Str, soReference)); FHandle.SetProgressCallback(@Self, @ProgressCallback); SetLength(FSelectedItems, 2); //uncommenting this causes a crash FSelectedItems[0] := 0; FSelectedItems[1] := 1; FHandle.ExtractItems(@FSelectedItems[0], Length(FSelectedItems), false, @Self, @GetStreamCallback); if FPrevFile <> nil then FOnNextFileCloseEvent(FPrevFile);end;
Otherwise... I think FHandle is freed before coming to Extract (or something).
And that's not a problem if you don't do anything with memory (because the memory is still the same)
but if you are re-getting the memory for FSelectedItems on the heap, the FHandle part is corrupted/overwritten.
(Interfaces are not my second nature so I can't be certain about above)
domasz:
Interesting, thanks!
rvk:
Also interesting is that if you set "Range check" or "Verify method calls" to true in your project, your progress isn't executed.
(It fails silently, somehow FCancel is set to True in that case, without you doing so)
I normally set all the "Checks and assertions" and include Heaptrc during testing.
If it runs in that case, you can leave them out in the final code.
Your project does not run with "Range" and "Verify method calls" set.
(even if you comment out said line)
domasz:
I introduced global variable PPP: TSevenUnpack;
Then:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TSevenUnpack.Open(Str: TStream);begin FHandle.SetPasswordCallback(@Self, @PasswordCallback); FHandle.SetProgressCallback(@Self, @ProgressCallback); FHandle.OpenStream(T7zStream.Create(Str, soReference)); PPP := Self; SetLength(FSelectedItems, 2);end;
then in ProgressCallback:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- Seven := Ppp;
Now it works even with 2xSetLength and "Range" and "Verify method calls". But global variable isn't a nice solution.
rvk:
--- Quote from: domasz on October 07, 2024, 08:02:10 pm ---Now it works even with 2xSetLength and "Range" and "Verify method calls". But global variable isn't a nice solution.
--- End quote ---
That still makes sender in the ProgressCallback(sender: Pointer) an invalid or corrupt value.
So it does seem like an ugly hack to fix the issue ;)
Navigation
[0] Message Index
[*] Previous page