2

When I have a string in a TOmniValue array, then accessing the value by name or by explicit index raises an access violation. See the following code for an example. Am I doing something wrong, or is there an error in Delphi or TOmniValue? I found a workaround for accessing by index, but what about by name?

UPDATE: I've moved Test into a console app for easier reproduction, but now the error only occurs in every second run or so instead of every interation. Or maybe it is not even the same error now?

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  OtlParallel,
  OtlCommon;

procedure Test;
const
  Count = 1000;
var
  i: integer;
  BackgroundWorker: IOmniBackgroundWorker;
begin
    BackgroundWorker := Parallel.BackgroundWorker.NumTasks(2)
      .Execute(
        procedure (const workItem: IOmniWorkItem)
        const Inx_ = 1;
        var Inx: integer;
        begin
          // Works:
          workItem.Result := 'Integer: '+workItem.Data[workItem.Data.AsArray.Count-1].AsString;
          // Works (but why?!):
          workItem.Result := 'Integer: '+workItem.Data[workItem.Data.AsArray.Count*0+Inx_].AsString;
          // Raises AV immediately:
          workItem.Result := 'Integer: '+workItem.Data[Inx_].AsString;
          // Raises AV immediately:
          Inx:=workItem.Data.AsArray.Count-1;
          workItem.Result := 'Integer: '+workItem.Data[Inx].AsString;
          // Raises AV later when workItem.Result is accessed:
          workItem.Result := 'Integer: '+workItem.Data['BB'].AsString;
        end
      )
      .OnRequestDone(
        procedure (const Sender: IOmniBackgroundWorker;
          const workItem: IOmniWorkItem)
        begin
          workItem.Result.AsString;
        end)
    ;
    for i := 1 to Count do begin
      BackgroundWorker.Schedule(BackgroundWorker.CreateWorkItem(
        TOmniValue.CreateNamed(
          [
            'AA',IntToStr(Random(100)),
            'BB',IntToStr(Random(100))
          ]
        )
      ));
    end;
    BackgroundWorker.WaitFor(INFINITE);
end;

begin
  Test;
end.

I'm using the newest trunk of Otl (r1333). I believe I had the same error in 3.03a.

boileau
  • 817
  • 6
  • 20
  • 1
    I'm disappointed that, despite my asking you to in my now deleted answer, that you won't supply an SSCCE. – David Heffernan Jun 03 '14 at 07:03
  • I have not refused to provide anything. I asked a question that you seem to have misinterpreted. I am trying to figure how to best help you help me. I have read descriptions of SSCCE. I have reread your comments. It is still not clear to me what I should post. A pas file is not compilable on it's own. Neither is a pas+dfm. At a minimum I would need to post the dpr, dproj, pas, and dfm files, and even then you could potentially argue that it is not complete, because the exact version of Otl that I am using is not included. – boileau Jun 03 '14 at 07:11
  • I am sorry if this has been a waste of time for you. I hope that you can help me to better another time. – boileau Jun 03 '14 at 07:12
  • A console app would be best. You can specify the revision number of Otl. If you cannot provide console app then .dpr, .pas and .dfm are fine. – David Heffernan Jun 03 '14 at 07:14
  • Well, the console version only gives intermittant errors. Would you still prefer that? – boileau Jun 03 '14 at 07:18
  • Also, I am happy to provide the information you need, but it seems to me that you are applying a standard that is much higher than I am used to seeing in SO questions. I have difficulty shaking the feeling that posting 3 complete files will turn off many potential answerers. Am I wrong? – boileau Jun 03 '14 at 07:24
  • If you give me complete files that I can compile and reproduce the bug, then I'm happy. As it stands I cannot reproduce. So I cannot help. Perhaps somebody else will. I am losing enthusiasm. It's been 19 hours. Evidence suggests there is a problem with the Q. Only I have bitten. – David Heffernan Jun 03 '14 at 07:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/54964/discussion-between-boileau-and-david-heffernan). – boileau Jun 03 '14 at 07:38
  • 1
    That's better. Now I upvote. I can repro every time. I put full debug fastmm in there which appears to make repros more reliable. – David Heffernan Jun 03 '14 at 08:55
  • Kind of feels like a compiler bug. Cannot repro in XE2. Can do so in 2010. Not got XE on this machine. Cannot work out what's wrong in 2010. AV appears to occur on shutdown. – David Heffernan Jun 03 '14 at 09:16
  • Hm. I guess I might not be able to do anything about it then. – boileau Jun 03 '14 at 11:35

0 Answers0