Results 1 to 10 of 10

Thread: Strange AV?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    I just tried your code with Lazarus and it doesn't give AV in objfpc or delphi modes. Works normally. It should be close to same thing as if you define a string variable in a procedure; initial value isn't initialized and when new value is stored, the trashcollector would try to free the old string which doesn't exist and give AV. However procedures do initialize string variables! If you make:
    edit: JSoftware already said the same...
    Code:
    var s: string;
    begin
      memo1.Lines.Add(s);
    It will print just a line chance, it never adds random characters. This however isn't case if you directly assign a memory space for it. Fillchar fixes that.

    string[4600] didn't even compile, max was indeed 255. But this works:
    Code:
    s: array[1..6400] of char;
    ...
    procedure TForm1.FormCreate(Sender: TObject);
    var i: integer;
    begin
      //s:='test'; // This works too with proper cut after 4 characters
      for i:=1 to 6400 do
        s[i]:=inttostr(i mod 10)[1]; 
        // [1] picks first and only character of inttostr() which results as string, expected char
      memo1.Lines.Add(s); // 6400 characters of continuous 0-9
    end;
    Last edited by User137; 12-11-2010 at 02:47 PM.

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
  •