我在下面寫了一個非常簡單的方法,它在TForm上的所有組件周圍創建一個多邊形。由于沒有HRGN.Free方法,Delphi XE6的編譯器指出了這一點,我只是問我是否應該Free,嗯,任何東西在那里,我以前從未使用過HRGN型別,想確定一下。謝謝你。
PS:我只是代表正確釋放記憶體的問題,如果這里甚至需要的話,沒有其他問題。
procedure TFormZoom.SetVisibleFormRegion; /span>
var.
VisibleRegionPoints: array[0.11] of TPoint;
VisibleFormRegion: HRGN。
begin
try
//我們希望在FormZoom上可見的所有組件周圍的XY點。
VisibleRegionPoints[0] := Point(0, 0) 。
VisibleRegionPoints[1] := Point(ZoomBoxPanel.Left ZoomBoxPanel.Width, 0) 。
VisibleRegionPoints[2] := Point(ZoomBoxPanel.Left ZoomBoxPanel.Width, ZoomBoxPanel.Height)。
VisibleRegionPoints[3] := Point(ZoomBoxPanel.Left, ZoomBoxPanel.Height)。
VisibleRegionPoints[4] := Point(ZoomBoxPanel.Left, 0) 。
VisibleRegionPoints[5] := Point(ColorBoxPanel.Width, 0)。
VisibleRegionPoints[6] := Point(ColorBoxPanel.Width, InfoValuesPanel.Top InfoValuesPanel.Height)。
VisibleRegionPoints[7] := Point(0, InfoValuesPanel.Top InfoValuesPanel.Height)。
VisibleRegionPoints[8] :=Point(0, InfoValuesPanel.Top);
VisibleRegionPoints[9] := Point(InfoValuesPanel.Width, InfoValuesPanel.Top)。
VisibleRegionPoints[10] := Point(ColorBoxPanel.Width, ColorBoxPanel.Height)。
VisibleRegionPoints[11] := Point(0, ColorBoxPanel.Height);
try
//我們從上述點創建一個多邊形區域。
VisibleFormRegion := CreatePolygonRgn(VisibleRegionPoints, Length(VisibleRegionPoints), ALTERNATE)。
//最后,我們將FormZoom視窗區域設定為創建的多邊形。
SetWindowRgn(Self.Handle, VisibleFormRegion, True)。
最終
VisibleFormRegion.Free; // <-- 沒有叫Free的方法!。
end。
except
on E: 例外 do
begin begin
//在出錯的情況下,我們只記錄例外。
FormMain.ErrorLog.Add('TFormZoom.SetVisibleFormRegion: ' E.ClassName ' - ' E.Message) 。
end。
end;
end。
uj5u.com熱心網友回復:
正如CreatePolygonRgn()的檔案中提到的,必須用DeleteObject()釋放回傳的句柄:
當你不再需要HRGN物件的時候,呼叫DeleteObject 函式來洗掉它。
UPDATE
正如Remy所指出的:在你的情況下,你正在呼叫SetWindowRgn(),它將區域的所有權轉移給系統。這意味著你不需要釋放它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316486.html
標籤:
