Forum > Windows
GetConsoleTitle with pchar as argument ?
Nitorami:
GetConsoleTitle works with a shortstring as parameter but not with a pchar. Why ?
--- 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";}};} ---{$H-}uses windows; var s: shortstring; p: pchar;begin writeln; s := '##########################################################################'; writeln ('GetTitle returns ',GetConsoleTitle (@s[1],50)); //works writeln (s+LineEnding); p := '##########################################################################'; writeln ('GetTitle returns ',GetConsoleTitle (p,50)); //doesn't work writeln (p+LineEnding); writeln ('GetTitle returns ',GetConsoleTitle (@p[0],50)); //doesn't either writeln (p+LineEnding);end.
Output:
Running "c:\temp\getconsoletitle.exe "
GetTitle returns 24
Eingabeaufforderung - fp #################################################
GetTitle returns 0
##########################################################################
GetTitle returns 0
##########################################################################
Red_prig:
Because pchar is a reference to data, first allocate the memory and put the reference in p, then when the data is no longer needed, free it accordingly
Nitorami:
Understood, but I initialised p with p := '####....', so it must have been allocated at a speciifc address ?
Red_prig:
'####....' is a constant and is write-protected
Nitorami:
You mean the content of pchar is stored in a specific write-protected area of memory which the API function cannot write to ?
Navigation
[0] Message Index
[#] Next page