1

I have a program written in Delphi 4 and trying to convert it to delphi xe10. One part i do not understand is this.

    Cmd[0] := 2;                   // Number of equipment to talk to
    Cmd[1] := 22;                  // My device address
    Cmd[2] := 0;
    MResults.Lines.Add('Reciving...');
    Refresh();

    Srlen := High(RecBuff);                               

     Ret := GpListen(@Cmd, @Srlen, @RecBuff);              // gets returned value
    if CheckRet('GpListen', (Ret and $FF), csBuf) = 0 then 
    begin
        RecBuff[Srlen] := Chr(0);                            // ??
        MResults.Lines.Add(RecBuff);               // returned 
        //csBuf := Format('????', [Srlen]); ////?some error??
    end;

The issue is RecBuff (RecBuff:array[0..9999] of Char;) It starts off full of #0 like so:

enter image description here

but as soon as

Ret := gpListen(@cmd, @srlen, @recbuff); 

is ran recbuff now looks like this:

enter image description here alot of japan char. how do i get this to encode onto the memopad correctly.

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
user41758
  • 309
  • 1
  • 2
  • 8
  • I have inserted the images for you. Two tips for next time: 1) We don't need these big screenshots, only the relevant local variables section will do 2) Never ever put code in your questions without specifying the variable types (we now have to assume what animal *cmd* is). – Jan Doggen Feb 08 '16 at 08:16

2 Answers2

3

Try changing

RecBuff:array[0..9999] of Char;

to

RecBuff:array[0..9999] of AnsiChar;

and see if it works. This may prompt some changes other places in the code.

In Delphi 10, a "Char" is a 2-byte entity (16 bit character, UniCode) as opposed to Delphi 4, where it is a 1-byte entity (8 bit character, ANSI). The common format for both compilers are "AnsiChar", which is an 8-bit character.

You'll probably also have issues with STRING variables which are now filled with 16-bit characters and not 8-bit characters.

Also - read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) before going any further in your conversion.

HeartWare
  • 7,464
  • 2
  • 26
  • 30
1

In Seattle strings and chars are Unicode by default.

Exchange with device usually is carried on through Ansi chars (one-byte) buffers.

So use AnsiString, AnsiChar, PAnsiChar etc

RecBuff:array[0..9999] of AnsiChar;

We have already discussed this problem here

Community
  • 1
  • 1
MBo
  • 77,366
  • 5
  • 53
  • 86