Je suis une erreur de vérification de gamme dans ce morceau de code:erreur de vérification de gamme tout en peignant la toile
{ This procedure is copied from RxLibrary VCLUtils }
procedure CopyParentImage(Control: TControl; Dest: TCanvas);
var
I, Count, X, Y, SaveIndex: Integer;
DC: HDC;
R, SelfR, CtlR: TRect;
begin
if (Control = nil) OR (Control.Parent = nil)
then Exit;
Count := Control.Parent.ControlCount;
DC := Dest.Handle;
with Control.Parent
DO ControlState := ControlState + [csPaintCopy];
TRY
with Control do
begin
SelfR := Bounds(Left, Top, Width, Height);
X := -Left; Y := -Top;
end;
{ Copy parent control image }
SaveIndex := SaveDC(DC);
TRY
SetViewportOrgEx(DC, X, Y, nil);
IntersectClipRect(DC, 0, 0, Control.Parent.ClientWidth, Control.Parent.ClientHeight);
with TParentControl(Control.Parent) DO
begin
{$R-}
Perform(WM_ERASEBKGND, DC, 0); <--------------- HERE
{$R+}
PaintWindow(DC);
end;
FINALLY
RestoreDC(DC, SaveIndex);
END;
{ Copy images of graphic controls }
for I := 0 to Count - 1 do begin
if Control.Parent.Controls[I] = Control then Break
else if (Control.Parent.Controls[I] <> nil) and
(Control.Parent.Controls[I] is TGraphicControl) then
begin
with TGraphicControl(Control.Parent.Controls[I]) do begin
CtlR := Bounds(Left, Top, Width, Height);
if Bool(IntersectRect(R, SelfR, CtlR)) and Visible then
begin
ControlState := ControlState + [csPaintCopy];
SaveIndex := SaveDC(DC);
try
SetViewportOrgEx(DC, Left + X, Top + Y, nil);
IntersectClipRect(DC, 0, 0, Width, Height);
{$R-}
Perform(WM_PAINT, DC, 0); <--------------- HERE
{$R+}
finally
RestoreDC(DC, SaveIndex);
ControlState := ControlState - [csPaintCopy];
end;
end;
end;
end;
end;
FINALLY
with Control.Parent DO
ControlState := ControlState - [csPaintCopy];
end;
end;
Quelqu'un a publié le code sans avoir le Range Check activé :(
je mets {$ R -.} {$ R +} autour des lignes qui génèrent l'erreur et le code fonctionne maintenant, mais je ne sais pas quelles sont les conséquences que je ne veux pas une étrange erreur plus tard
Delphi, Win. 7 32bit
Merci beaucoup. Ça a marché. J'ai vu la différence entre les paramètres mais je n'avais aucune idée que je peux typecast en utilisant WParam. Il semble que le changement est apparu dans Delphi 3 mais le code était destiné à Delphi 2005 et j'ai d'abord pensé qu'il s'agissait d'une erreur dans le code. Probablement le développeur avait l'option Range Check désactivée. – Ampere