2013-12-15 36 views
3

在兩臺計算機上都沒問題,在三臺計算機上,有相同的異常,並且具有相同的AV地址。謝謝幫忙Delphi XE5在應用程序啓動時訪問衝突

begin 
    Application.Hinthidepause := 30000; 
    Application.Initialize; 
    Application.MainFormOnTaskbar := True; 
    Application.CreateForm(TForm1, Form1); 
    Application.CreateForm(TForm2, Form2); 
    Application.CreateForm(TForm3, Form3); 
    Application.CreateForm(TForm4, Form4); 
    Application.Run; 
end; 

exception class : EAccessViolation 
exception message : Access violation at address 00405361 in module 'Project1.exe'. Read of address 00000064. 

main thread ($1d44): 
00405361 +3d Project1.exe System   75 +0 SysGetMem 
00406827 +3f Project1.exe System   75 +0 @ReallocMem 
0040c38c +d8 Project1.exe System   75 +0 DynArraySetLength 
0040c4bd +05 Project1.exe System   75 +0 @DynArraySetLength 
005465af +23 Project1.exe System.Classes  {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.SetCapacity 
005466b0 +2c Project1.exe System.Classes  {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.Grow 
005466d2 +16 Project1.exe System.Classes  {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.GrowCheck 
00546a4d +0d Project1.exe System.Classes  {System.Generics.Collections}TList<System.Generics.Collections.TList<System.Classes.TComponent>>.Add 
0051e75e +36 Project1.exe System.Classes  BeginGlobalLoading 
0051e8de +46 Project1.exe System.Classes  InitInheritedComponent 
0064cfde +c6 Project1.exe Vcl.Forms    TCustomForm.Create 
00657ffa +76 Project1.exe Vcl.Forms    TApplication.CreateForm 
00883ce7 +c7 Project1.exe Project1 54 +13 initialization 
76a13368 +10 kernel32.dll 

UPDATE 問題是這個過程:

procedure KopiujRTF(const Source, destination: TRichEdit); 
var 
    rtfStream: TEditStream; 
    sourceStream: TMemoryStream; 
    function EditStreamReader(dwCookie: DWORD; pBuff: Pointer; cb: LongInt; 
    pcb: PLongInt): DWORD; stdcall; 
    begin 
    Result := $0000; 
    try 
     pcb^ := TStream(dwCookie).Read(pBuff^, cb); 
    except 
     Result := $FFFF; 
    end; 
    end; 
begin 
    destination.Lines.BeginUpdate; 
    sourceStream := TMemoryStream.Create; 
    try 
    Source.Lines.SaveToStream(sourceStream); 
    sourceStream.Position := 0; 
    destination.MaxLength := destination.MaxLength + sourceStream.Size; 
    rtfStream.dwCookie := DWORD(sourceStream); 
    rtfStream.dwError := $0000; 
    rtfStream.pfnCallback := @EditStreamReader; 
    destination.Perform(EM_STREAMIN, SFF_SELECTION or SF_RTF or SFF_PLAINRTF, 
     lParam(@rtfStream)); 
    if rtfStream.dwError <> $0000 then 
     zolty := True; 
    sourceStream.Free; 
    destination.Lines.EndUpdate; 
    except 
    end; 
end; 

在Form1上創建我有:

RichEdit1.MaxLength:= $ 7FFFFFF0;

使範圍檢查調試白標明此之後:

destination.MaxLength := destination.MaxLength + sourceStream.Size; 

刪除對RichEdit解決問題的最大長度。感謝您的幫助。

+1

您的調用堆棧表明在DFM流式傳輸期間正在訪問零「TList」指針。 –

+0

@RemyLebeau不,這是一個錯誤的分析。 AV會在很久之前發生。這會發生爲'TList .Add'讀取'FCount'以形成傳遞給'GrowCheck'的參數。 –

+0

AV處於足夠低的地址以指示正在某處訪問零指針。如果在無效的'TList '上調用'Add()',那麼顯然它的'FCount'不會保持有效的計數,並且它將在無效的動態數組上調用SetLength()。 –

回答

3

調用堆棧指示您在程序的其他部分損壞了堆。這是解釋,對於SysGetMem中的訪問衝突,概率> 0.999。

您需要查看啓動過程中發生的情況,然後執行此調用堆棧中的代碼。尋找緩衝區溢出,即訪問超出界限的數組元素。很有可能僅僅啓用不可或缺的功能就足以找到程序的缺陷。

+0

謝謝你的答案。將嘗試,一個問題是,在我的電腦上工作正常。 – user3075132

+0

這在堆損壞中很常見。他們往往不可重複。您必須至少使用範圍檢查進行調試構建。這是一個非常棒的功能。 –

+0

我總是想知道爲什麼人們在開發過程中保持這種狀態 - 特別是當發生錯誤時。 –