### 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: 2201
##### 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: 3539
##### 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: 10
##### 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: 10
##### 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: 2443
##### 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.

#### noszone

• New Member
• Posts: 13
##### Re: Can someone please explain pointers..
« Reply #25 on: June 23, 2021, 10:18:30 am »
Beside of an explanation of pointers, there is one good question I guess. What is the real use case of pointers in standard business app dev? Or for example in which operations pointers are must have to use. I am quite new to pointers, realy interesting.

#### Zvoni

• Hero Member
• Posts: 627
##### Re: Can someone please explain pointers..
« Reply #26 on: June 23, 2021, 10:29:24 am »
Heap vs. stack when calling functions/passing params to functions?
Speed in general?
since basically any code you write gets "boiled" down to assembler-code, which is in its guts manipulation of memory-addresses resp. registers?
Using external API's (e.g. Winbloze-API)?
« Last Edit: June 23, 2021, 10:31:23 am by Zvoni »
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

#### 440bx

• Hero Member
• Posts: 2443
##### Re: Can someone please explain pointers..
« Reply #27 on: June 23, 2021, 05:00:00 pm »
Beside of an explanation of pointers, there is one good question I guess. What is the real use case of pointers in standard business app dev? Or for example in which operations pointers are must have to use. I am quite new to pointers, realy interesting.
In any kind of application, business or otherwise, the ability to use pointers adeptly gives the programmer a lot of flexibility in how to manage memory.  This in turn can greatly simplify code as well as having a noticeable impact on the program's performance.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

#### y.ivanov

• Full Member
• Posts: 197
##### Re: Can someone please explain pointers..
« Reply #28 on: June 23, 2021, 07:35:51 pm »
In any kind of application, business or otherwise, the ability to use pointers adeptly gives the programmer a lot of flexibility in how to manage memory.  This in turn can greatly simplify code as well as having a noticeable impact on the program's performance.

On the other hand, there is a group of programming languages that explicitly prohibits memory management, i.e. they have no pointer concept. For example, the Java and .NET family. Don't even count the script languages.

#### 440bx

• Hero Member
• Posts: 2443
##### Re: Can someone please explain pointers..
« Reply #29 on: June 23, 2021, 08:45:26 pm »
On the other hand, there is a group of programming languages that explicitly prohibits memory management, i.e. they have no pointer concept. For example, the Java and .NET family. Don't even count the script languages.
That's true but, for instance .net applications often feel clumsy and slow (unless on a very, very fast machine) the same is often true of Java programs.  Of course, for simple things they do ok but, when it comes to real programs they inevitably fall short of the mark.

I like and use AWK relatively often and, for some things it is wonderful but, I don't see something like Oracle or Photohop written in AWK given its totally absent facilities to manage memory.

Some programmers should work on their aversion towards pointers.  It's like an airline pilot being afraid of flying.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.