F0O@psuvm.psu.edu (06/05/91)
Hi netters! I'm new to Windows programming and I was trying to modify the STEP3.PAS example program that comes with TPW. I was changing the WMLButtonDown method. The original routine looks like this: Procedure TMyWindow.WMLButtonDown(Var Msg:TMessage); VAR DC: HDC; S: array[0..9] of char; BEGIN WVSPrintF(S, '(%d,%d)', Msg.LParam); DC := GetDC(HWindow); TextOut(DC, Msg.LParamLo, Msg.LParamHi, S, StrLen(S)); ReleaseDC(HWindow, DC); END; This of course works fine, but I modified the code in the following way so I could print some text instead of a number: Procedure TMyWindow.WMLButtonDown(Var TextString: PChar); VAR DC: HDC; S: PChar; BEGIN WVSPrintF(S, '%s', TextString); DC := GetDC(HWindow); TextOut(DC, Msg.LParamLo, Msg.LParamHi, S, StrLen(S)); ReleaseDC(HWindow, DC); END; When Windows hits the WVSPrintF statement, I get a UAE. By running in the debugger, the UAE is reported as exception code 13, a memory addressing error. The problem must be that I'm not using PChar correctly, although the on-line help states all parameters of WVSPrintF are of type PChar and the manual shows examples of where you can put a text string into a variable of type PChar. If someone can tell me what I'm doing wrong, I'd greatly appreciate it! [Tim]
dsampson@x102a.harris-atd.com (sampson david 58163) (06/06/91)
In article <ONEEL.91Jun5145428@heawk1.gsfc.nasa.gov> oneel@heawk1.gsfc.nasa.gov ( Bruce Oneel ) writes: [main msg deleted] But who knows, this could be all wrong. bruce Yes it is wrong Bruce. He cross posted into the ms.windows.programmer group where I put a msg explaining why it crashes. Simply put, when he redefined S to be a *char, he never allocated any space for the string. Borland sets S up as an array, which does the allocation for you. When he tried to copy a string to the pointer, it crashed. -- A new world record in the javalin throw / / / I ------------------------------------------------- David Sampson Harris Corporation dsampson@x102a.ess.harris.com Gov't Aerospace Systems Divison uunet!x102a!dsampson Melbourne, Florida -------------------------------------------------------------------------------