Expert opinion needed: Delphi bug or what?

From: Eden Kirin (eden_MAKNIOVO_at_cvs.hr)
Date: 11/10/03


Date: Mon, 10 Nov 2003 13:32:36 +0100

Hello.

I need an expert opinion in my issue. I work on somewhat bigger project
(>1MB .pas files). In some moment, after i wrote and added new unit to
project (this unit contains only some class definitions) and using it from
one of my units, program failed to start, in the unit initialization par,
*before* my application code, before the code in the dpr file.

Looking at the Call Stack, i put breakpoint in InitUnits function:
SqlTimSt
InitUnits
@StartExe(???,???)
@InitExe(???)
App.exe

When I press F7, it goes to the SqlTimSt initialization part:
initialization
  SQLTimeStampVariantType := TSQLTimeStampVariantType.Create;

When I press F7, it is in Variants unit:
constructor TCustomVariantType.Create;
begin
  Create(LNextVarType);

After F7, it calls following constructor (RequestedVarType=271):
constructor TCustomVariantType.Create(RequestedVarType: TVarType);
var
  LSlot, LWas, LNewLength, I: Integer;
begin
  inherited Create;
  EnterCriticalSection(LVarTypeSync);
  try
    LSlot := RequestedVarType - CMinVarType;
    if (LSlot < 0) or (RequestedVarType < CFirstUserType) then
      raise EVariantError.CreateFmt(SVarTypeOutOfRangeWithPrefix,
[HexDisplayPrefix, RequestedVarType]);
    LWas := Length(LVarTypes);
    if LSlot >= LWas then
    begin
      LNewLength := ((LSlot div CIncVarType) + 1) * CIncVarType;
      if LNewLength > CMaxVarType then
        raise EVariantError.Create(SVarTypeTooManyCustom);
      SetLength(LVarTypes, LNewLength);

In the last line (SetLength) i press F7 and it goes to System unit:
procedure _DynArraySetLength;
asm
        PUSH ESP
        ADD dword ptr [ESP],4
        CALL DynArraySetLength

After F7, it calls DynArraySetLength:
procedure DynArraySetLength(var a: Pointer; typeInfo: Pointer; dimCnt:
Longint; lengthVec: PLongint);

30, 40 lines below:

  // If the heap object isn't shared (ref count = 1), just resize it.
Otherwise, we make a copy
  if (p = nil) or (PLongint(p)^ = 1) then
  begin
    pp := p;
    if (newLength < oldLength) and (typeInfo <> nil) then
      FinalizeArray(PChar(p) + Sizeof(Longint)*2 + newLength*elSize,
typeInfo, oldLength - newLength);
    ReallocMem(pp, neededSize);

When it reaches ReallocMem(pp=nil, neededSize=128), it calls
MemoryManager.GetMem and when I run it further (F9), application raises
error: Project App.exe faulted with message 'access violation at xxx: write of
address xxxx', with debugger positioned on System.LoadResString.

Just for the record, I noticed that application sometimes used to behaive
this way after rebuilding the whole project. After this, when code of the
main unit changed and partially compiling it, application worked.

At this moment, I can't make it work. When this "invalid" exe is started
outside of Delphi IDE, nothing happens. Application doesn't start, no error
message is displayed.

I use few little 3rd party components and TB2k. I searched JGSoftware news
server to see if anyone has similar problems, but I haven't found any.

The application is compiled with Delphi7. I compiled it with Delphi6 also,
and the problem remains.

Any help is appreciated. I don't know what to do with it. It seems absurd
and unlogical.

Eden



Relevant Pages

  • Expert opinion needed: Delphi bug or what?
    ... (>1MB .pas files). ... constructor TCustomVariantType.Create; ... main unit changed and partially compiling it, ... outside of Delphi IDE, nothing happens. ...
    (alt.comp.lang.borland-delphi)
  • Re: Standard VCL resource stings...
    ... > translateded resourcestring units are part of all Delphi versions. ... > don't want the repositories for ITE but the PAS files. ... > is german. ... Until D6 we did get also an english version with buying ...
    (borland.public.delphi.non-technical)
  • Re: Compare pas files
    ... John wrote: ... identify specific differences in two similar *.pas files? ... I use Beyond Compare and if you also use Delphi 2007 you might find ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Thanks John Kaster, Borland and the TDUG group!!
    ... Writing more and more C# and less and less Pascal, I find that I move away from my Delphi "habits" and write code and position methods and variables quite differently in CS files than in PAS files. ...
    (borland.public.delphi.non-technical)