### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Recent

#### anna

• Sr. Member
• Posts: 426
##### Re: Can someone please explain pointers..
« Reply #15 on: November 09, 2011, 05:38:07 am »
Ha-ha-ha! Next code even doesn't work
Code: [Select]
`for i:=1 to length(Utf8ToAnsi(path0)) do sh.pFrom^[i-1]:=Utf8ToAnsi(path0)[i];`
Error:
unit1.pas(498,19) Error: Illegal qualifier
And cursor shows 'i' (for-loop counter ):
sh.pFrom^[ i -1  ]:=Utf8ToAnsi(path0)[ i ];

Why is qualifier  illegal?

« Last Edit: November 09, 2011, 05:41:55 am by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

#### anna

• Sr. Member
• Posts: 426
##### Re: Can someone please explain pointers..
« Reply #16 on: November 09, 2011, 05:54:31 am »
I've found error. That should be:
Code: [Select]
`for i:=1 to length(Utf8ToAnsi(path0)) do sh.pFrom{^}[i-1]:=Utf8ToAnsi(path0)[i];`

Temporary i will use slowly for-loop, until invent better solution ...

Stupid pointers!
« Last Edit: November 09, 2011, 05:56:14 am by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

#### User137

• Hero Member
• Posts: 1791
##### Re: Can someone please explain pointers..
« Reply #17 on: November 09, 2011, 06:56:02 am »
Isn't UTF8 string sometimes longer than ANSI string? Ain't the whole point that it sometimes makes 1 character out of 2 bytes, so that it can support wider range of characters.

I don't know if this works.. but instead of for-loop, something like:
Code: [Select]
` PChar( [code]sh.pFrom[0] ):=PChar(Utf8ToAnsi(path0));`
Or first convert it into temporary string so you also know the real length it's reduced to.
« Last Edit: November 09, 2011, 06:59:51 am by User137 »

#### avra

• Hero Member
• Posts: 1884
##### Re: Can someone please explain pointers..
« Reply #18 on: November 09, 2011, 10:21:40 am »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

#### felipemdc

• Hero Member
• Posts: 3541
##### Re: Can someone please explain pointers..
« Reply #19 on: November 09, 2011, 10:29:11 am »
Isn't UTF8 string sometimes longer than ANSI string? Ain't the whole point that it sometimes makes 1 character out of 2 bytes, so that it can support wider range of characters.

Yes, Anna should probably be using a W version of this Windows API, supposing it exists. Then she would need to convert the utf8 string to utf-16 using UTF8ToUTF16 and then copy the resulting string to the Windows record string array. I think that := will be able to copy a UnicodeString to a array of WideChar.

Quote
I don't know if this works.. but instead of for-loop, something like:
Code: [Select]
` PChar( [code]sh.pFrom[0] ):=PChar(Utf8ToAnsi(path0));`

No, I think that will fail. Windows API structures usually have real storage, not pointers to data.

#### anna

• Sr. Member
• Posts: 426
##### Re: Can someone please explain pointers..
« Reply #20 on: November 09, 2011, 01:23:30 pm »
Isn't UTF8 string sometimes longer than ANSI string? Ain't the whole point that it sometimes makes 1 character out of 2 bytes, so that it can support wider range of characters.

Yes, Anna should probably be using a W version of this Windows API, supposing it exists. Then she would need to convert the utf8 string to utf-16 using UTF8ToUTF16 and then copy the resulting string to the Windows record string array. I think that := will be able to copy a UnicodeString to a array of WideChar.

I need not utf8 or unicode. I need ANSI and there is no problems with conversion. ANSI-string has 1-byted characters. For me conversion is clear. Thank you but I need not help with conversion.

***********************

There is only one func in Windows unit - SHFileOperation. But in OllyDBG I see SHFileOperationA, so compiler convert func to ansi version.
« Last Edit: November 09, 2011, 01:37:49 pm by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

#### anna

• Sr. Member
• Posts: 426
##### Re: Can someone please explain pointers..
« Reply #21 on: November 09, 2011, 01:31:29 pm »
Isn't UTF8 string sometimes longer than ANSI string? Ain't the whole point that it sometimes makes 1 character out of 2 bytes, so that it can support wider range of characters.

I don't know if this works.. but instead of for-loop, something like:
Code: [Select]
` PChar( [code]sh.pFrom[0] ):=PChar(Utf8ToAnsi(path0));`
Or first convert it into temporary string so you also know the real length it's reduced to.

unit1.pas(36,1) Error: Illegal type conversion: "Char" to "PChar"

So you are not allowed to make type conversion in left part of operator. It's similar as you would code : S1+S2:=S3;// compiler doesn't  understand such lines

Afrer that even if you code would be compiled , Pchar() is absolutely new variable (but just not declared and initializated). So it similar to
NEW_VARIABLE:=PChar(Utf8ToAnsi(path0));
PChar( sh.pFrom[0] ):=NEW_VARIABLE;
« Last Edit: November 09, 2011, 01:40:40 pm by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

#### zzamyy

• New member
• Posts: 8
##### Re: Can someone please explain pointers..
« Reply #22 on: April 03, 2020, 07:45:13 pm »
cruz, on the Self pointer of class type is a signal that also is not in permission to read memory: pushing a SIVSEG error. is pushed by... well cannot access memory at address

#### zzamyy

• New member
• Posts: 8
##### Re: Can someone please explain pointers..
« Reply #23 on: April 03, 2020, 08:22:44 pm »
Code: Pascal  [Select][+][-]
1. program exPointers;
2. var
3.    number: integer;
4.    iptr: ^integer;
5.    y: ^word;
6.
7. begin
8.    number := 100;
9.    writeln('Number is: ', number);
10.    iptr := @number;
11.    writeln('iptr points to a value: ', iptr^);
12.
13.    iptr^ := 200;
14.    writeln('Number is: ', number);
15.    writeln('iptr points to a value: ', iptr^);
17.    writeln(y^);
18. end.
19.
20.

this is the most relevand info but still a permission is lost

#### 440bx

• Hero Member
• Posts: 1824
##### Re: Can someone please explain pointers..
« Reply #24 on: April 03, 2020, 08:44:22 pm »
I think every programmer should learn some assembly, or at least C, to understand what is actually going on.
This is a big problem with modern languages which have more and more abstraction from the actual processor level. If a programmer doesn't know how the code translates into low-level binary then he/she can make inefficient programs.

Juha
If anything, this thread proves those words to be absolutely true.

A lack or, poor understanding of pointers, severely limits a programmer's abilities to produce clean and efficient algorithms and, the set of methods that can be used to solve a problem.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.