Hi Charles,
for EM_GETLINE...
lets say "word CharCount = 7" and
"string sText = nuls CharCount"
then if I write
"word WordValue at strptr(sText) = CharCount"
it won't work
I have to do it on separate lines
"word WordValue at strptr(sText)"
"WordValue = CharCount"
Is this normal behavior ?
Thanks
Hi Pierre
may i ask you why you use type WORD ?
hey Pierre
i think that this is not valid ???
word WordValue at strptr(sText) = CharCount
but this should be i am not sure 7 nulls
'pierre
word CharCount = 7
string sText = nuls CharCount ' "0000000"
word WordValue at strptr(sText) ' CharCount
WordValue = CharCount
print stext
Yes Pierre, this is normal behavior when setting up a pointer variable, then assigning values to it. Are you working with wide strings?
Hi Charles and Aurel,
I work with both wstring and string.
For this question I wrote a demo that do not use wide character.
I made different variation of "word WordLen at strptr(sText) = CharCount"
Look for "choice" in code
I got a non assigned value in one case, I got a gpf on reassigment try,
and a good result which the normal behavior, now that I'm aware of it.
Thank for the answer.
Note: If you revisit the help file, might be good to say
that "sText = string(CharCount, 0) 'zero to nine "
is the equivalent of "sText = string(CharCount, "0")"
and to obtain a string made of nul like
"sText = nuls(CharCount)" you have to add "chr()" like in
"sText = string(CharCount, chr(0))"
//KickResource "D:\Dev\Oxygen\o2\~code\~~~Resource.res" //kick add a manifest for CommonControl-6
//KickSwitch -32 //compile to 32bit
//KickEnd //optional, end of kick instructions
% Edit01 102
% lText01 201
% CheckboxTopMost 301
% DEFAULT_GUI_FONT 17
% GCL_HICON -14
% SWP_NOSIZE 1
% HWND_NOTOPMOST 0xFFFFFFFE
uses dialogs
'____________________________________________________________________________
function DialogProc(sys hDlg, uint uMsg, sys wParam, lParam) as int callback
select case uMsg
case WM_INITDIALOG
sys hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 294) 'o
SetClassLongPtr(hDlg, GCL_HICON, hIcon)
sys hEdit = GetDlgItem(hDlg, Edit01)
sys hFont = CreateFont(14, 0, 'Height 14 = 9, 16=12, 15=11, 14=11, Width usually 0,
0, 0, 'Escapement(angle), Orientation
0, 0, 0, 0, 'Bold, Italic, Underline, Strikethru
0, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FF_DONTCARE, "Consolas") 'Fixed width font ("Segoe UI", 9 Arial Consolas)
SendMessage(hEdit, WM_SETFONT, hFont, 0)
SendMessage(GetDlgItem(hDlg, IDCANCEL), WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT), 0)
SendMessage(GetDlgItem(hDlg, lText01), WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT), 0)
SendMessage(GetDlgItem(hDlg, CheckboxTopMost), WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT), 0)
PostMessage(hEdit, %EM_SETSEL, -1, 0) 'Set caret at the end of text
return true
case WM_COMMAND
select case loword(wParam)
case IDCANCEL
if hiword(wParam) = BN_CLICKED OR hiword(wParam) = 1
EndDialog(hDlg, null)
end if
case Edit01
if hiword(wParam) = EN_CHANGE 'OR hiword(wParam) = 1
word CharCount = SendMessage(GetDlgItem(hDlg, Edit01), EM_LINELENGTH, 0, 0)
string sText = nuls(CharCount)
if CharCount = 1 then CharCount = 2 'EM_GETLINE need at least 2 to work on a one char string,
'--------------------------------------
long choice = 2 'try 1, 2, or 3
'-
if choice = 1 'bad, value is not assigned to CharCount
word WordLen at strptr(sText) = CharCount
end if
'-
if choice = 2 'ok, value is assigned to CharCount
word WordLen at strptr(sText)
WordLen = CharCount
end if
'-
if choice = 3 'gpf, reassigmnet will gpf
word WordLen at strptr(sText) = CharCount
WordLen = CharCount
end if
'--------------------------------------
long retval = SendDlgItemMessage(hDlg, Edit01, EM_GETLINE, 0, STRPTR(sText))
SetWindowText(GetDlgItem(hDlg, lText01), "[" + sText + "] len " & str(len(sText)) & ", count from em_getline " & str(retval))
end if
case CheckboxTopMost
if hiword(wParam) = BN_CLICKED OR hiword(wParam) = 1
if IsDlgButtonChecked(hDlg, CheckboxTopMost) then
SetWindowPos(hDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)
else
SetWindowPos(hDlg, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)
end if
end if
end select
case WM_CLOSE
EndDialog(hDlg, null)
case WM_DESTROY
DeleteObject(hFont)
DestroyIcon(hIcon)
end select
return 0
end function
'______________________________________________________________________________
sub winmain()
Dialog(0, 0, 155, 30, "edit EM_GETLINE", WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | DS_CENTER, WS_EX_LEFT)
EditText("123456", Edit01, 05, 05, 80, 10)
Ltext("try choice 1, 2, 3 in code", lText01, 5, 18, 100, 10, SS_NOTIFY, ws_ex_staticedge, 0) 'ws_ex_windowedge) 'ws_ex_clientedge) 'ws_ex_staticedge)
PushButton("&close" , IDCANCEL, 110, 5, 40, 10)
AutoCheckBox("topmost" , CheckboxTopMost, 110, 18, 40, 10)
CreateModalDialog(null, @DialogProc, 0)
end sub
'______________________________________________________________________________
winmain()
'______________________________________________________________________________
'
Quotethat "sText = string(CharCount, 0) 'zero to nine "
is the equivalent of "sText = string(CharCount, "0")"
O2 automatically converts string parameters into numbers and numbers into strings to match the function prototype.
This is what happens with
string(Charcount,n): In this case n gets converted into a string, as if you had used
string(Charcount,str(n) )O2 performs automatic type conversion for all primitive types in an expression, including integers, floats and strings. It works well in most instances but occasionally produces unintended results!