Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: random noise in record?

  1. #11

    random noise in record?

    A string with predefined length (string[x]) is a "shortstring", the old string-type of Delphi 16-bit and Turbo Pascal, and it is not null-terminated. Instead the first byte is the string length. This means it can contain zero-characters. s:='te'#0'st' is a valid shortstring with length 5 (length stored in s[0]).

    As already suggested just do a FillChar(MyRecord, sizeof(TMyRecord), 0) to clear the whole record at once.
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  2. #12

    random noise in record?

    A string with predefined length (string[x]) is a "shortstring", the old string-type of Delphi 16-bit and Turbo Pascal, and it is not null-terminated. Instead the first byte is the string length. This means it can contain zero-characters. s:='te'#0'st' is a valid shortstring with length 5 (length stored in s[0]).

    As already suggested just do a FillChar(MyRecord, sizeof(TMyRecord), 0) to clear the whole record at once.
    Are you Sure ?

    i made a record like noeska last week using delphi 6, i used an hex editor and i saw a null character just after the last char. will send some screen captures when i'm back home

    AFAIK, Windows use "pchar type" natively ?

  3. #13

    random noise in record?

    Delphi 2007:

    Code:
    type
    TMyRecord = packed record
    name: string[255];
    someint: int64;
    end;
    
    procedure TForm2.FormCreate(Sender: TObject);
    var
      s : tmyrecord;
    begin
    fillchar(s,sizeof(tmyrecord),$80); //fill with non-zero for testing
    s.name := '12'#0'34';
    self.caption := inttostr(length(s.name));  //set breakpoint here
    end;
    The window caption will display the length of the string as 5. If you set a breakpoint where selected and press ctrl-f7 for evaluate and type "s,m" you will see a hex dump of the "s" variable. You will see that there is no zero after the string.
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  4. #14

    random noise in record?

    Quote Originally Posted by Lowercase
    i made a record like noeska last week using delphi 6, i used an hex editor and i saw a null character just after the last char. will send some screen captures when i'm back home
    So how exactly did you write the record to a file?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  5. #15

    re-

    When you checks in delphi help the topic about functions and rutines by category you will note tha there are two sections, string and null terminated string rutines, the "string" rutines use the first character for denote the string lenght; nul terminate string are used as pchar.

  6. #16

    random noise in record?

    ok I found why... i used strpcopy function which result as pchar

    [pascal] TFileIndex = record
    FileName: array[0..119] of char;
    FilePos: integer;
    FileLength: integer;
    end;

    //and later i use :


    strpcopy(Dir.FileName, ExtractFileName(files.Strings[i]));


    [/pascal]



Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •