Forum > General
New wrapper for 7zip
rvk:
--- Quote from: domasz on October 07, 2024, 03:05:42 pm ---Not really. The same line is called just before in a different procedure (Open). So there are always 2 items to unpack and it does unpack them.
So calling this line once (in Open)- works. Twice (Open, then Extract)- doesn't work. Moving this line from Open to Extract- also doesn't work.
Procedure Extract is called immediately after Open.
--- End quote ---
Ha, I see what you mean now.
Seems like "SetLength(FSelectedItems, 2)" in that .Extract is overwrting something (which is strange).
BTW. Why is TSevenUnpack inherited from TCustomControl which is a TWinControl.
It doesn't need to have width/length and parent does it?
Maybe that's the problem. You didn't assign a parent.
I would still just do this if it doesn't need to have form presence (and then it can be used with plain FPC too).
--- 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";}};} ---TSevenUnpack = class(TComponent)
domasz:
Sure, it can inherit from TComponent but that doesn't change the crash.
rvk:
--- Quote from: domasz on October 07, 2024, 03:31:08 pm ---Sure, it can inherit from TWinControl but that doesn't change the crash.
--- End quote ---
Na, but it can introduce some problems down the road.
TWinControl normally needs a form as parent.
Without it, it can cause problems (at least that is my experience with Delphi).
If you don't do anything with parent, width, top, left etc (i.e. doesn't need a form component) you can better inherit from TComponent (which still has an Owner but not a Parent !!).
(Parent and Owner are different, Parent is for screen, Owner is for Create/Free)
Also do correct create and free in your buttonpress because now you don't release anything after the first press of the button.
--- 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 TForm1.Button1Click(Sender: TObject);begin Seven := TSevenUnpack.Create(nil); // <-- this can be nil if not created by the TForm itself (and because you free it yourself) try Seven.OnNextFile := @Next; Seven.OnNextFileClose := @NextClose; Seven.OnFileProgress := @Progress; Seven.OnPasswordNeeded := @Pass; F := TFileStream.Create('test2.7z', fmOpenRead); Seven.Open(F); Seven.Extract; finally Seven.Free; end;end;
It doesn;t fix the crash but the flow is better like this.
rvk:
Sorry about my previous post.
Your Seven is a TForm variable and you use it in Button2... so you DO NEED to create it in FormCreate, not in Button1.Click.
So:
--- 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 TForm1.FormCreate(Sender: TObject);begin Seven := TSevenUnpack.Create(Self);end; procedure TForm1.Button1Click(Sender: TObject);begin Seven.OnNextFile := @Next; Seven.OnNextFileClose := @NextClose; Seven.OnFileProgress := @Progress; Seven.OnPasswordNeeded := @Pass; F := TFileStream.Create('test2.7z', fmOpenRead); Seven.Open(F); Seven.Extract;end; procedure TForm1.Button2Click(Sender: TObject);begin Seven.CancelNow;end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin F.Free; // Seven.Free; // is done by TForm because of the Create(Self)end;
domasz:
It's not the cleanest code, just for testing the class. But good points, sure.
ProgressCallback is most likely called from another thread by the DLL. Perhaps I should do something to synchronize access. But PostMessage won't work here (it's a class, not a form).
Navigation
[0] Message Index
[#] Next page
[*] Previous page