Forum > Beginners
open file
scons:
ok another problem
I have a ListBox and I want to open the selected file on double click, with the standard windows program.
this is my code:
--- 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.ListBox1DblClick(Sender: TObject);var i: integer;begin for i:=0 to ListBox1.Count -1 do if ListBox1.ItemIndex = 1 then ShellExecute(Form1.Handle, PChar('open'),PChar(ListBox1.ItemIndex), PChar(''), PChar(''), 1);end;
nothing happens, no error code.
what did I mess up this time ?
FTurtle:
--- 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.ListBox1DblClick(Sender: TObject);var i: Integer; s: UnicodeString;begin i := ListBox1.ItemIndex; if i<0 then Exit; // -1 means there is no selected item s := ListBox1.Items[i]; ShellExecute(Handle, PWideChar('open'),PWideChar(s), PWideChar(''), PWideChar(''), 1);end;
scons:
Your solution gave me an error, but, when I changed it to:
--- 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.ListBox1DblClick(Sender: TObject);var i: Integer; s: UnicodeString;begin i := ListBox1.ItemIndex; if i<0 then Exit; // -1 means there is no selected item s := ListBox1.Items[i]; ShellExecute(Handle, PChar('open'),PChar(s), PChar(''), PChar(''), 1);end;
it works !!
Thank you for pointing me in the right direction FTurtle
Bart:
Casting a UnicodeString to PChar makes no sense to me?
Bart
balazsszekely:
It should be more like this:
--- 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.ListBox1DblClick(Sender: TObject);var I: Integer; WS: WideString;begin I := ListBox1.ItemIndex; if I < 0 then Exit; WS := WideString(ListBox1.Items[I]); //or UTF8ToUTF16(ListBox1.Items[I]) from LazUTF8 ShellExecuteW(Handle, PWideChar('open'), PWideChar(WS), PWideChar(''), PWideChar(''), SW_SHOW);end;
Navigation
[0] Message Index
[#] Next page