Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-08

Help with basic pointer operations

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tommi Prami

Hello,

I kind of always try to stay away from the pointers, but now I maybe need to use them...

I think this is not correct yet (at least it does not to 100% what I like) :

var
   LSimpleStr     : string;
   LTmpWStr      : array [0..250] of WideChar;
...
   LSimpleStr := 'Some text';
   mwStrToWide(LSimpleStr, LTmpWStr ,  250);
...
procedure mwStrToWide(const AString: string; PWideString: PWideChar;
   const ABufferLen: Integer);
begin
   FillChar(PWideString^, ABufferLen, 0);
   if AString   '' then
   begin
     StringToWideChar(AString, PWideString, ABufferLen);
   end;
end;

With debugger it seems that the Buffer is not cleared correctly like I would like to (Much easier to debug when you see more easily the content of the Array).

And the most worrying part is that the code seems to work other vice, but I have the feeling that it is not 100% correct.

-TP-

Reply by email

Unknown author
to Tommi Prami
Tommi Prami wrote 20 lines
Hello, I kind of always try to stay away from the pointers, but now I maybe need to use them... I think this is not correct yet (at least it does not to 100% what I like) : var LSimpleStr : string; LTmpWStr : array [0..250] of WideChar; ... LSimpleStr := 'Some text'; mwStrToWide(LSimpleStr, LTmpWStr , 250); ... procedure mwStrToWide(const AString: string; PWideString: PWideChar; const ABufferLen: Integer); begin FillChar(PWideString^, ABufferLen, 0);

At least this is wrong, since the buffer is 2*250 wide. FillChar assumes that 1 char = 1 byte.

Michael.

Reply by email