Re: Expert opinion needed: Delphi bug or what?

From: Sander Martens (sandermartens_at_msn.com)
Date: 11/10/03


Date: Mon, 10 Nov 2003 18:05:54 +0100

Don't know if I can be of any help in this thing because I'm not an expert.
You are taking about adding a new unit and after that the program fails to
run. I've had that problem several times. What I do is when adding a new
unit I save it first, giving it the correct filename and after that start
writing the code. That's my way to prevent having that problem. It could be
that I totally don't understand your problem.

Sander

"Eden Kirin" <eden_MAKNIOVO@cvs.hr> schreef in bericht
news:tud8bb5ias7y$.1cqy4j6y7h4gs$.dlg@40tude.net...
> 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