April 23, 2024, 11:28:35 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


A reminder please - pointer to string

Started by Andy, January 28, 2021, 04:40:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

I have this structure for tab controls:

type TCITEM
  UINT   mask
  DWORD  dwState
  DWORD  dwStateMask
  LPSTR  pszText
  int    cchTextMax
  int    iImage
  LPARAM lParam
endtype
DEF tie as TCITEM

I have a sub routine to get the tab text:

SUB GetTabText(hWnd:window,cntID:int,index:int)
    tie.cchTextMax = 255
    SendMessage(hwnd,TCM_GETITEM,index,tie,cntID)
    'print len(tie.pszText)
return
ENDSUB

I want to assign a string to tie.pszText

i.e. MyString = tie.pszText

but I'm getting cannot assign pointer to string error.

What am I doing wrong please?

I can print the tab text in a console, but not assign a string to it.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

I think what you are looking for is:

MyString = <string>tie.pszText

Bill
When all else fails, get a bigger hammer.

Andy

Thanks Bill,

That didn't work sorry, thanks for trying.

I've managed to get around the need to get the tab text via API, but it still doesn't tell me how to get the tab text into a string.

Thanks again,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

I think I figured out what you wanted.

try:

string sblarp = "Testing Pointers Blarp"
pointer pblarp

pblarp = &sblarp

print *<STRING>pblarp

do:until inkey$<>""
END

Bill
When all else fails, get a bigger hammer.

ckoehn

This was in the help file:
QuoteRetrieving the value that is contained in the address, that is stored in the pointer is called dereferencing.  In some texts you may see it referred to as indirection. The IWBASIC compiler supports two general dereferencing operators, the # symbol and a 'C' style dereference operator, the '*'. The hash dereference '#' operator is unique to the IWBASIC language and is suitable for most basic pointer needs.

You can use Bill's way or use a # instead of a *.

STRING txt

txt = #<STRING>tie.pszText

Later
Clint

Andy

Thanks both of you,

I see what you are saying, and I have tried both ways, but they don't work here?

Andy.
 :) 
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

ckoehn

February 02, 2021, 06:59:15 AM #6 Last Edit: February 02, 2021, 07:23:49 AM by ckoehn
You challenged me with this problem.  I had to see if I could make it work. ;D
I don't know if you have solved this yet, but here it is....

Run as a console obviously
$include "windowssdk.inc"
openconsole
type TCITEM
  UINT   mask
  DWORD  dwState
  DWORD  dwStateMask
  LPSTR  pszText
  int    cchTextMax
  int    iImage
  LPARAM lParam
endtype

TCITEM tie
POINTER ptr 'temp pointer
STRING test = "something to point to"
STRING ret 'string var to store in to display

tie.pszText = &test 'assign a pointer to the structure, string is already a pointer, I don't know if we are doing multiple redirections or what

ptr = tie.pszText 'assign a pointer to a pointer variable outside of the structure
ret = #<STRING>ptr 'move the contents to a string variable

print ret 'print it

DO:UNTIL INKEY$ <> ""

CLOSECONSOLE

END

Later,
Clint

aurelCB

February 02, 2021, 08:38:02 AM #7 Last Edit: February 02, 2021, 08:47:02 AM by aurelCB
Some things here are not nececery at all

and i am not sure why you need string casting to UDT member when is already defined
as LPSTR...which is LongPointer to string i think that can be just string
and why windoowssdk and openconsole  ::)

Andy i really dont get it what you want this time

look in this code from o2 just modify it to IWB

Function GetTabText (cntID as INT,tbIndex as INT) as string
string tabText=Space(256)
TC_ITEM tie
tie.mask=1
tie.pszText = strptr tabText
tie.cchTextMax = 256
tie.iImage = -1
Sendmessage (cntID,TCM_GETITEM,tbIndex,&tie)
Return tabText
End Function

as you can see you need to alocate some space before you fill it with 
structure member tie.pszText

and that is all

Andy

Thanks Aurel,

My eyes must have been playing tricks with me.

Andy.
 :)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.