Take value of a variable highlighted in PB IDE [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5528
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Take value of a variable highlighted in PB IDE [Resolved]

Post by Kwai chang caine »

Hello at all

is there a way for put in clipboard the value of a variable highlighted in the IDE of PB ?
Thanks to this code of MESA that i have simplified, i take the name of the variable highlighted 8)

viewtopic.php?p=595584#p595584

Code: Select all

Global PbIdeHandle, ScintillaHandle
Global classText.s = Space(256), SelectedWord.s

Procedure.s GetScintillaText()
	Protected ReturnValue.s
	Protected length
	Protected buffer
	Protected processId
	Protected hProcess
	Protected result

	length = SendMessage_(ScintillaHandle, #SCI_GETLENGTH, 0, 0)
	If length
		length + 2
		buffer = AllocateMemory(length)
		If buffer
			SendMessageTimeout_(ScintillaHandle, #SCI_GETCHARACTERPOINTER, 0, 0, #SMTO_ABORTIFHUNG, 2000, @result)
			If result
				GetWindowThreadProcessId_(ScintillaHandle, @processId)
				hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #False, processId)
				If hProcess
					ReadProcessMemory_(hProcess, result, buffer, length, 0)
					ReturnValue = PeekS(buffer, -1, #PB_UTF8)
					CloseHandle_(hProcess)  ; <-- Axolotl, added acc. to MSDN
				EndIf
			EndIf
		EndIf
		FreeMemory(buffer)
	EndIf
	ProcedureReturn ReturnValue
EndProcedure

; Finding the Scintilla
Procedure.l enumChildren0(hwnd.l)
	If hwnd
		GetClassName_(hwnd, @classText, 256)
		If classText = "WindowClass_2"
			GetWindowText_(hwnd, @classText, 256)
			If Left(classText, 9) = "PureBasic"
				PbIdeHandle = hwnd
				ProcedureReturn 0
			EndIf
		EndIf
		ProcedureReturn 1
	EndIf
	ProcedureReturn 0
EndProcedure

Procedure.l enumChildren1(hwnd.l)
	If hwnd
		GetClassName_(hwnd, @classText, 256)
		If classText = "Scintilla"
			ScintillaHandle = hwnd
			ProcedureReturn 0
		EndIf
		ProcedureReturn 1
	EndIf
	ProcedureReturn 0
EndProcedure

Procedure Initialization()

	PbIdeHandle = Val(GetEnvironmentVariable("PB_TOOL_MainWindow"))

	ScintillaHandle = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))

	SelectedWord.s = GetEnvironmentVariable("PB_TOOL_Word")
	ScintillaText.s = GetScintillaText()

	CursorLine = Int(Val(StringField(GetEnvironmentVariable("PB_TOOL_Cursor"), 1, "x")))

	ProcedureReturn 0  ; default (ZERO is returned by default, even if there is no ProcedureReturn)
EndProcedure

Initialization()
ScintillaText.s = GetScintillaText()
MessageRequester(Trim(Str(@SelectedWord)), SelectedWord)
But how ask to the compiler/debugger the value of a variable by his name ? :oops:

Have a good day
Last edited by Kwai chang caine on Sat Sep 30, 2023 7:16 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5528
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Take value of a variable highlighted in PB IDE

Post by Kwai chang caine »

I nearly answer myself to my question :D
Like apparently nobody know how ask to PB the value of a variable, i say to me :
"A way is to remote the DebugWindow :idea: "
Because in this case...the Debug Window is like GOOGLE...she is my friend and know all :D

So i have create this cowpat code like only KCC know do that :mrgreen:

1/ SendKey F12 (Open Debug window)
2/ Clic on clear all text button of the debug window
3/ Take the text selected in the IDE thanks to Scintilla (In this case the variable)
4/ Writing the name of variable on ComboBox at the bottom of the window debug
5/ Clic to the buton at the right of the combobox for show value of the variable in editor of the debug window
6/ Read the value in the editor of debug window, and put it in another variable
7/ Click to the button "copy" of the debug window for put the value of the variable in the Clipboard

And the MsgBox appears with the name of variable and his value, put also in the clipboard
It's far-fetched, but for the moment i not have better :oops:

If you want try this code, and not be French, change the text of buttons and WindowDebug in english
I don't know what is the english text, it's the reason why i leave alone the French text :oops:
After create an exe with this code and call it with a new personnal tools create for him :wink:

A thanks at Stargate for his part of code of Scintilla :wink: the rest is pretty much mine (With help of all the members, since all this years obviously :mrgreen: )

Code: Select all

Global HwndDebug, HwndEditDebug, TexteBouton.s

Procedure.l enumChildren(hwnd.l, lParam.l)

 If hwnd
   
  ChildText$ = Space(256) 
  ClassName$ = Space(256) 
  SendMessage_(hwnd, #WM_GETTEXT, 256, @ChildText$) 
  GetClassName_(hwnd, @ClassName$, 256) 
  
  If ChildText$ = TexteBouton And ClassName$ = "Button"
   Delay(100)
   SendMessage_(hwnd,#WM_LBUTTONDOWN,0,0)
   Delay(100)
   SendMessage_(hwnd,#WM_LBUTTONUP,0,0)
  EndIf
   
  ProcedureReturn 1
  
 Else
 
  ProcedureReturn 0
  
 EndIf
 
EndProcedure 

Procedure.l EnumWindows(WindowHandle.l, Parameter.l) 
  
 Title$ = Space(200) 
 GetWindowText_(WindowHandle, @Title$, 200) 
 
 If FindString(Title$, "Messages du débogueur - ", 1, #PB_String_NoCase ) <> 0
  HwndDebug = WindowHandle
  ProcedureReturn #False
 Else 
  ProcedureReturn #True
 EndIf 
 
EndProcedure

Define ScintillaID.i = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
SelectDebut = SendMessage_(ScintillaID, #SCI_GETSELECTIONSTART, #Null, #Null)
SelectFin = SendMessage_(ScintillaID, #SCI_GETSELECTIONNEND, #Null, #Null)

If SelectDebut 
 SelectFin - 1
EndIf 

VariableSelection$ = ""

For Position = SelectDebut To SelectFin
 VariableSelection$ + Chr(SendMessage_(ScintillaID, #SCI_GETCHARAT, Position, #Null))
Next

Delay(100)
keybd_event_(#VK_F12, 0, 0, 0)
Delay(100)
keybd_event_(#VK_F12, 0, #KEYEVENTF_KEYUP, 0)
Delay(400)

EnumWindows_(@EnumWindows(), 0)

If HwndDebug
 
 ShowWindow_(HwndDebug, #SW_HIDE)
 TexteBouton = "Tout retirer"
 EnumChildWindows_(HwndDebug, @enumChildren(), 0)
 Delay(200)
 HwndCombo = FindWindowEx_(HwndDebug, #Null, "ComboBox", #Null)
 HwndComboEdit = FindWindowEx_(HwndCombo, #Null, "Edit", #Null)
 HwndEditDebug = FindWindowEx_(HwndDebug, #Null, "RICHEDIT50W", #Null)
 SendMessage_(HwndComboEdit, #WM_SETTEXT, 0, @VariableSelection$)
 TexteBouton = "Afficher"
 EnumChildWindows_(HwndDebug, @enumChildren(), 0)
 
 While Valeur$ = ""
  Delay(100)
  Valeur$ = Space(256)
  SendMessage_(HwndEditDebug, #WM_GETTEXT, 256, @Valeur$)
 Wend
 
 TexteBouton = "Copier tout"
 EnumChildWindows_(HwndDebug, @enumChildren(), 0)
 ShowWindow_(HwndDebug, #SW_SHOW)
 PostMessage_(HwndDebug, #WM_SYSCOMMAND, #SC_CLOSE, 0)
 MessageRequester("", "The value of ''" + VariableSelection$ + "'' is ''" + Valeur$ + "''", #MB_SYSTEMMODAL)
  
Else
 
 MessageRequester("", "La fenetre Debug n'a pas été trouvée")
 
EndIf

; Scintilla utilisation[Stargate]IDE position du curseur v4.51 [Stargate] = http://www.purebasic.fr/english/viewtopic.php?p=377768#p377768
ImageThe happiness is a road...
Not a destination
Post Reply