Search code examples
imageobjectpointersdelphidelphi-12-athens

Delphi I am trying to check for the position of the Sender but i get inaccessible value. How do i do it correctly?


I have an Image with the function OnMouseUp and i put an if statement using the Sender it didnt work with the Sender directly because it told me that It has to be an object which it is but it doesnt care. This is the func:

procedure THeaderFooterwithNavigation.DraggableImageMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
  Current:^TImage;
begin
  ActiveDrag.Remove(Sender);
  Current:=Sender.ClassInfo;//here is the problem(it doesnt save the pointer in Current)error in if
  if ((Image12.Position.X)<(Current.Position.X+Current.Width/2)) and ((Current.Position.X+Current.Width/2)<(Image12.Position.X+Image12.Width)) then
  begin
    if ((Image12.Position.Y)<(Current.Position.Y+Current.Height/2)) and ((Current.Position.Y+Current.Height/2)<(Image12.Position.Y+Image12.Height)) then
    begin
        Current.Position.X:=Image12.Position.X;
        Current.Position.Y:=Image12.Position.Y;
    end;
  end;
end;

I tried declaring Current as a pointer to TImage (^TImage) and also tried to set Current:=^Sender.ClassInfo but it returned the error: Incompatible types 'Pointer' and 'Char'


Solution

  • You can CAST the Sender Object as TImage (use IS operator for more security).
    Try something like this:

    var
      Current:TImage;
    begin
      ActiveDrag.Remove(Sender);
      if (Current is TImage) then
        Current := TImage(Sender);
    ...
    

    Now you can access to Current.ClassInfo, Current.ClassName, Current.ClassType, etc.