【发布时间】:2021-09-03 07:46:28
【问题描述】:
我在下面完整编写了一个非常简单的方法,它在TForm 上的所有组件周围创建了一个多边形。由于 Delphi XE6 的编译器指出没有 HRGN.Free 方法,我只是问我是否应该 Free,嗯,任何东西在里面,我以前从未使用过HRGN 类型并且想确定。谢谢。
PS:我只是代表正确释放内存,如果这里甚至需要,仅此而已。
procedure TFormZoom.SetVisibleFormRegion;
var
VisibleRegionPoints: array[0..11] of TPoint;
VisibleFormRegion: HRGN;
begin
try
// XY points around all components that we want to be visible on the FormZoom
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
// we create a polygon region from the above points
VisibleFormRegion := CreatePolygonRgn(VisibleRegionPoints, Length(VisibleRegionPoints), ALTERNATE);
// finally, we set the FormZoom window region to the created polygon
SetWindowRgn(Self.Handle, VisibleFormRegion, True);
finally
VisibleFormRegion.Free; // <-- There is no method called Free!
end;
except
on E: Exception do
begin
// in case of error, we log the exception only
FormMain.ErrorLog.Add('TFormZoom.SetVisibleFormRegion: ' + E.ClassName + ' - ' + E.Message);
end;
end;
end;
【问题讨论】:
标签: delphi winapi memory-management